Skip to content

Commit

Permalink
Add default name/dir to svg export
Browse files Browse the repository at this point in the history
Recent dir is saved in config.

Also:
- Fix button text in file chooser
- Fix appending .svg to file name
  • Loading branch information
ztlxltl committed Feb 2, 2025
1 parent 9f3ca23 commit a59bf3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/family_tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def export_svg_view(self, *args):
dialog.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN,
Gtk.STOCK_SAVE,
Gtk.ResponseType.OK,
)

Expand All @@ -634,16 +634,23 @@ def export_svg_view(self, *args):
filter_any.add_pattern("*")
dialog.add_filter(filter_any)

recent_dir = self._config.get("paths.familytreeview-recent-export-dir")
dialog.set_current_folder(recent_dir)
dbname = self.dbstate.db.get_dbname()
dialog.set_current_name(f"untitled_FTV_export_of_{dbname}.svg")

response = dialog.run()

if response != Gtk.ResponseType.OK:
dialog.destroy()
return

file_name = dialog.get_filename()
dir_name = os.path.dirname(file_name)
self._config.set("paths.familytreeview-recent-export-dir", dir_name)
dialog.destroy()

if file_name[:-4].lower() != ".svg":
if file_name[-4:].lower() != ".svg":
file_name += ".svg"

# TODO Catch errors of cairo write.
Expand Down
5 changes: 4 additions & 1 deletion src/family_tree_view_config_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from gi.repository import Gtk

from gramps.gen.config import config
from gramps.gen.const import GRAMPS_LOCALE, SIZE_LARGE, SIZE_NORMAL
from gramps.gen.const import GRAMPS_LOCALE, SIZE_LARGE, SIZE_NORMAL, USER_HOME
from gramps.gen.lib.eventtype import EventType

from family_tree_view_config_provider_names import names_page, DEFAULT_ABBREV_RULES
Expand Down Expand Up @@ -109,6 +109,9 @@ def get_config_settings():
("experimental.familytreeview-adaptive-ancestor-generation-dist", False),
("experimental.familytreeview-connection-follow-on-click", False),
("experimental.familytreeview-canvas-font-size-ppi", 96),

# without config ui
("paths.familytreeview-recent-export-dir", USER_HOME),
)

@staticmethod
Expand Down

0 comments on commit a59bf3b

Please sign in to comment.