mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
open file dialogs at the most recent folder
This commit is contained in:
parent
4f40e91726
commit
9938bb9519
2 changed files with 20 additions and 6 deletions
|
@ -34,6 +34,7 @@ enum FileMenuId {
|
||||||
@onready var file_popup_menu: PopupMenu = %File as PopupMenu
|
@onready var file_popup_menu: PopupMenu = %File as PopupMenu
|
||||||
var max_recents := 4
|
var max_recents := 4
|
||||||
var recent_files := []
|
var recent_files := []
|
||||||
|
var recent_path: String
|
||||||
@onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck
|
@onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck
|
||||||
@onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog
|
@onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog
|
||||||
|
|
||||||
|
@ -60,6 +61,10 @@ func _ready() -> void:
|
||||||
PERSISTENCE_NAMESPACE, "config",
|
PERSISTENCE_NAMESPACE, "config",
|
||||||
"recent_files", []
|
"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()
|
add_recents_to_menu()
|
||||||
|
|
||||||
tab_container.tab_close_requested.connect(
|
tab_container.tab_close_requested.connect(
|
||||||
|
@ -91,11 +96,11 @@ func _on_file_id_pressed(id: int) -> void:
|
||||||
FileMenuId.NEW:
|
FileMenuId.NEW:
|
||||||
add_empty_deck()
|
add_empty_deck()
|
||||||
FileMenuId.OPEN:
|
FileMenuId.OPEN:
|
||||||
open_open_dialog("res://")
|
open_open_dialog(recent_path)
|
||||||
FileMenuId.SAVE:
|
FileMenuId.SAVE when tab_container.get_tab_count() > 0:
|
||||||
save_active_deck()
|
save_active_deck()
|
||||||
FileMenuId.SAVE_AS:
|
FileMenuId.SAVE_AS when tab_container.get_tab_count() > 0:
|
||||||
open_save_dialog("res://")
|
open_save_dialog(tab_container.get_tab_metadata(tab_container.get_current_tab(), "path"))
|
||||||
FileMenuId.CLOSE:
|
FileMenuId.CLOSE:
|
||||||
close_current_tab()
|
close_current_tab()
|
||||||
_ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1):
|
_ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1):
|
||||||
|
@ -108,6 +113,7 @@ func add_empty_deck() -> void:
|
||||||
inst.deck = deck
|
inst.deck = deck
|
||||||
tab_container.add_content(inst, "<unsaved deck>")
|
tab_container.add_content(inst, "<unsaved deck>")
|
||||||
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id)
|
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.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
||||||
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
|
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:
|
func open_open_dialog(path: String) -> void:
|
||||||
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILES
|
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILES
|
||||||
file_dialog.title = "Open Deck(s)"
|
file_dialog.title = "Open Deck(s)"
|
||||||
file_dialog.current_path = path
|
file_dialog.current_path = path + "/"
|
||||||
file_dialog.popup_centered()
|
file_dialog.popup_centered()
|
||||||
file_dialog.files_selected.connect(_on_file_dialog_open_files, CONNECT_ONE_SHOT)
|
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)
|
var f := FileAccess.open(path, FileAccess.WRITE)
|
||||||
f.store_string(json)
|
f.store_string(json)
|
||||||
add_recent_file(get_active_deck().save_path)
|
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
|
## 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
|
inst.deck = deck
|
||||||
tab_container.add_content(inst, path.get_file())
|
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(), "id", deck.id)
|
||||||
|
tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", path)
|
||||||
inst.initialize_from_deck()
|
inst.initialize_from_deck()
|
||||||
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
|
||||||
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
|
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
|
||||||
add_recent_file(path)
|
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]
|
## Gets the currently active [Deck] from [member tab_container]
|
||||||
func get_active_deck() -> Deck:
|
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)
|
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.set_value(PERSISTENCE_NAMESPACE, "config", "recent_files", recent_files)
|
||||||
RendererPersistence.commit(PERSISTENCE_NAMESPACE)
|
|
||||||
|
|
||||||
|
|
||||||
func _notification(what: int) -> void:
|
func _notification(what: int) -> void:
|
||||||
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
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):
|
if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty):
|
||||||
unsaved_changes_dialog.show()
|
unsaved_changes_dialog.show()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -143,6 +143,7 @@ layout_mode = 2
|
||||||
size = Vector2i(776, 447)
|
size = Vector2i(776, 447)
|
||||||
mode_overrides_title = false
|
mode_overrides_title = false
|
||||||
access = 2
|
access = 2
|
||||||
|
filters = PackedStringArray("*.deck ;StreamGraph Decks")
|
||||||
use_native_dialog = true
|
use_native_dialog = true
|
||||||
|
|
||||||
[node name="Connections" type="Node" parent="."]
|
[node name="Connections" type="Node" parent="."]
|
||||||
|
|
Loading…
Reference in a new issue