summaryrefslogtreecommitdiff
path: root/editor/editor_file_dialog.cpp
diff options
context:
space:
mode:
authorDmitry Koteroff <vortex@verona.im>2017-11-24 21:12:18 +0300
committerDmitry Koteroff <vortex@verona.im>2017-11-24 21:21:55 +0300
commite3b0214f401da3cbb18a81cee0f0f5631f43239b (patch)
treeb8f5444d7f5fe3b33dc124fefa71595022046149 /editor/editor_file_dialog.cpp
parent6086252f66ac185b97b0580352383e4b068b9fe5 (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 'editor/editor_file_dialog.cpp')
-rw-r--r--editor/editor_file_dialog.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index f8b9425a4e..c78b11737e 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -197,6 +197,9 @@ Vector<String> EditorFileDialog::get_selected_files() const {
void EditorFileDialog::update_dir() {
dir->set_text(dir_access->get_current_dir());
+
+ // Disable "Open" button only when we in selecting file(s) mode or open dir mode.
+ get_ok()->set_disabled(_is_open_should_be_disabled());
}
void EditorFileDialog::_dir_entered(String p_dir) {
@@ -452,6 +455,28 @@ void EditorFileDialog::_item_selected(int p_item) {
file->set_text(d["name"]);
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
}
+
+ get_ok()->set_disabled(_is_open_should_be_disabled());
+}
+
+void EditorFileDialog::_items_clear_selection() {
+
+ item_list->unselect_all();
+
+ // If nothing is selected, then block Open button.
+ switch (mode) {
+
+ case MODE_OPEN_FILE:
+ case MODE_OPEN_FILES:
+ get_ok()->set_text(TTR("Open"));
+ get_ok()->set_disabled(item_list->is_anything_selected() == false);
+ break;
+
+ case MODE_OPEN_DIR:
+ get_ok()->set_disabled(false);
+ get_ok()->set_text(TTR("Select Current Folder"));
+ break;
+ }
}
void EditorFileDialog::_push_history() {
@@ -487,6 +512,26 @@ void EditorFileDialog::_item_dc_selected(int p_item) {
}
}
+bool EditorFileDialog::_is_open_should_be_disabled() {
+
+ if (mode == MODE_OPEN_ANY || mode == MODE_SAVE_FILE)
+ return false;
+
+ Vector<int> items = item_list->get_selected_items();
+ if (items.size() == 0)
+ return true;
+
+ for (int i = 0; i < items.size(); i++) {
+
+ Dictionary d = item_list->get_item_metadata(items.get(i));
+
+ if (((mode == MODE_OPEN_FILE || mode == MODE_OPEN_FILES) && d["dir"]) || (mode == MODE_OPEN_DIR && !d["dir"]))
+ return true;
+ }
+
+ return false;
+}
+
void EditorFileDialog::update_file_list() {
int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
@@ -681,6 +726,7 @@ void EditorFileDialog::update_file_list() {
favorite->set_pressed(false);
fav_up->set_disabled(true);
fav_down->set_disabled(true);
+ get_ok()->set_disabled(_is_open_should_be_disabled());
for (int i = 0; i < favorites->get_item_count(); i++) {
if (favorites->get_item_metadata(i) == base_dir) {
favorites->select(i);
@@ -1139,6 +1185,7 @@ void EditorFileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorFileDialog::_unhandled_input);
ClassDB::bind_method(D_METHOD("_item_selected"), &EditorFileDialog::_item_selected);
+ ClassDB::bind_method(D_METHOD("_items_clear_selection"), &EditorFileDialog::_items_clear_selection);
ClassDB::bind_method(D_METHOD("_item_db_selected"), &EditorFileDialog::_item_dc_selected);
ClassDB::bind_method(D_METHOD("_dir_entered"), &EditorFileDialog::_dir_entered);
ClassDB::bind_method(D_METHOD("_file_entered"), &EditorFileDialog::_file_entered);
@@ -1415,6 +1462,7 @@ EditorFileDialog::EditorFileDialog() {
//cancel->connect("pressed", this,"_cancel_pressed");
item_list->connect("item_selected", this, "_item_selected", varray(), CONNECT_DEFERRED);
item_list->connect("item_activated", this, "_item_db_selected", varray());
+ item_list->connect("nothing_selected", this, "_items_clear_selection");
dir->connect("text_entered", this, "_dir_entered");
file->connect("text_entered", this, "_file_entered");
filter->connect("item_selected", this, "_filter_selected");