diff options
Diffstat (limited to 'editor/editor_file_dialog.cpp')
-rw-r--r-- | editor/editor_file_dialog.cpp | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index f11a30bb86..438d7ea306 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -198,8 +198,22 @@ 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. + // Disable "Open" button only when selecting file(s) mode. get_ok()->set_disabled(_is_open_should_be_disabled()); + switch (mode) { + + case MODE_OPEN_FILE: + case MODE_OPEN_FILES: + get_ok()->set_text(TTR("Open")); + break; + case MODE_OPEN_DIR: + get_ok()->set_text(TTR("Select Current Folder")); + break; + case MODE_OPEN_ANY: + case MODE_SAVE_FILE: + // FIXME: Implement, or refactor to avoid duplication with set_mode + break; + } } void EditorFileDialog::_dir_entered(String p_dir) { @@ -453,6 +467,8 @@ void EditorFileDialog::_item_selected(int p_item) { file->set_text(d["name"]); _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); + } else if (mode == MODE_OPEN_DIR) { + get_ok()->set_text(TTR("Select This Folder")); } get_ok()->set_disabled(_is_open_should_be_disabled()); @@ -485,13 +501,18 @@ void EditorFileDialog::_items_clear_selection() { case MODE_OPEN_FILE: case MODE_OPEN_FILES: get_ok()->set_text(TTR("Open")); - get_ok()->set_disabled(item_list->is_anything_selected() == false); + get_ok()->set_disabled(!item_list->is_anything_selected()); break; case MODE_OPEN_DIR: get_ok()->set_disabled(false); get_ok()->set_text(TTR("Select Current Folder")); break; + + case MODE_OPEN_ANY: + case MODE_SAVE_FILE: + // FIXME: Implement, or refactor to avoid duplication with set_mode + break; } } @@ -637,7 +658,7 @@ bool EditorFileDialog::_is_open_should_be_disabled() { Vector<int> items = item_list->get_selected_items(); if (items.size() == 0) - return true; + return mode != MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder. for (int i = 0; i < items.size(); i++) { @@ -1114,14 +1135,10 @@ void EditorFileDialog::_update_drives() { } void EditorFileDialog::_favorite_selected(int p_idx) { - - Vector<String> favorited = EditorSettings::get_singleton()->get_favorites(); - ERR_FAIL_INDEX(p_idx, favorited.size()); - - dir_access->change_dir(favorited[p_idx]); + dir_access->change_dir(favorites->get_item_metadata(p_idx)); file->set_text(""); - invalidate(); update_dir(); + invalidate(); _push_history(); } @@ -1171,7 +1188,7 @@ void EditorFileDialog::_update_favorites() { bool res = access == ACCESS_RESOURCES; String current = get_current_dir(); - Ref<Texture> star = get_icon("Favorites", "EditorIcons"); + Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons"); favorites->clear(); favorite->set_pressed(false); @@ -1182,16 +1199,23 @@ void EditorFileDialog::_update_favorites() { if (cres != res) continue; String name = favorited[i]; - - bool setthis = name == current; + bool setthis = false; if (res && name == "res://") { + if (name == current) + setthis = true; name = "/"; + } else if (name.ends_with("/")) { + if (name == current) + setthis = true; + name = name.substr(0, name.length() - 1); + name = name.get_file(); + + favorites->add_item(name, folder_icon); } else { - name = name.get_file() + "/"; + continue; // We don't handle favorite files here } - favorites->add_item(name, star); favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]); if (setthis) { |