From e98f0392cc0b1e8a17e22493ac9cc47d8d316169 Mon Sep 17 00:00:00 2001 From: Mew Pur Pur <85438892+MewPurPur@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:38:42 +0300 Subject: [PATCH] Fix system directory highlight not updating in GoodFileDialog (#642) --- src/ui_parts/good_file_dialog.gd | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ui_parts/good_file_dialog.gd b/src/ui_parts/good_file_dialog.gd index b03faf0f..031cf937 100644 --- a/src/ui_parts/good_file_dialog.gd +++ b/src/ui_parts/good_file_dialog.gd @@ -99,19 +99,6 @@ func _ready() -> void: special_button.text = tr("Select") if mode == FileMode.SELECT else tr("Save") path_label.text = tr("Path") + ":" extension_label.text = "." + extension - for dir in [OS.SYSTEM_DIR_DESKTOP, OS.SYSTEM_DIR_DOCUMENTS, OS.SYSTEM_DIR_DOWNLOADS, - OS.SYSTEM_DIR_MOVIES, OS.SYSTEM_DIR_MUSIC, OS.SYSTEM_DIR_PICTURES]: - var dir_string := OS.get_system_dir(dir) - if dir_string.is_empty(): - continue - - var item_idx := system_dir_list.add_item(dir_string.get_file(), - system_dir_icons[dir] if dir in system_dir_icons else folder_icon) - system_dir_list.set_item_metadata(item_idx, - Actions.new(Callable(), enter_dir.bind(dir_string))) - # If you start off in a system dir, highlight it in the list to make it clear. - if current_dir == dir_string: - system_dir_list.select(item_idx) # Should always be safe. set_dir(current_dir) @@ -137,6 +124,20 @@ func set_dir(dir: String) -> void: # Basic setup. current_dir = dir path_field.text = current_dir + # Rebuild the system dirs to see if we now need to highlight the relevant one. + system_dir_list.clear() + for sysdir in [OS.SYSTEM_DIR_DESKTOP, OS.SYSTEM_DIR_DOCUMENTS, OS.SYSTEM_DIR_DOWNLOADS, + OS.SYSTEM_DIR_MOVIES, OS.SYSTEM_DIR_MUSIC, OS.SYSTEM_DIR_PICTURES]: + var dir_string := OS.get_system_dir(sysdir) + if dir_string.is_empty(): + continue + + var item_idx := system_dir_list.add_item(dir_string.get_file(), + system_dir_icons[sysdir] if sysdir in system_dir_icons else folder_icon) + system_dir_list.set_item_metadata(item_idx, + Actions.new(Callable(), enter_dir.bind(dir_string))) + if current_dir == dir_string: + system_dir_list.select(item_idx) # Create the DirAccess object. var DA := DirAccess.open(dir) DA.include_hidden = GlobalSettings.save_data.file_dialog_show_hidden