summaryrefslogtreecommitdiff
path: root/scene/gui/file_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/file_dialog.cpp')
-rw-r--r--scene/gui/file_dialog.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 5599c64daa..04fb991f78 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) {
@@ -86,7 +87,9 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
_dir_entered("..");
} break;
- default: { handled = false; }
+ default: {
+ handled = false;
+ }
}
if (handled)
@@ -299,11 +302,8 @@ bool FileDialog::_is_open_should_be_disabled() {
Dictionary d = ti->get_metadata(0);
// Opening a file, but selected a folder? Forbidden.
- if (((mode == MODE_OPEN_FILE || mode == MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden.
- (mode == MODE_OPEN_DIR && !d["dir"]))
- return true;
-
- return false;
+ return ((mode == MODE_OPEN_FILE || mode == MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden.
+ (mode == MODE_OPEN_DIR && !d["dir"]);
}
void FileDialog::_go_up() {
@@ -381,6 +381,18 @@ void FileDialog::_tree_item_activated() {
}
}
+void FileDialog::update_file_name() {
+ int idx = filter->get_selected() - 1;
+ if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
+ if (idx == -1) idx += 1;
+ String filter_str = filters[idx];
+ String file_str = file->get_text();
+ String base_name = file_str.get_basename();
+ file_str = base_name + "." + filter_str.strip_edges().to_lower();
+ file->set_text(file_str);
+ }
+}
+
void FileDialog::update_file_list() {
tree->clear();
@@ -391,20 +403,19 @@ void FileDialog::update_file_list() {
List<String> files;
List<String> 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);
@@ -429,8 +440,6 @@ void FileDialog::update_file_list() {
dirs.pop_front();
}
- dirs.clear();
-
List<String> patterns;
// build filter
if (filter->get_selected() == filter->get_item_count() - 1) {
@@ -505,12 +514,11 @@ void FileDialog::update_file_list() {
if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == NULL)
tree->get_root()->get_children()->select(0);
-
- files.clear();
}
void FileDialog::_filter_selected(int) {
+ update_file_name();
update_file_list();
}
@@ -802,6 +810,7 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive);
ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir);
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm);
+ ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name);
ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list);
ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir);
ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up);
@@ -861,7 +870,7 @@ FileDialog::FileDialog() {
HBoxContainer *hbc = memnew(HBoxContainer);
dir_up = memnew(ToolButton);
- dir_up->set_tooltip(RTR("Go to parent folder"));
+ dir_up->set_tooltip(RTR("Go to parent folder."));
hbc->add_child(dir_up);
dir_up->connect("pressed", this, "_go_up");
@@ -871,9 +880,17 @@ FileDialog::FileDialog() {
dir->set_h_size_flags(SIZE_EXPAND_FILL);
refresh = memnew(ToolButton);
+ refresh->set_tooltip(RTR("Refresh"));
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");