diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-27 00:23:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-27 00:23:15 +0100 |
commit | 2755eeb2f001179fc650342b3a5d8930692decb5 (patch) | |
tree | cbeffd56dbff38c45d832ff0a0106a2585c824ad /scene/gui | |
parent | 024c4f14a14e67f15adbcca39c6a941ea89e0f3d (diff) | |
parent | e3b0214f401da3cbb18a81cee0f0f5631f43239b (diff) |
Merge pull request #13252 from Krakean/file_dialogs_small_tweaks
A few adjustments to file/dir open dialogs
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/file_dialog.cpp | 30 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 3 |
2 files changed, 30 insertions, 3 deletions
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 6aba535572..663a2b390e 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -85,6 +85,10 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { invalidate(); } break; + case KEY_BACKSPACE: { + + _dir_entered(".."); + } break; default: { handled = false; } } @@ -189,7 +193,7 @@ void FileDialog::_action_pressed() { TreeItem *item = tree->get_selected(); if (item) { Dictionary d = item->get_metadata(0); - if (d["dir"]) { + if (d["dir"] && d["name"] != "..") { path = path.plus_file(d["name"]); } } @@ -272,6 +276,26 @@ void FileDialog::_cancel_pressed() { hide(); } +bool FileDialog::_is_open_should_be_disabled() { + + if (mode == MODE_OPEN_ANY || mode == MODE_SAVE_FILE) + return false; + + TreeItem *ti = tree->get_selected(); + // We have something that we can't select? + if (!ti) + return true; + + 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; +} + void FileDialog::_tree_selected() { TreeItem *ti = tree->get_selected(); @@ -283,6 +307,8 @@ void FileDialog::_tree_selected() { file->set_text(d["name"]); } + + get_ok()->set_disabled(_is_open_should_be_disabled()); } void FileDialog::_tree_dc_selected() { @@ -563,7 +589,7 @@ void FileDialog::set_mode(Mode p_mode) { makedir->hide(); break; case MODE_OPEN_DIR: - get_ok()->set_text(RTR("Open")); + get_ok()->set_text(RTR("Select Current Folder")); set_title(RTR("Open a Directory")); makedir->show(); break; diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 34cecfe4d0..6281e88731 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -33,7 +33,6 @@ #include "box_container.h" #include "os/dir_access.h" #include "scene/gui/dialogs.h" -#include "scene/gui/dialogs.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" #include "scene/gui/tool_button.h" @@ -117,6 +116,8 @@ private: void _unhandled_input(const Ref<InputEvent> &p_event); + bool _is_open_should_be_disabled(); + virtual void _post_popup(); protected: |