diff options
Diffstat (limited to 'editor/editor_file_dialog.cpp')
-rw-r--r-- | editor/editor_file_dialog.cpp | 263 |
1 files changed, 154 insertions, 109 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 0e851734a7..8956983646 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,10 +30,10 @@ #include "editor_file_dialog.h" -#include "core/os/file_access.h" +#include "core/io/file_access.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include "dependency_editor.h" #include "editor_file_system.h" #include "editor_resource_preview.h" @@ -59,19 +59,24 @@ VBoxContainer *EditorFileDialog::get_vbox() { } void EditorFileDialog::_notification(int p_what) { - if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED) { - // update icons - mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); - mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); - dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); - dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); - dir_up->set_icon(item_list->get_theme_icon("ArrowUp", "EditorIcons")); - refresh->set_icon(item_list->get_theme_icon("Reload", "EditorIcons")); - favorite->set_icon(item_list->get_theme_icon("Favorites", "EditorIcons")); - show_hidden->set_icon(item_list->get_theme_icon("GuiVisibilityVisible", "EditorIcons")); - - fav_up->set_icon(item_list->get_theme_icon("MoveUp", "EditorIcons")); - fav_down->set_icon(item_list->get_theme_icon("MoveDown", "EditorIcons")); + if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED || p_what == Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { + // Update icons. + mode_thumbnails->set_icon(item_list->get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons"))); + mode_list->set_icon(item_list->get_theme_icon(SNAME("FileList"), SNAME("EditorIcons"))); + if (is_layout_rtl()) { + dir_prev->set_icon(item_list->get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + dir_next->set_icon(item_list->get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + } else { + dir_prev->set_icon(item_list->get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + dir_next->set_icon(item_list->get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + } + dir_up->set_icon(item_list->get_theme_icon(SNAME("ArrowUp"), SNAME("EditorIcons"))); + refresh->set_icon(item_list->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); + favorite->set_icon(item_list->get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons"))); + show_hidden->set_icon(item_list->get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons"))); + + fav_up->set_icon(item_list->get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons"))); + fav_down->set_icon(item_list->get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons"))); } else if (p_what == NOTIFICATION_PROCESS) { if (preview_waiting) { @@ -81,7 +86,7 @@ void EditorFileDialog::_notification(int p_what) { if (preview_wheel_index >= 8) { preview_wheel_index = 0; } - Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons"); + Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), SNAME("EditorIcons")); preview->set_texture(frame); preview_wheel_timeout = 0.1; } @@ -94,17 +99,22 @@ void EditorFileDialog::_notification(int p_what) { } set_display_mode((DisplayMode)EditorSettings::get_singleton()->get("filesystem/file_dialog/display_mode").operator int()); - // update icons - mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); - mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); - dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); - dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); - dir_up->set_icon(item_list->get_theme_icon("ArrowUp", "EditorIcons")); - refresh->set_icon(item_list->get_theme_icon("Reload", "EditorIcons")); - favorite->set_icon(item_list->get_theme_icon("Favorites", "EditorIcons")); - - fav_up->set_icon(item_list->get_theme_icon("MoveUp", "EditorIcons")); - fav_down->set_icon(item_list->get_theme_icon("MoveDown", "EditorIcons")); + // Update icons. + mode_thumbnails->set_icon(item_list->get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons"))); + mode_list->set_icon(item_list->get_theme_icon(SNAME("FileList"), SNAME("EditorIcons"))); + if (is_layout_rtl()) { + dir_prev->set_icon(item_list->get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + dir_next->set_icon(item_list->get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + } else { + dir_prev->set_icon(item_list->get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + dir_next->set_icon(item_list->get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + } + dir_up->set_icon(item_list->get_theme_icon(SNAME("ArrowUp"), SNAME("EditorIcons"))); + refresh->set_icon(item_list->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); + favorite->set_icon(item_list->get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons"))); + + fav_up->set_icon(item_list->get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons"))); + fav_down->set_icon(item_list->get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons"))); // DO NOT CALL UPDATE FILE LIST HERE, ALL HUNDREDS OF HIDDEN DIALOGS WILL RESPOND, CALL INVALIDATE INSTEAD invalidate(); } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { @@ -114,7 +124,9 @@ void EditorFileDialog::_notification(int p_what) { } } -void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { +void EditorFileDialog::unhandled_input(const Ref<InputEvent> &p_event) { + ERR_FAIL_COND(p_event.is_null()); + Ref<InputEventKey> k = p_event; if (k.is_valid()) { @@ -138,9 +150,7 @@ void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { handled = true; } if (ED_IS_SHORTCUT("file_dialog/toggle_hidden_files", p_event)) { - bool show = !show_hidden_files; - set_show_hidden_files(show); - EditorSettings::get_singleton()->set("filesystem/file_dialog/show_hidden_files", show); + set_show_hidden_files(!show_hidden_files); handled = true; } if (ED_IS_SHORTCUT("file_dialog/toggle_favorite", p_event)) { @@ -204,14 +214,14 @@ void EditorFileDialog::update_dir() { dir->set_text(dir_access->get_current_dir(false)); // Disable "Open" button only when selecting file(s) mode. - get_ok()->set_disabled(_is_open_should_be_disabled()); + get_ok_button()->set_disabled(_is_open_should_be_disabled()); switch (mode) { case FILE_MODE_OPEN_FILE: case FILE_MODE_OPEN_FILES: - get_ok()->set_text(TTR("Open")); + get_ok_button()->set_text(TTR("Open")); break; case FILE_MODE_OPEN_DIR: - get_ok()->set_text(TTR("Select Current Folder")); + get_ok_button()->set_text(TTR("Select Current Folder")); break; case FILE_MODE_OPEN_ANY: case FILE_MODE_SAVE_FILE: @@ -220,15 +230,14 @@ void EditorFileDialog::update_dir() { } } -void EditorFileDialog::_dir_entered(String p_dir) { +void EditorFileDialog::_dir_submitted(String p_dir) { dir_access->change_dir(p_dir); - file->set_text(""); invalidate(); update_dir(); _push_history(); } -void EditorFileDialog::_file_entered(const String &p_file) { +void EditorFileDialog::_file_submitted(const String &p_file) { _action_pressed(); } @@ -236,11 +245,19 @@ void EditorFileDialog::_save_confirm_pressed() { String f = dir_access->get_current_dir().plus_file(file->get_text()); _save_to_recent(); hide(); - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); } void EditorFileDialog::_post_popup() { ConfirmationDialog::_post_popup(); + + // Check if the current path doesn't exist and correct it. + String current = dir_access->get_current_dir(); + while (!dir_access->dir_exists(current)) { + current = current.get_base_dir(); + } + set_current_dir(current); + if (invalidated) { update_file_list(); invalidated = false; @@ -262,8 +279,8 @@ void EditorFileDialog::_post_popup() { } if (is_visible()) { - Ref<Texture2D> folder = item_list->get_theme_icon("folder", "FileDialog"); - const Color folder_color = item_list->get_theme_color("folder_icon_modulate", "FileDialog"); + Ref<Texture2D> folder = item_list->get_theme_icon(SNAME("folder"), SNAME("FileDialog")); + const Color folder_color = item_list->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog")); recent->clear(); bool res = access == ACCESS_RESOURCES; @@ -277,13 +294,22 @@ void EditorFileDialog::_post_popup() { if (res && name == "res://") { name = "/"; } else { + if (name.ends_with("/")) { + name = name.substr(0, name.length() - 1); + } name = name.get_file() + "/"; } - - recent->add_item(name, folder); - recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]); - recent->set_item_icon_modulate(recent->get_item_count() - 1, folder_color); + bool exists = dir_access->dir_exists(recentd[i]); + if (!exists) { + // Remove invalid directory from the list of Recent directories. + recentd.remove(i--); + } else { + recent->add_item(name, folder); + recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]); + recent->set_item_icon_modulate(recent->get_item_count() - 1, folder_color); + } } + EditorSettings::get_singleton()->set_recent_dirs(recentd); local_history.clear(); local_history_pos = -1; @@ -353,7 +379,7 @@ void EditorFileDialog::_action_pressed() { if (files.size()) { _save_to_recent(); hide(); - emit_signal("files_selected", files); + emit_signal(SNAME("files_selected"), files); } return; @@ -364,7 +390,7 @@ void EditorFileDialog::_action_pressed() { if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) { _save_to_recent(); hide(); - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) { String path = dir_access->get_current_dir(); @@ -383,7 +409,7 @@ void EditorFileDialog::_action_pressed() { _save_to_recent(); hide(); - emit_signal("dir_selected", path); + emit_signal(SNAME("dir_selected"), path); } if (mode == FILE_MODE_SAVE_FILE) { @@ -434,9 +460,12 @@ void EditorFileDialog::_action_pressed() { } } + // Add first extension of filter if no valid extension is found. if (!valid) { - exterr->popup_centered(Size2(250, 80) * EDSCALE); - return; + int idx = filter->get_selected(); + String flt = filters[idx].get_slice(";", 0); + String ext = flt.get_slice(",", 0).strip_edges().get_extension(); + f += "." + ext; } if (dir_access->file_exists(f) && !disable_overwrite_warning) { @@ -445,7 +474,7 @@ void EditorFileDialog::_action_pressed() { } else { _save_to_recent(); hide(); - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); } } } @@ -468,10 +497,10 @@ 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 == FILE_MODE_OPEN_DIR) { - get_ok()->set_text(TTR("Select This Folder")); + get_ok_button()->set_text(TTR("Select This Folder")); } - get_ok()->set_disabled(_is_open_should_be_disabled()); + get_ok_button()->set_disabled(_is_open_should_be_disabled()); } void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { @@ -487,23 +516,23 @@ void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); } - get_ok()->set_disabled(_is_open_should_be_disabled()); + get_ok_button()->set_disabled(_is_open_should_be_disabled()); } void EditorFileDialog::_items_clear_selection() { - item_list->unselect_all(); + item_list->deselect_all(); // If nothing is selected, then block Open button. switch (mode) { case FILE_MODE_OPEN_FILE: case FILE_MODE_OPEN_FILES: - get_ok()->set_text(TTR("Open")); - get_ok()->set_disabled(!item_list->is_anything_selected()); + get_ok_button()->set_text(TTR("Open")); + get_ok_button()->set_disabled(!item_list->is_anything_selected()); break; case FILE_MODE_OPEN_DIR: - get_ok()->set_disabled(false); - get_ok()->set_text(TTR("Select Current Folder")); + get_ok_button()->set_disabled(false); + get_ok_button()->set_text(TTR("Select Current Folder")); break; case FILE_MODE_OPEN_ANY: @@ -534,8 +563,8 @@ void EditorFileDialog::_item_dc_selected(int p_item) { if (d["dir"]) { dir_access->change_dir(d["name"]); - call_deferred("_update_file_list"); - call_deferred("_update_dir"); + call_deferred(SNAME("_update_file_list")); + call_deferred(SNAME("_update_dir")); _push_history(); @@ -559,23 +588,23 @@ void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p continue; } Dictionary item_meta = item_list->get_item_metadata(i); - if (item_meta["path"] == "res://.import") { + if (String(item_meta["path"]).begins_with("res://.godot")) { allow_delete = false; break; } } if (single_item_selected) { - item_menu->add_icon_item(item_list->get_theme_icon("ActionCopy", "EditorIcons"), TTR("Copy Path"), ITEM_MENU_COPY_PATH); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), TTR("Copy Path"), ITEM_MENU_COPY_PATH); } if (allow_delete) { - item_menu->add_icon_item(item_list->get_theme_icon("Remove", "EditorIcons"), TTR("Delete"), ITEM_MENU_DELETE, KEY_DELETE); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete"), ITEM_MENU_DELETE, KEY_DELETE); } if (single_item_selected) { item_menu->add_separator(); Dictionary item_meta = item_list->get_item_metadata(p_item); String item_text = item_meta["dir"] ? TTR("Open in File Manager") : TTR("Show in File Manager"); - item_menu->add_icon_item(item_list->get_theme_icon("Filesystem", "EditorIcons"), item_text, ITEM_MENU_SHOW_IN_EXPLORER); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), item_text, ITEM_MENU_SHOW_IN_EXPLORER); } if (item_menu->get_item_count() > 0) { @@ -587,18 +616,18 @@ void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p void EditorFileDialog::_item_list_rmb_clicked(const Vector2 &p_pos) { // Right click on folder background. Deselect all files so that actions are applied on the current folder. for (int i = 0; i < item_list->get_item_count(); i++) { - item_list->unselect(i); + item_list->deselect(i); } item_menu->clear(); item_menu->set_size(Size2(1, 1)); if (can_create_dir) { - item_menu->add_icon_item(item_list->get_theme_icon("folder", "FileDialog"), TTR("New Folder..."), ITEM_MENU_NEW_FOLDER, KEY_MASK_CMD | KEY_N); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("folder"), SNAME("FileDialog")), TTR("New Folder..."), ITEM_MENU_NEW_FOLDER, KEY_MASK_CMD | KEY_N); } - item_menu->add_icon_item(item_list->get_theme_icon("Reload", "EditorIcons"), TTR("Refresh"), ITEM_MENU_REFRESH, KEY_F5); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), TTR("Refresh"), ITEM_MENU_REFRESH, KEY_F5); item_menu->add_separator(); - item_menu->add_icon_item(item_list->get_theme_icon("Filesystem", "EditorIcons"), TTR("Open in File Manager"), ITEM_MENU_SHOW_IN_EXPLORER); + item_menu->add_icon_item(item_list->get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), TTR("Open in File Manager"), ITEM_MENU_SHOW_IN_EXPLORER); item_menu->set_position(item_list->get_global_position() + p_pos); item_menu->popup(); @@ -699,14 +728,15 @@ void EditorFileDialog::update_file_list() { item_list->set_icon_mode(ItemList::ICON_MODE_TOP); item_list->set_fixed_column_width(thumbnail_size * 3 / 2); item_list->set_max_text_lines(2); + item_list->set_text_overrun_behavior(TextParagraph::OVERRUN_TRIM_ELLIPSIS); item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); if (thumbnail_size < 64) { - folder_thumbnail = item_list->get_theme_icon("FolderMediumThumb", "EditorIcons"); - file_thumbnail = item_list->get_theme_icon("FileMediumThumb", "EditorIcons"); + folder_thumbnail = item_list->get_theme_icon(SNAME("FolderMediumThumb"), SNAME("EditorIcons")); + file_thumbnail = item_list->get_theme_icon(SNAME("FileMediumThumb"), SNAME("EditorIcons")); } else { - folder_thumbnail = item_list->get_theme_icon("FolderBigThumb", "EditorIcons"); - file_thumbnail = item_list->get_theme_icon("FileBigThumb", "EditorIcons"); + folder_thumbnail = item_list->get_theme_icon(SNAME("FolderBigThumb"), SNAME("EditorIcons")); + file_thumbnail = item_list->get_theme_icon(SNAME("FileBigThumb"), SNAME("EditorIcons")); } preview_vb->hide(); @@ -726,8 +756,8 @@ void EditorFileDialog::update_file_list() { dir_access->list_dir_begin(); - Ref<Texture2D> folder = item_list->get_theme_icon("folder", "FileDialog"); - const Color folder_color = item_list->get_theme_color("folder_icon_modulate", "FileDialog"); + Ref<Texture2D> folder = item_list->get_theme_icon(SNAME("folder"), SNAME("FileDialog")); + const Color folder_color = item_list->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog")); List<String> files; List<String> dirs; @@ -750,7 +780,7 @@ void EditorFileDialog::update_file_list() { dirs.sort_custom<NaturalNoCaseComparator>(); files.sort_custom<NaturalNoCaseComparator>(); - while (!dirs.empty()) { + while (!dirs.is_empty()) { const String &dir_name = dirs.front()->get(); item_list->add_item(dir_name); @@ -798,11 +828,11 @@ void EditorFileDialog::update_file_list() { } } - while (!files.empty()) { - bool match = patterns.empty(); + while (!files.is_empty()) { + bool match = patterns.is_empty(); - for (List<String>::Element *E = patterns.front(); E; E = E->next()) { - if (files.front()->get().matchn(E->get())) { + for (const String &E : patterns) { + if (files.front()->get().matchn(E)) { match = true; break; } @@ -841,13 +871,13 @@ void EditorFileDialog::update_file_list() { } if (favorites->get_current() >= 0) { - favorites->unselect(favorites->get_current()); + favorites->deselect(favorites->get_current()); } favorite->set_pressed(false); fav_up->set_disabled(true); fav_down->set_disabled(true); - get_ok()->set_disabled(_is_open_should_be_disabled()); + get_ok_button()->set_disabled(_is_open_should_be_disabled()); for (int i = 0; i < favorites->get_item_count(); i++) { if (favorites->get_item_metadata(i) == cdir || favorites->get_item_metadata(i) == cdir + "/") { favorites->select(i); @@ -928,7 +958,7 @@ String EditorFileDialog::get_current_path() const { } void EditorFileDialog::set_current_dir(const String &p_dir) { - if (p_dir.is_rel_path()) { + if (p_dir.is_relative_path()) { dir_access->change_dir(OS::get_singleton()->get_resource_dir()); } dir_access->change_dir(p_dir); @@ -970,27 +1000,27 @@ void EditorFileDialog::set_file_mode(FileMode p_mode) { mode = p_mode; switch (mode) { case FILE_MODE_OPEN_FILE: - get_ok()->set_text(TTR("Open")); + get_ok_button()->set_text(TTR("Open")); set_title(TTR("Open a File")); can_create_dir = false; break; case FILE_MODE_OPEN_FILES: - get_ok()->set_text(TTR("Open")); + get_ok_button()->set_text(TTR("Open")); set_title(TTR("Open File(s)")); can_create_dir = false; break; case FILE_MODE_OPEN_DIR: - get_ok()->set_text(TTR("Open")); + get_ok_button()->set_text(TTR("Open")); set_title(TTR("Open a Directory")); can_create_dir = true; break; case FILE_MODE_OPEN_ANY: - get_ok()->set_text(TTR("Open")); + get_ok_button()->set_text(TTR("Open")); set_title(TTR("Open a File or Directory")); can_create_dir = true; break; case FILE_MODE_SAVE_FILE: - get_ok()->set_text(TTR("Save")); + get_ok_button()->set_text(TTR("Save")); set_title(TTR("Save a File")); can_create_dir = true; break; @@ -1052,9 +1082,9 @@ EditorFileDialog::Access EditorFileDialog::get_access() const { } void EditorFileDialog::_make_dir_confirm() { - Error err = dir_access->make_dir(makedirname->get_text()); + Error err = dir_access->make_dir(makedirname->get_text().strip_edges()); if (err == OK) { - dir_access->change_dir(makedirname->get_text()); + dir_access->change_dir(makedirname->get_text().strip_edges()); invalidate(); update_filters(); update_dir(); @@ -1126,7 +1156,6 @@ void EditorFileDialog::_update_drives() { void EditorFileDialog::_favorite_selected(int p_idx) { dir_access->change_dir(favorites->get_item_metadata(p_idx)); - file->set_text(""); update_dir(); invalidate(); _push_history(); @@ -1178,8 +1207,8 @@ void EditorFileDialog::_update_favorites() { bool res = access == ACCESS_RESOURCES; String current = get_current_dir(); - Ref<Texture2D> folder_icon = item_list->get_theme_icon("Folder", "EditorIcons"); - const Color folder_color = item_list->get_theme_color("folder_icon_modulate", "FileDialog"); + Ref<Texture2D> folder_icon = item_list->get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")); + const Color folder_color = item_list->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog")); favorites->clear(); favorite->set_pressed(false); @@ -1218,7 +1247,7 @@ void EditorFileDialog::_update_favorites() { if (setthis) { favorite->set_pressed(true); favorites->set_current(favorites->get_item_count() - 1); - recent->unselect_all(); + recent->deselect_all(); } } } @@ -1326,8 +1355,6 @@ EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const { } void EditorFileDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorFileDialog::_unhandled_input); - ClassDB::bind_method(D_METHOD("_cancel_pressed"), &EditorFileDialog::_cancel_pressed); ClassDB::bind_method(D_METHOD("clear_filters"), &EditorFileDialog::clear_filters); @@ -1385,6 +1412,11 @@ void EditorFileDialog::_bind_methods() { } void EditorFileDialog::set_show_hidden_files(bool p_show) { + if (p_show == show_hidden_files) { + return; + } + + EditorSettings::get_singleton()->set("filesystem/file_dialog/show_hidden_files", p_show); show_hidden_files = p_show; show_hidden->set_pressed(p_show); invalidate(); @@ -1477,12 +1509,15 @@ EditorFileDialog::EditorFileDialog() { dir_next->connect("pressed", callable_mp(this, &EditorFileDialog::_go_forward)); dir_up->connect("pressed", callable_mp(this, &EditorFileDialog::_go_up)); - pathhb->add_child(memnew(Label(TTR("Path:")))); + Label *l = memnew(Label(TTR("Path:"))); + l->set_theme_type_variation("HeaderSmall"); + pathhb->add_child(l); drives_container = memnew(HBoxContainer); pathhb->add_child(drives_container); dir = memnew(LineEdit); + dir->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); pathhb->add_child(dir); dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -1510,7 +1545,7 @@ EditorFileDialog::EditorFileDialog() { pathhb->add_child(memnew(VSeparator)); Ref<ButtonGroup> view_mode_group; - view_mode_group.instance(); + view_mode_group.instantiate(); mode_thumbnails = memnew(Button); mode_thumbnails->set_flat(true); @@ -1557,7 +1592,11 @@ EditorFileDialog::EditorFileDialog() { fav_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); HBoxContainer *fav_hb = memnew(HBoxContainer); fav_vb->add_child(fav_hb); - fav_hb->add_child(memnew(Label(TTR("Favorites:")))); + + l = memnew(Label(TTR("Favorites:"))); + l->set_theme_type_variation("HeaderSmall"); + fav_hb->add_child(l); + fav_hb->add_spacer(); fav_up = memnew(Button); fav_up->set_flat(true); @@ -1592,7 +1631,10 @@ EditorFileDialog::EditorFileDialog() { VBoxContainer *list_vb = memnew(VBoxContainer); list_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - list_vb->add_child(memnew(Label(TTR("Directories & Files:")))); + + l = memnew(Label(TTR("Directories & Files:"))); + l->set_theme_type_variation("HeaderSmall"); + list_vb->add_child(l); preview_hb->add_child(list_vb); // Item (files and folders) list with context menu. @@ -1602,6 +1644,7 @@ EditorFileDialog::EditorFileDialog() { item_list->connect("item_rmb_selected", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_selected)); item_list->connect("rmb_clicked", callable_mp(this, &EditorFileDialog::_item_list_rmb_clicked)); item_list->set_allow_rmb_select(true); + list_vb->add_child(item_list); item_menu = memnew(PopupMenu); @@ -1619,8 +1662,13 @@ EditorFileDialog::EditorFileDialog() { preview_vb->hide(); file_box = memnew(HBoxContainer); - file_box->add_child(memnew(Label(TTR("File:")))); + + l = memnew(Label(TTR("File:"))); + l->set_theme_type_variation("HeaderSmall"); + file_box->add_child(l); + file = memnew(LineEdit); + file->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); file->set_stretch_ratio(4); file->set_h_size_flags(Control::SIZE_EXPAND_FILL); file_box->add_child(file); @@ -1641,12 +1689,12 @@ EditorFileDialog::EditorFileDialog() { item_list->connect("multi_selected", callable_mp(this, &EditorFileDialog::_multi_selected), varray(), CONNECT_DEFERRED); item_list->connect("item_activated", callable_mp(this, &EditorFileDialog::_item_dc_selected), varray()); item_list->connect("nothing_selected", callable_mp(this, &EditorFileDialog::_items_clear_selection)); - dir->connect("text_entered", callable_mp(this, &EditorFileDialog::_dir_entered)); - file->connect("text_entered", callable_mp(this, &EditorFileDialog::_file_entered)); + dir->connect("text_submitted", callable_mp(this, &EditorFileDialog::_dir_submitted)); + file->connect("text_submitted", callable_mp(this, &EditorFileDialog::_file_submitted)); filter->connect("item_selected", callable_mp(this, &EditorFileDialog::_filter_selected)); confirm_save = memnew(ConfirmationDialog); - //confirm_save->set_as_toplevel(true); + //confirm_save->set_as_top_level(true); add_child(confirm_save); confirm_save->connect("confirmed", callable_mp(this, &EditorFileDialog::_save_confirm_pressed)); @@ -1659,6 +1707,7 @@ EditorFileDialog::EditorFileDialog() { makedialog->add_child(makevb); makedirname = memnew(LineEdit); + makedirname->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); makevb->add_margin_child(TTR("Name:"), makedirname); add_child(makedialog); makedialog->register_text_enter(makedirname); @@ -1667,10 +1716,6 @@ EditorFileDialog::EditorFileDialog() { mkdirerr->set_text(TTR("Could not create folder.")); add_child(mkdirerr); - exterr = memnew(AcceptDialog); - exterr->set_text(TTR("Must use a valid extension.")); - add_child(exterr); - update_filters(); update_dir(); |