From ad85c8dd3e5724ce59398617c713bb1d01ef8e28 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:12:27 +0200 Subject: [PATCH] Minor open/save dialog path related code cleaning --- src/Autoload/OpenSave.gd | 3 +++ src/Classes/Project.gd | 12 ++++-------- src/Main.gd | 6 ------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 1b71c08af..eb090aaa3 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -242,6 +242,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true else: new_project.tiles.reset_mask() zip_reader.close() + new_project.export_directory_path = path.get_basename() if empty_project: new_project.change_project() @@ -258,6 +259,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true Global.main_window.title = path.get_file() + " - Pixelorama " + Global.current_version Global.save_sprites_dialog.current_path = path # Set last opened project path and save + Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) Global.config_cache.set_value("data", "last_project_path", path) Global.config_cache.save("user://cache.ini") new_project.export_directory_path = path.get_base_dir() @@ -420,6 +422,7 @@ func save_pxo_file( Global.main_window.title = path.get_file() + " - Pixelorama " + Global.current_version # Set last opened project path and save + Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) Global.config_cache.set_value("data", "last_project_path", path) Global.config_cache.save("user://cache.ini") if !project.was_exported: diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index fe2511d0b..00bd2b541 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -217,12 +217,11 @@ func change_project() -> void: if has_changed: Global.main_window.title = Global.main_window.title + "(*)" - var save_path := OpenSave.current_save_paths[Global.current_project_index] - if save_path != "": - Global.open_sprites_dialog.current_path = save_path - Global.save_sprites_dialog.current_path = save_path + if export_directory_path != "": + Global.open_sprites_dialog.current_path = export_directory_path + Global.save_sprites_dialog.current_path = export_directory_path Global.top_menu_container.file_menu.set_item_text( - Global.FileMenu.SAVE, tr("Save") + " %s" % save_path.get_file() + Global.FileMenu.SAVE, tr("Save") + " %s" % file_name ) else: Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save")) @@ -347,7 +346,6 @@ func serialize() -> Dictionary: "brushes": brush_data, "reference_images": reference_image_data, "vanishing_points": vanishing_points, - "export_directory_path": export_directory_path, "export_file_name": file_name, "export_file_format": file_format, "fps": fps, @@ -466,8 +464,6 @@ func deserialize(dict: Dictionary, zip_reader: ZIPReader = null, file: FileAcces x_symmetry_axis.points[point].y = floorf(y_symmetry_point / 2 + 1) for point in y_symmetry_axis.points.size(): y_symmetry_axis.points[point].x = floorf(x_symmetry_point / 2 + 1) - if dict.has("export_directory_path"): - export_directory_path = dict.export_directory_path if dict.has("export_file_name"): file_name = dict.export_file_name if dict.has("export_file_format"): diff --git a/src/Main.gd b/src/Main.gd index ead47a38d..b600c3d33 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -263,10 +263,6 @@ func load_recent_project_file(path: String) -> void: # Check if file still exists on disk if FileAccess.file_exists(path): # If yes then load the file OpenSave.handle_loading_file(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.popup_error("Cannot find project file.") @@ -276,7 +272,6 @@ func _on_OpenSprite_files_selected(paths: PackedStringArray) -> void: for path in paths: OpenSave.handle_loading_file(path) Global.save_sprites_dialog.current_dir = paths[0].get_base_dir() - Global.config_cache.set_value("data", "current_dir", paths[0].get_base_dir()) func show_save_dialog(project := Global.current_project) -> void: @@ -311,7 +306,6 @@ func save_project(path: String) -> void: var success := OpenSave.save_pxo_file(path, false, include_blended, project_to_save) if success: 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: changed_projects_on_quit.pop_front() _save_on_quit_confirmation()