From 9938bb9519f614d1ed279ca74eee04a2619f5f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 13 Dec 2023 20:16:17 +0300 Subject: [PATCH] open file dialogs at the most recent folder --- graph_node_renderer/deck_holder_renderer.gd | 25 ++++++++++++++----- graph_node_renderer/deck_holder_renderer.tscn | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index bc7e501..82d8372 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -34,6 +34,7 @@ enum FileMenuId { @onready var file_popup_menu: PopupMenu = %File as PopupMenu var max_recents := 4 var recent_files := [] +var recent_path: String @onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck @onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog @@ -60,6 +61,10 @@ func _ready() -> void: PERSISTENCE_NAMESPACE, "config", "recent_files", [] ) + recent_path = RendererPersistence.get_or_create( + PERSISTENCE_NAMESPACE, "config", + "recent_path", OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS) + ) add_recents_to_menu() tab_container.tab_close_requested.connect( @@ -91,11 +96,11 @@ func _on_file_id_pressed(id: int) -> void: FileMenuId.NEW: add_empty_deck() FileMenuId.OPEN: - open_open_dialog("res://") - FileMenuId.SAVE: + open_open_dialog(recent_path) + FileMenuId.SAVE when tab_container.get_tab_count() > 0: save_active_deck() - FileMenuId.SAVE_AS: - open_save_dialog("res://") + FileMenuId.SAVE_AS when tab_container.get_tab_count() > 0: + open_save_dialog(tab_container.get_tab_metadata(tab_container.get_current_tab(), "path")) FileMenuId.CLOSE: close_current_tab() _ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1): @@ -108,6 +113,7 @@ func add_empty_deck() -> void: inst.deck = deck tab_container.add_content(inst, "") tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) + tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", recent_path.path_join("")) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst)) @@ -141,7 +147,7 @@ func open_save_dialog(path: String) -> void: func open_open_dialog(path: String) -> void: file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILES file_dialog.title = "Open Deck(s)" - file_dialog.current_path = path + file_dialog.current_path = path + "/" file_dialog.popup_centered() file_dialog.files_selected.connect(_on_file_dialog_open_files, CONNECT_ONE_SHOT) @@ -161,6 +167,8 @@ func _on_file_dialog_save_file(path: String) -> void: var f := FileAccess.open(path, FileAccess.WRITE) f.store_string(json) add_recent_file(get_active_deck().save_path) + recent_path = path.get_base_dir() + RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path) ## Connected to [signal FileDialog.open_files] on [member file_dialog]. Opens @@ -181,10 +189,14 @@ func open_deck_at_path(path: String) -> void: inst.deck = deck tab_container.add_content(inst, path.get_file()) tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) + tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", path) inst.initialize_from_deck() inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst)) add_recent_file(path) + recent_path = path.get_base_dir() + RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path) + ## Gets the currently active [Deck] from [member tab_container] func get_active_deck() -> Deck: @@ -345,11 +357,12 @@ func add_recents_to_menu() -> void: file_popup_menu.set_item_shortcut(file_popup_menu.get_item_count() - 1, s) RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_files", recent_files) - RendererPersistence.commit(PERSISTENCE_NAMESPACE) func _notification(what: int) -> void: if what == NOTIFICATION_WM_CLOSE_REQUEST: + RendererPersistence.commit(PERSISTENCE_NAMESPACE) + if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty): unsaved_changes_dialog.show() else: diff --git a/graph_node_renderer/deck_holder_renderer.tscn b/graph_node_renderer/deck_holder_renderer.tscn index 2fc4952..634da7f 100644 --- a/graph_node_renderer/deck_holder_renderer.tscn +++ b/graph_node_renderer/deck_holder_renderer.tscn @@ -143,6 +143,7 @@ layout_mode = 2 size = Vector2i(776, 447) mode_overrides_title = false access = 2 +filters = PackedStringArray("*.deck ;StreamGraph Decks") use_native_dialog = true [node name="Connections" type="Node" parent="."]