From be6d48fcad49b8ed5ed68dd4ce86bf486941b90d Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Mon, 10 Jun 2019 00:20:24 -0300 Subject: [PATCH] Add toggle for hidden file visibility in FileDialog --- scene/gui/file_dialog.cpp | 23 ++++++++++++------ scene/gui/file_dialog.h | 1 + .../resources/default_theme/default_theme.cpp | 3 ++- .../default_theme/icon_visibility.png | Bin 0 -> 488 bytes scene/resources/default_theme/theme_data.h | 4 +++ 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 scene/resources/default_theme/icon_visibility.png diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index bdb1342019..bc8dcf0e82 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -48,8 +48,9 @@ void FileDialog::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - refresh->set_icon(get_icon("reload")); dir_up->set_icon(get_icon("parent_folder")); + refresh->set_icon(get_icon("reload")); + show_hidden->set_icon(get_icon("toggle_hidden")); } if (p_what == NOTIFICATION_POPUP_HIDE) { @@ -393,20 +394,19 @@ void FileDialog::update_file_list() { List files; List dirs; - bool isdir; - bool ishidden; - bool show_hidden = show_hidden_files; + bool is_dir; + bool is_hidden; String item; - while ((item = dir_access->get_next(&isdir)) != "") { + while ((item = dir_access->get_next(&is_dir)) != "") { if (item == "." || item == "..") continue; - ishidden = dir_access->current_is_hidden(); + is_hidden = dir_access->current_is_hidden(); - if (show_hidden || !ishidden) { - if (!isdir) + if (show_hidden_files || !is_hidden) { + if (!is_dir) files.push_back(item); else dirs.push_back(item); @@ -873,6 +873,13 @@ FileDialog::FileDialog() { refresh->connect("pressed", this, "_update_file_list"); hbc->add_child(refresh); + show_hidden = memnew(ToolButton); + show_hidden->set_toggle_mode(true); + show_hidden->set_pressed(is_showing_hidden_files()); + show_hidden->set_tooltip(RTR("Toggle Hidden Files")); + show_hidden->connect("toggled", this, "set_show_hidden_files"); + hbc->add_child(show_hidden); + drives = memnew(OptionButton); hbc->add_child(drives); drives->connect("item_selected", this, "_select_drive"); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 85edac0b12..9f7ea1a2f2 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -90,6 +90,7 @@ private: ToolButton *dir_up; ToolButton *refresh; + ToolButton *show_hidden; Vector filters; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index e8359e3dfe..2c5dfc375c 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -541,8 +541,9 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const // File Dialog - theme->set_icon("reload", "FileDialog", make_icon(icon_reload_png)); theme->set_icon("parent_folder", "FileDialog", make_icon(icon_parent_folder_png)); + theme->set_icon("reload", "FileDialog", make_icon(icon_reload_png)); + theme->set_icon("toggle_hidden", "FileDialog", make_icon(icon_visibility_png)); // Popup diff --git a/scene/resources/default_theme/icon_visibility.png b/scene/resources/default_theme/icon_visibility.png new file mode 100644 index 0000000000000000000000000000000000000000..6402571f3ec44d32d7ef794882888a7b702dde9b GIT binary patch literal 488 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJbFq_W2nPqp?T7vkfLzW3kH}&M z2EHR8%s5q>PZ}sFS>hT|5}cn_Ql40p%1~Zju9umYU7Va)kgAtols@~NjTBJPv;dzF zS0H`={{6>~A3uBc?CRC4H*Vaxef##^yLTTxd8E z*+3Ga213H*K{P}Pqz(*#Ccu~o8mr*;I^JzSml>4=`2{m@aB}hR^6?7_3G3+_8Jn3~ zczAjT1c!#@HLFs`LF&wxH$9f(<$6@euk@YHpMQyKWW