From be6d48fcad49b8ed5ed68dd4ce86bf486941b90d Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Mon, 10 Jun 2019 00:20:24 -0300 Subject: Add toggle for hidden file visibility in FileDialog --- scene/gui/file_dialog.cpp | 23 +++++++++++++++-------- scene/gui/file_dialog.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'scene/gui') 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; -- cgit v1.2.3