diff options
Diffstat (limited to 'editor/editor_file_dialog.cpp')
-rw-r--r-- | editor/editor_file_dialog.cpp | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 2411852541..561ebb6298 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -55,9 +55,7 @@ VBoxContainer *EditorFileDialog::get_vbox() { } void EditorFileDialog::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - // update icons mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); @@ -72,7 +70,6 @@ void EditorFileDialog::_notification(int p_what) { fav_down->set_icon(item_list->get_theme_icon("MoveDown", "EditorIcons")); } else if (p_what == NOTIFICATION_PROCESS) { - if (preview_waiting) { preview_wheel_timeout -= get_process_delta_time(); if (preview_wheel_timeout <= 0) { @@ -86,7 +83,6 @@ void EditorFileDialog::_notification(int p_what) { } } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - bool is_showing_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"); if (show_hidden_files != is_showing_hidden) set_show_hidden_files(is_showing_hidden); @@ -106,7 +102,6 @@ void EditorFileDialog::_notification(int p_what) { // 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) { - if (!is_visible()) { set_process_unhandled_input(false); } @@ -114,13 +109,10 @@ void EditorFileDialog::_notification(int p_what) { } void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> k = p_event; if (k.is_valid()) { - if (k->is_pressed()) { - bool handled = false; if (ED_IS_SHORTCUT("file_dialog/go_back", p_event)) { @@ -186,12 +178,10 @@ void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { } void EditorFileDialog::set_enable_multiple_selection(bool p_enable) { - item_list->set_select_mode(p_enable ? ItemList::SELECT_MULTI : ItemList::SELECT_SINGLE); }; Vector<String> EditorFileDialog::get_selected_files() const { - Vector<String> list; for (int i = 0; i < item_list->get_item_count(); i++) { if (item_list->is_selected(i)) @@ -201,7 +191,6 @@ Vector<String> EditorFileDialog::get_selected_files() const { }; void EditorFileDialog::update_dir() { - if (drives->is_visible()) { drives->select(dir_access->get_current_drive()); } @@ -210,7 +199,6 @@ void EditorFileDialog::update_dir() { // Disable "Open" button only when selecting file(s) mode. get_ok()->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")); @@ -226,7 +214,6 @@ void EditorFileDialog::update_dir() { } void EditorFileDialog::_dir_entered(String p_dir) { - dir_access->change_dir(p_dir); file->set_text(""); invalidate(); @@ -235,12 +222,10 @@ void EditorFileDialog::_dir_entered(String p_dir) { } void EditorFileDialog::_file_entered(const String &p_file) { - _action_pressed(); } void EditorFileDialog::_save_confirm_pressed() { - String f = dir_access->get_current_dir().plus_file(file->get_text()); _save_to_recent(); hide(); @@ -248,7 +233,6 @@ void EditorFileDialog::_save_confirm_pressed() { } void EditorFileDialog::_post_popup() { - ConfirmationDialog::_post_popup(); if (invalidated) { update_file_list(); @@ -302,7 +286,6 @@ void EditorFileDialog::_post_popup() { } void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) { - if (display_mode == DISPLAY_LIST || p_preview.is_null()) return; @@ -317,12 +300,10 @@ void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture } void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) { - set_process(false); preview_waiting = false; if (p_preview.is_valid() && get_current_path() == p_path) { - preview->set_texture(p_preview); if (display_mode == DISPLAY_THUMBNAILS) { preview_vb->hide(); @@ -337,7 +318,6 @@ void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture2D } void EditorFileDialog::_request_single_thumbnail(const String &p_path) { - if (!FileAccess::exists(p_path)) return; @@ -348,9 +328,7 @@ void EditorFileDialog::_request_single_thumbnail(const String &p_path) { } void EditorFileDialog::_action_pressed() { - if (mode == FILE_MODE_OPEN_FILES) { - String fbase = dir_access->get_current_dir(); Vector<String> files; @@ -375,7 +353,6 @@ void EditorFileDialog::_action_pressed() { hide(); emit_signal("file_selected", f); } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) { - String path = dir_access->get_current_dir(); path = path.replace("\\", "/"); @@ -397,7 +374,6 @@ void EditorFileDialog::_action_pressed() { } if (mode == FILE_MODE_SAVE_FILE) { - bool valid = false; if (filter->get_selected() == filter->get_item_count() - 1) { @@ -405,10 +381,8 @@ void EditorFileDialog::_action_pressed() { } else if (filters.size() > 1 && filter->get_selected() == 0) { // match all filters for (int i = 0; i < filters.size(); i++) { - String flt = filters[i].get_slice(";", 0); for (int j = 0; j < flt.get_slice_count(","); j++) { - String str = flt.get_slice(",", j).strip_edges(); if (f.match(str)) { valid = true; @@ -423,11 +397,9 @@ void EditorFileDialog::_action_pressed() { if (filters.size() > 1) idx--; if (idx >= 0 && idx < filters.size()) { - String flt = filters[idx].get_slice(";", 0); int filterSliceCount = flt.get_slice_count(","); for (int j = 0; j < filterSliceCount; j++) { - String str = (flt.get_slice(",", j).strip_edges()); if (f.match(str)) { valid = true; @@ -448,7 +420,6 @@ void EditorFileDialog::_action_pressed() { } if (!valid) { - exterr->popup_centered(Size2(250, 80) * EDSCALE); return; } @@ -457,7 +428,6 @@ void EditorFileDialog::_action_pressed() { confirm_save->set_text(TTR("File Exists, Overwrite?")); confirm_save->popup_centered(Size2(200, 80)); } else { - _save_to_recent(); hide(); emit_signal("file_selected", f); @@ -466,14 +436,12 @@ void EditorFileDialog::_action_pressed() { } void EditorFileDialog::_cancel_pressed() { - file->set_text(""); invalidate(); hide(); } void EditorFileDialog::_item_selected(int p_item) { - int current = p_item; if (current < 0 || current >= item_list->get_item_count()) return; @@ -481,7 +449,6 @@ void EditorFileDialog::_item_selected(int p_item) { Dictionary d = item_list->get_item_metadata(current); if (!d["dir"]) { - file->set_text(d["name"]); _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); } else if (mode == FILE_MODE_OPEN_DIR) { @@ -492,7 +459,6 @@ void EditorFileDialog::_item_selected(int p_item) { } void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { - int current = p_item; if (current < 0 || current >= item_list->get_item_count()) return; @@ -500,7 +466,6 @@ void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { Dictionary d = item_list->get_item_metadata(current); if (!d["dir"] && p_selected) { - file->set_text(d["name"]); _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); } @@ -509,12 +474,10 @@ void EditorFileDialog::_multi_selected(int p_item, bool p_selected) { } void EditorFileDialog::_items_clear_selection() { - item_list->unselect_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")); @@ -534,7 +497,6 @@ void EditorFileDialog::_items_clear_selection() { } void EditorFileDialog::_push_history() { - local_history.resize(local_history_pos + 1); String new_path = dir_access->get_current_dir(); if (local_history.size() == 0 || new_path != local_history[local_history_pos]) { @@ -545,7 +507,6 @@ void EditorFileDialog::_push_history() { } } void EditorFileDialog::_item_dc_selected(int p_item) { - int current = p_item; if (current < 0 || current >= item_list->get_item_count()) return; @@ -553,7 +514,6 @@ void EditorFileDialog::_item_dc_selected(int p_item) { Dictionary d = item_list->get_item_metadata(current); if (d["dir"]) { - dir_access->change_dir(d["name"]); call_deferred("_update_file_list"); call_deferred("_update_dir"); @@ -561,13 +521,11 @@ void EditorFileDialog::_item_dc_selected(int p_item) { _push_history(); } else { - _action_pressed(); } } void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p_pos) { - // Right click on specific file(s) or folder(s). item_menu->clear(); item_menu->set_size(Size2(1, 1)); @@ -608,7 +566,6 @@ 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); @@ -629,9 +586,7 @@ void EditorFileDialog::_item_list_rmb_clicked(const Vector2 &p_pos) { } void EditorFileDialog::_item_menu_id_pressed(int p_option) { - switch (p_option) { - case ITEM_MENU_COPY_PATH: { Dictionary item_meta = item_list->get_item_metadata(item_list->get_current()); DisplayServer::get_singleton()->clipboard_set(item_meta["path"]); @@ -669,7 +624,6 @@ void EditorFileDialog::_item_menu_id_pressed(int p_option) { } bool EditorFileDialog::_is_open_should_be_disabled() { - if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) return false; @@ -678,7 +632,6 @@ bool EditorFileDialog::_is_open_should_be_disabled() { return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder. for (int i = 0; i < items.size(); i++) { - Dictionary d = item_list->get_item_metadata(items.get(i)); if (((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || (mode == FILE_MODE_OPEN_DIR && !d["dir"])) @@ -708,7 +661,6 @@ void EditorFileDialog::update_file_name() { // DO NOT USE THIS FUNCTION UNLESS NEEDED, CALL INVALIDATE() INSTEAD. void EditorFileDialog::update_file_list() { - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; Ref<Texture2D> folder_thumbnail; @@ -720,7 +672,6 @@ void EditorFileDialog::update_file_list() { item_list->get_v_scroll()->set_value(0); if (display_mode == DISPLAY_THUMBNAILS) { - item_list->set_max_columns(0); item_list->set_icon_mode(ItemList::ICON_MODE_TOP); item_list->set_fixed_column_width(thumbnail_size * 3 / 2); @@ -738,7 +689,6 @@ void EditorFileDialog::update_file_list() { preview_vb->hide(); } else { - item_list->set_icon_mode(ItemList::ICON_MODE_LEFT); item_list->set_max_columns(1); item_list->set_max_text_lines(1); @@ -760,7 +710,6 @@ void EditorFileDialog::update_file_list() { String item; while ((item = dir_access->get_next()) != "") { - if (item == "." || item == "..") continue; @@ -781,10 +730,8 @@ void EditorFileDialog::update_file_list() { item_list->add_item(dir_name); if (display_mode == DISPLAY_THUMBNAILS) { - item_list->set_item_icon(item_list->get_item_count() - 1, folder_thumbnail); } else { - item_list->set_item_icon(item_list->get_item_count() - 1, folder); } @@ -802,15 +749,12 @@ void EditorFileDialog::update_file_list() { List<String> patterns; // build filter if (filter->get_selected() == filter->get_item_count() - 1) { - // match all } else if (filters.size() > 1 && filter->get_selected() == 0) { // match all filters for (int i = 0; i < filters.size(); i++) { - String f = filters[i].get_slice(";", 0); for (int j = 0; j < f.get_slice_count(","); j++) { - patterns.push_back(f.get_slice(",", j).strip_edges()); } } @@ -820,37 +764,29 @@ void EditorFileDialog::update_file_list() { idx--; if (idx >= 0 && idx < filters.size()) { - String f = filters[idx].get_slice(";", 0); for (int j = 0; j < f.get_slice_count(","); j++) { - patterns.push_back(f.get_slice(",", j).strip_edges()); } } } while (!files.empty()) { - bool match = patterns.empty(); for (List<String>::Element *E = patterns.front(); E; E = E->next()) { - if (files.front()->get().matchn(E->get())) { - match = true; break; } } if (match) { - item_list->add_item(files.front()->get()); if (get_icon_func) { - Ref<Texture2D> icon = get_icon_func(cdir.plus_file(files.front()->get())); if (display_mode == DISPLAY_THUMBNAILS) { - item_list->set_item_icon(item_list->get_item_count() - 1, file_thumbnail); item_list->set_item_tag_icon(item_list->get_item_count() - 1, icon); } else { @@ -905,7 +841,6 @@ void EditorFileDialog::_filter_selected(int) { } void EditorFileDialog::update_filters() { - filter->clear(); if (filters.size() > 1) { @@ -926,7 +861,6 @@ void EditorFileDialog::update_filters() { filter->add_item(TTR("All Recognized") + " (" + all_filters + ")"); } for (int i = 0; i < filters.size(); i++) { - String flt = filters[i].get_slice(";", 0).strip_edges(); String desc = filters[i].get_slice(";", 1).strip_edges(); if (desc.length()) @@ -939,32 +873,26 @@ void EditorFileDialog::update_filters() { } void EditorFileDialog::clear_filters() { - filters.clear(); update_filters(); invalidate(); } void EditorFileDialog::add_filter(const String &p_filter) { - filters.push_back(p_filter); update_filters(); invalidate(); } String EditorFileDialog::get_current_dir() const { - return dir_access->get_current_dir(); } String EditorFileDialog::get_current_file() const { - return file->get_text(); } String EditorFileDialog::get_current_path() const { - return dir_access->get_current_dir().plus_file(file->get_text()); } void EditorFileDialog::set_current_dir(const String &p_dir) { - if (p_dir.is_rel_path()) dir_access->change_dir(OS::get_singleton()->get_resource_dir()); dir_access->change_dir(p_dir); @@ -972,7 +900,6 @@ void EditorFileDialog::set_current_dir(const String &p_dir) { invalidate(); } void EditorFileDialog::set_current_file(const String &p_file) { - file->set_text(p_file); update_dir(); invalidate(); @@ -986,15 +913,12 @@ void EditorFileDialog::set_current_file(const String &p_file) { _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); } void EditorFileDialog::set_current_path(const String &p_path) { - if (!p_path.size()) return; int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); if (pos == -1) { - set_current_file(p_path); } else { - String dir = p_path.substr(0, pos); String file = p_path.substr(pos + 1, p_path.length()); set_current_dir(dir); @@ -1003,10 +927,8 @@ void EditorFileDialog::set_current_path(const String &p_path) { } void EditorFileDialog::set_file_mode(FileMode p_mode) { - mode = p_mode; switch (mode) { - case FILE_MODE_OPEN_FILE: get_ok()->set_text(TTR("Open")); set_title(TTR("Open a File")); @@ -1048,27 +970,22 @@ void EditorFileDialog::set_file_mode(FileMode p_mode) { } EditorFileDialog::FileMode EditorFileDialog::get_file_mode() const { - return mode; } void EditorFileDialog::set_access(Access p_access) { - ERR_FAIL_INDEX(p_access, 3); if (access == p_access) return; memdelete(dir_access); switch (p_access) { case ACCESS_FILESYSTEM: { - dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); } break; case ACCESS_RESOURCES: { - dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); } break; case ACCESS_USERDATA: { - dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA); } break; } @@ -1080,7 +997,6 @@ void EditorFileDialog::set_access(Access p_access) { } void EditorFileDialog::invalidate() { - if (is_visible()) { update_file_list(); _update_favorites(); @@ -1091,12 +1007,10 @@ void EditorFileDialog::invalidate() { } EditorFileDialog::Access EditorFileDialog::get_access() const { - return access; } void EditorFileDialog::_make_dir_confirm() { - Error err = dir_access->make_dir(makedirname->get_text()); if (err == OK) { dir_access->change_dir(makedirname->get_text()); @@ -1112,13 +1026,11 @@ void EditorFileDialog::_make_dir_confirm() { } void EditorFileDialog::_make_dir() { - makedialog->popup_centered(Size2(250, 80) * EDSCALE); makedirname->grab_focus(); } void EditorFileDialog::_delete_items() { - // Collect the selected folders and files to delete and check them in the deletion dependency dialog. Vector<String> folders; Vector<String> files; @@ -1140,7 +1052,6 @@ void EditorFileDialog::_delete_items() { } void EditorFileDialog::_select_drive(int p_idx) { - String d = drives->get_item_text(p_idx); dir_access->change_dir(d); file->set_text(""); @@ -1150,7 +1061,6 @@ void EditorFileDialog::_select_drive(int p_idx) { } void EditorFileDialog::_update_drives() { - int dc = dir_access->get_drive_count(); if (dc == 0 || access != ACCESS_FILESYSTEM) { drives->hide(); @@ -1174,7 +1084,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(); @@ -1183,7 +1092,6 @@ void EditorFileDialog::_favorite_selected(int p_idx) { } void EditorFileDialog::_favorite_move_up() { - int current = favorites->get_current(); if (current > 0 && current < favorites->get_item_count()) { @@ -1203,7 +1111,6 @@ void EditorFileDialog::_favorite_move_up() { } } void EditorFileDialog::_favorite_move_down() { - int current = favorites->get_current(); if (current >= 0 && current < favorites->get_item_count() - 1) { @@ -1224,7 +1131,6 @@ void EditorFileDialog::_favorite_move_down() { } void EditorFileDialog::_update_favorites() { - bool res = access == ACCESS_RESOURCES; String current = get_current_dir(); @@ -1302,7 +1208,6 @@ void EditorFileDialog::_favorite_pressed() { } void EditorFileDialog::_recent_selected(int p_idx) { - Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs(); ERR_FAIL_INDEX(p_idx, recentd.size()); @@ -1313,7 +1218,6 @@ void EditorFileDialog::_recent_selected(int p_idx) { } void EditorFileDialog::_go_up() { - dir_access->change_dir(".."); update_file_list(); update_dir(); @@ -1321,7 +1225,6 @@ void EditorFileDialog::_go_up() { } void EditorFileDialog::_go_back() { - if (local_history_pos <= 0) { return; } @@ -1335,7 +1238,6 @@ void EditorFileDialog::_go_back() { dir_next->set_disabled(local_history_pos == local_history.size() - 1); } void EditorFileDialog::_go_forward() { - if (local_history_pos == local_history.size() - 1) { return; } @@ -1354,7 +1256,6 @@ bool EditorFileDialog::default_show_hidden_files = false; EditorFileDialog::DisplayMode EditorFileDialog::default_display_mode = DISPLAY_THUMBNAILS; void EditorFileDialog::set_display_mode(DisplayMode p_mode) { - if (display_mode == p_mode) return; if (p_mode == DISPLAY_THUMBNAILS) { @@ -1369,12 +1270,10 @@ void EditorFileDialog::set_display_mode(DisplayMode p_mode) { } EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const { - return display_mode; } void EditorFileDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorFileDialog::_unhandled_input); ClassDB::bind_method(D_METHOD("_cancel_pressed"), &EditorFileDialog::_cancel_pressed); @@ -1452,7 +1351,6 @@ void EditorFileDialog::set_default_display_mode(DisplayMode p_mode) { } void EditorFileDialog::_save_to_recent() { - String dir = get_current_dir(); Vector<String> recent = EditorSettings::get_singleton()->get_recent_dirs(); @@ -1476,17 +1374,14 @@ void EditorFileDialog::_save_to_recent() { } void EditorFileDialog::set_disable_overwrite_warning(bool p_disable) { - disable_overwrite_warning = p_disable; } bool EditorFileDialog::is_overwrite_warning_disabled() const { - return disable_overwrite_warning; } EditorFileDialog::EditorFileDialog() { - show_hidden_files = default_show_hidden_files; display_mode = default_display_mode; local_history_pos = 0; @@ -1730,7 +1625,6 @@ EditorFileDialog::EditorFileDialog() { } EditorFileDialog::~EditorFileDialog() { - if (unregister_func) unregister_func(this); memdelete(dir_access); |