diff options
author | Dmitry Koteroff <vortex@verona.im> | 2017-11-24 21:12:18 +0300 |
---|---|---|
committer | Dmitry Koteroff <vortex@verona.im> | 2017-11-24 21:21:55 +0300 |
commit | e3b0214f401da3cbb18a81cee0f0f5631f43239b (patch) | |
tree | b8f5444d7f5fe3b33dc124fefa71595022046149 /scene/gui | |
parent | 6086252f66ac185b97b0580352383e4b068b9fe5 (diff) |
A few small adjustments to file dialogs:
a) Added Backspace key support for Tree-based file dialog.
b) Fixed issue inability to select a folder in project manager (always previous folder was selected instead).
c) Open Directory mode: changed "Open" to "Select Current Folder"
d) Block "Open" button when inappropriate content is selected (for example, file when in open folder mode, or folder when in open files mode)
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: |