diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 201 |
1 files changed, 141 insertions, 60 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 4e94ff1129..02ae15b80d 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -39,10 +39,10 @@ #include "core/templates/list.h" #include "editor/create_dialog.h" #include "editor/directory_create_dialog.h" +#include "editor/editor_dock_manager.h" #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_dir_dialog.h" @@ -53,6 +53,8 @@ #include "editor/scene_create_dialog.h" #include "editor/scene_tree_dock.h" #include "editor/shader_create_dialog.h" +#include "editor/themes/editor_scale.h" +#include "editor/themes/editor_theme_manager.h" #include "scene/gui/item_list.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" @@ -493,43 +495,17 @@ void FileSystemDock::_update_display_mode(bool p_force) { void FileSystemDock::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_TRANSLATION_CHANGED: - case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: - case NOTIFICATION_ENTER_TREE: { - if (initialized) { - return; - } - initialized = true; + case NOTIFICATION_READY: { EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &FileSystemDock::_feature_profile_changed)); - EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &FileSystemDock::_fs_changed)); EditorResourcePreview::get_singleton()->connect("preview_invalidated", callable_mp(this, &FileSystemDock::_preview_invalidated)); - button_reload->set_icon(get_editor_theme_icon(SNAME("Reload"))); button_file_list_display_mode->connect("pressed", callable_mp(this, &FileSystemDock::_toggle_file_display)); - files->connect("item_activated", callable_mp(this, &FileSystemDock::_file_list_activate_file)); button_hist_next->connect("pressed", callable_mp(this, &FileSystemDock::_fw_history)); button_hist_prev->connect("pressed", callable_mp(this, &FileSystemDock::_bw_history)); - - tree_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); - tree_search_box->set_clear_button_enabled(true); - tree_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); - - file_list_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); - file_list_search_box->set_clear_button_enabled(true); - file_list_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); - - if (is_layout_rtl()) { - button_hist_next->set_icon(get_editor_theme_icon(SNAME("Back"))); - button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Forward"))); - } else { - button_hist_next->set_icon(get_editor_theme_icon(SNAME("Forward"))); - button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Back"))); - } file_list_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_file_list_rmb_option)); tree_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_tree_rmb_option)); - current_path_line_edit->connect("text_submitted", callable_mp(this, &FileSystemDock::_navigate_to_path).bind(false)); always_show_folders = bool(EDITOR_GET("docks/filesystem/always_show_folders")); @@ -581,16 +557,11 @@ void FileSystemDock::_notification(int p_what) { } } break; + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { - overwrite_dialog_scroll->add_theme_style_override("panel", get_theme_stylebox("panel", "Tree")); - - if (is_visible_in_tree()) { - _update_display_mode(true); - } - } break; + _update_display_mode(true); - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - // Update icons. button_reload->set_icon(get_editor_theme_icon(SNAME("Reload"))); StringName mode_icon = "Panels1"; @@ -601,13 +572,6 @@ void FileSystemDock::_notification(int p_what) { } button_toggle_display_mode->set_icon(get_editor_theme_icon(mode_icon)); - if (is_layout_rtl()) { - button_hist_next->set_icon(get_editor_theme_icon(SNAME("Back"))); - button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Forward"))); - } else { - button_hist_next->set_icon(get_editor_theme_icon(SNAME("Forward"))); - button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Back"))); - } if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { button_file_list_display_mode->set_icon(get_editor_theme_icon(SNAME("FileThumbnail"))); } else { @@ -615,17 +579,29 @@ void FileSystemDock::_notification(int p_what) { } tree_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); - tree_search_box->set_clear_button_enabled(true); tree_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); file_list_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); - file_list_search_box->set_clear_button_enabled(true); file_list_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); + button_dock_placement->set_icon(get_editor_theme_icon(SNAME("GuiTabMenu"))); + + if (is_layout_rtl()) { + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Back"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Forward"))); + } else { + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Forward"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Back"))); + } + + overwrite_dialog_scroll->add_theme_style_override("panel", get_theme_stylebox("panel", "Tree")); + } break; + + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { // Update editor dark theme & always show folders states from editor settings, redraw if needed. bool do_redraw = false; - bool new_editor_is_dark_theme = EditorSettings::get_singleton()->is_dark_theme(); + bool new_editor_is_dark_theme = EditorThemeManager::is_dark_theme(); if (new_editor_is_dark_theme != editor_is_dark_theme) { editor_is_dark_theme = new_editor_is_dark_theme; do_redraw = true; @@ -765,7 +741,7 @@ void FileSystemDock::navigate_to_path(const String &p_path) { } void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) { - if ((file_list_vb->is_visible_in_tree() || current_path == p_path.get_base_dir()) && p_preview.is_valid()) { + if ((file_list_vb->is_visible_in_tree() || current_path.trim_suffix("/") == p_path.get_base_dir()) && p_preview.is_valid()) { Array uarr = p_udata; int idx = uarr[0]; String file = uarr[1]; @@ -865,18 +841,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * struct FileSystemDock::FileInfoTypeComparator { bool operator()(const FileInfo &p_a, const FileInfo &p_b) const { - // Uses the extension, then the icon name to distinguish file types. - String icon_path_a = ""; - String icon_path_b = ""; - Ref<Texture2D> icon_a = EditorNode::get_singleton()->get_class_icon(p_a.type); - if (icon_a.is_valid()) { - icon_path_a = icon_a->get_name(); - } - Ref<Texture2D> icon_b = EditorNode::get_singleton()->get_class_icon(p_b.type); - if (icon_b.is_valid()) { - icon_path_b = icon_b->get_name(); - } - return NaturalNoCaseComparator()(p_a.name.get_extension() + icon_path_a + p_a.name.get_basename(), p_b.name.get_extension() + icon_path_b + p_b.name.get_basename()); + return NaturalNoCaseComparator()(p_a.name.get_extension() + p_a.type + p_a.name.get_basename(), p_b.name.get_extension() + p_b.type + p_b.name.get_basename()); } }; @@ -2571,6 +2536,10 @@ void FileSystemDock::_rescan() { EditorFileSystem::get_singleton()->scan(); } +void FileSystemDock::_change_bottom_dock_placement() { + EditorDockManager::get_singleton()->bottom_dock_show_placement_popup(button_dock_placement->get_screen_rect(), this); +} + void FileSystemDock::_change_split_mode() { DisplayMode next_mode = DISPLAY_MODE_TREE_ONLY; if (display_mode == DISPLAY_MODE_VSPLIT) { @@ -3644,6 +3613,43 @@ MenuButton *FileSystemDock::_create_file_menu_button() { return button; } +bool FileSystemDock::_can_dock_horizontal() const { + return true; +} + +void FileSystemDock::_set_dock_horizontal(bool p_enable) { + if (button_dock_placement->is_visible() == p_enable) { + return; + } + + if (p_enable) { + set_meta("_dock_display_mode", get_display_mode()); + set_meta("_dock_file_display_mode", get_file_list_display_mode()); + + FileSystemDock::DisplayMode new_display_mode = FileSystemDock::DisplayMode(int(get_meta("_bottom_display_mode", int(FileSystemDock::DISPLAY_MODE_HSPLIT)))); + FileSystemDock::FileListDisplayMode new_file_display_mode = FileSystemDock::FileListDisplayMode(int(get_meta("_bottom_file_display_mode", int(FileSystemDock::FILE_LIST_DISPLAY_THUMBNAILS)))); + + set_display_mode(new_display_mode); + set_file_list_display_mode(new_file_display_mode); + set_custom_minimum_size(Size2(0, 200) * EDSCALE); + } else { + set_meta("_bottom_display_mode", get_display_mode()); + set_meta("_bottom_file_display_mode", get_file_list_display_mode()); + + FileSystemDock::DisplayMode new_display_mode = FileSystemDock::DISPLAY_MODE_TREE_ONLY; + FileSystemDock::FileListDisplayMode new_file_display_mode = FileSystemDock::FILE_LIST_DISPLAY_LIST; + + new_display_mode = FileSystemDock::DisplayMode(int(get_meta("_dock_display_mode", new_display_mode))); + new_file_display_mode = FileSystemDock::FileListDisplayMode(int(get_meta("_dock_file_display_mode", new_file_display_mode))); + + set_display_mode(new_display_mode); + set_file_list_display_mode(new_file_display_mode); + set_custom_minimum_size(Size2(0, 0)); + } + + button_dock_placement->set_visible(p_enable); +} + void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_file_list_thumbnail_done"), &FileSystemDock::_file_list_thumbnail_done); ClassDB::bind_method(D_METHOD("_tree_thumbnail_done"), &FileSystemDock::_tree_thumbnail_done); @@ -3653,6 +3659,9 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("add_resource_tooltip_plugin", "plugin"), &FileSystemDock::add_resource_tooltip_plugin); ClassDB::bind_method(D_METHOD("remove_resource_tooltip_plugin", "plugin"), &FileSystemDock::remove_resource_tooltip_plugin); + ClassDB::bind_method(D_METHOD("_set_dock_horizontal", "enable"), &FileSystemDock::_set_dock_horizontal); + ClassDB::bind_method(D_METHOD("_can_dock_horizontal"), &FileSystemDock::_can_dock_horizontal); + ADD_SIGNAL(MethodInfo("inherit", PropertyInfo(Variant::STRING, "file"))); ADD_SIGNAL(MethodInfo("instantiate", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); @@ -3665,6 +3674,70 @@ void FileSystemDock::_bind_methods() { ADD_SIGNAL(MethodInfo("display_mode_changed")); } +void FileSystemDock::save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const { + p_layout->set_value(p_section, "dock_filesystem_h_split_offset", get_h_split_offset()); + p_layout->set_value(p_section, "dock_filesystem_v_split_offset", get_v_split_offset()); + p_layout->set_value(p_section, "dock_filesystem_display_mode", get_display_mode()); + p_layout->set_value(p_section, "dock_filesystem_file_sort", get_file_sort()); + p_layout->set_value(p_section, "dock_filesystem_file_list_display_mode", get_file_list_display_mode()); + PackedStringArray selected_files = get_selected_paths(); + p_layout->set_value(p_section, "dock_filesystem_selected_paths", selected_files); + Vector<String> uncollapsed_paths = get_uncollapsed_paths(); + p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", uncollapsed_paths); +} + +void FileSystemDock::load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) { + if (p_layout->has_section_key(p_section, "dock_filesystem_h_split_offset")) { + int fs_h_split_ofs = p_layout->get_value(p_section, "dock_filesystem_h_split_offset"); + set_h_split_offset(fs_h_split_ofs); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_v_split_offset")) { + int fs_v_split_ofs = p_layout->get_value(p_section, "dock_filesystem_v_split_offset"); + set_v_split_offset(fs_v_split_ofs); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_display_mode")) { + DisplayMode dock_filesystem_display_mode = DisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_display_mode"))); + set_display_mode(dock_filesystem_display_mode); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_file_sort")) { + FileSortOption dock_filesystem_file_sort = FileSortOption(int(p_layout->get_value(p_section, "dock_filesystem_file_sort"))); + set_file_sort(dock_filesystem_file_sort); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_file_list_display_mode")) { + FileListDisplayMode dock_filesystem_file_list_display_mode = FileListDisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_file_list_display_mode"))); + set_file_list_display_mode(dock_filesystem_file_list_display_mode); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_selected_paths")) { + PackedStringArray dock_filesystem_selected_paths = p_layout->get_value(p_section, "dock_filesystem_selected_paths"); + for (int i = 0; i < dock_filesystem_selected_paths.size(); i++) { + select_file(dock_filesystem_selected_paths[i]); + } + } + + // Restore collapsed state. + PackedStringArray uncollapsed_tis; + if (p_layout->has_section_key(p_section, "dock_filesystem_uncollapsed_paths")) { + uncollapsed_tis = p_layout->get_value(p_section, "dock_filesystem_uncollapsed_paths"); + } else { + uncollapsed_tis = { "res://" }; + } + + if (!uncollapsed_tis.is_empty()) { + for (int i = 0; i < uncollapsed_tis.size(); i++) { + TreeItem *uncollapsed_ti = get_tree_control()->get_item_with_metadata(uncollapsed_tis[i], 0); + if (uncollapsed_ti) { + uncollapsed_ti->set_collapsed(false); + } + } + get_tree_control()->queue_redraw(); + } +} + FileSystemDock::FileSystemDock() { singleton = this; set_name("FileSystem"); @@ -3699,7 +3772,7 @@ FileSystemDock::FileSystemDock() { assigned_folder_colors = ProjectSettings::get_singleton()->get_setting("file_customization/folder_colors"); - editor_is_dark_theme = EditorSettings::get_singleton()->is_dark_theme(); + editor_is_dark_theme = EditorThemeManager::is_dark_theme(); VBoxContainer *top_vbc = memnew(VBoxContainer); add_child(top_vbc); @@ -3742,6 +3815,12 @@ FileSystemDock::FileSystemDock() { button_toggle_display_mode->set_flat(true); toolbar_hbc->add_child(button_toggle_display_mode); + button_dock_placement = memnew(Button); + button_dock_placement->set_flat(true); + button_dock_placement->connect("pressed", callable_mp(this, &FileSystemDock::_change_bottom_dock_placement)); + button_dock_placement->hide(); + toolbar_hbc->add_child(button_dock_placement); + toolbar2_hbc = memnew(HBoxContainer); toolbar2_hbc->add_theme_constant_override("separation", 0); top_vbc->add_child(toolbar2_hbc); @@ -3749,6 +3828,7 @@ FileSystemDock::FileSystemDock() { tree_search_box = memnew(LineEdit); tree_search_box->set_h_size_flags(SIZE_EXPAND_FILL); tree_search_box->set_placeholder(TTR("Filter Files")); + tree_search_box->set_clear_button_enabled(true); tree_search_box->connect("text_changed", callable_mp(this, &FileSystemDock::_search_changed).bind(tree_search_box)); toolbar2_hbc->add_child(tree_search_box); @@ -3798,6 +3878,7 @@ FileSystemDock::FileSystemDock() { file_list_search_box = memnew(LineEdit); file_list_search_box->set_h_size_flags(SIZE_EXPAND_FILL); file_list_search_box->set_placeholder(TTR("Filter Files")); + file_list_search_box->set_clear_button_enabled(true); file_list_search_box->connect("text_changed", callable_mp(this, &FileSystemDock::_search_changed).bind(file_list_search_box)); path_hb->add_child(file_list_search_box); |