From 969aed8070922df5a1594b29d8aa108d78549230 Mon Sep 17 00:00:00 2001 From: mrtripie <65431647+mrtripie@users.noreply.github.com> Date: Tue, 16 Nov 2021 17:17:02 -0500 Subject: [PATCH] Cache Save/Open Sprite Dialog's directory, and keep dialogs synced (#559) * Open/Save Sprite Dialogs now have their directory cached so when reopening Pixelorama they will be set to that directory. Load last project and load recent project also syncs with the open/save dialogs and caches that directory * Sets a projects default file path to the cached file directory (not sure about) and if the export directory is blank, use the cached file directory * Changed 'file_dialog_dir' to 'current_dir' Co-authored-by: MrTriPie <MrTriPie> --- src/Classes/Project.gd | 2 +- src/Main.gd | 16 ++++++++++++++-- src/UI/Dialogs/ExportDialog.gd | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 04797201e..04b61ee47 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -82,7 +82,7 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> if OS.get_name() == "HTML5": directory_path = "user://" else: - directory_path = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP) + directory_path = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) func commit_undo() -> void: diff --git a/src/Main.gd b/src/Main.gd index 8896521f0..9b2626ef4 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -46,8 +46,8 @@ func _ready() -> void: Global.quit_and_save_dialog.add_button("Save & Exit", false, "Save") Global.quit_and_save_dialog.get_ok().text = "Exit without saving" - Global.open_sprites_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP) - Global.save_sprites_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP) + Global.open_sprites_dialog.current_dir = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) + Global.save_sprites_dialog.current_dir = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) # FIXME: OS.get_system_dir does not grab the correct directory for Ubuntu Touch. # Additionally, AppArmor policies prevent the app from writing to the /home @@ -313,6 +313,10 @@ func load_last_project() -> void: var file_check := File.new() if file_check.file_exists(file_path): # If yes then load the file OpenSave.open_pxo_file(file_path) + # Sync file dialogs + Global.save_sprites_dialog.current_dir = file_path.get_base_dir() + Global.open_sprites_dialog.current_dir = file_path.get_base_dir() + Global.config_cache.set_value("data", "current_dir", file_path.get_base_dir()) else: # If file doesn't exist on disk then warn user about this Global.error_dialog.set_text("Cannot find last project file.") @@ -328,6 +332,10 @@ func load_recent_project_file(path : String) -> void: var file_check := File.new() if file_check.file_exists(path): # If yes then load the file OpenSave.handle_loading_files([path]) + # Sync file dialogs + Global.save_sprites_dialog.current_dir = path.get_base_dir() + Global.open_sprites_dialog.current_dir = path.get_base_dir() + Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) else: # If file doesn't exist on disk then warn user about this Global.error_dialog.set_text("Cannot find project file.") @@ -337,11 +345,15 @@ func load_recent_project_file(path : String) -> void: func _on_OpenSprite_file_selected(path : String) -> void: OpenSave.handle_loading_files([path]) + Global.save_sprites_dialog.current_dir = path.get_base_dir() + Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) func _on_SaveSprite_file_selected(path : String) -> void: var zstd = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed OpenSave.save_pxo_file(path, false, zstd) + Global.open_sprites_dialog.current_dir = path.get_base_dir() + Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) if is_quitting_on_save: _on_QuitDialog_confirmed() diff --git a/src/UI/Dialogs/ExportDialog.gd b/src/UI/Dialogs/ExportDialog.gd index c59165335..a5dbc824c 100644 --- a/src/UI/Dialogs/ExportDialog.gd +++ b/src/UI/Dialogs/ExportDialog.gd @@ -229,7 +229,7 @@ func _on_ExportDialog_about_to_show() -> void: Export.directory_path = "user://" if Export.directory_path.empty(): - Export.directory_path = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP) + Export.directory_path = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) # If export already occured - sets gui to show previous settings options_resize.value = Export.resize