diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 206 |
1 files changed, 121 insertions, 85 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index eebf1b6ab8..ec1153a015 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -139,41 +139,56 @@ void FileSystemDock::_update_tree(bool keep_collapse_state, bool p_uncollapse_ro updating_tree = false; } -void FileSystemDock::_notification(int p_what) { +void FileSystemDock::_update_display_mode() { - switch (p_what) { + bool disable_split = bool(EditorSettings::get_singleton()->get("docks/filesystem/disable_split")); + bool compact_mode = get_size().height < int(EditorSettings::get_singleton()->get("docks/filesystem/split_mode_minimum_height")); + DisplayMode new_mode; + if (disable_split || compact_mode) { + new_mode = file_list_view ? DISPLAY_FILE_LIST_ONLY : DISPLAY_TREE_ONLY; + } else { + new_mode = DISPLAY_SPLIT; + } - case NOTIFICATION_RESIZED: { + if (new_mode != display_mode) { + switch (new_mode) { + case DISPLAY_TREE_ONLY: + tree->show(); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + _update_tree(true); - bool new_mode = get_size().height < get_viewport_rect().size.height / 2; + file_list_vb->hide(); + break; - if (new_mode != low_height_mode) { + case DISPLAY_FILE_LIST_ONLY: + tree->hide(); + button_tree->show(); - low_height_mode = new_mode; + file_list_vb->show(); + _update_files(true); + break; - if (low_height_mode) { + case DISPLAY_SPLIT: + tree->show(); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + button_tree->hide(); + tree->ensure_cursor_is_visible(); + _update_tree(true); - tree->hide(); - tree->set_v_size_flags(SIZE_EXPAND_FILL); - button_tree->show(); - } else { + file_list_vb->show(); + _update_files(true); + break; + } + display_mode = new_mode; + } +} - tree->set_v_size_flags(SIZE_FILL); - button_tree->hide(); - if (!tree->is_visible()) { - tree->show(); - button_favorite->show(); - _update_tree(true); - } - tree->ensure_cursor_is_visible(); +void FileSystemDock::_notification(int p_what) { - if (!file_list_vb->is_visible()) { - file_list_vb->show(); - _update_files(true); - } - } - } + switch (p_what) { + case NOTIFICATION_RESIZED: { + _update_display_mode(); } break; case NOTIFICATION_ENTER_TREE: { @@ -190,13 +205,14 @@ void FileSystemDock::_notification(int p_what) { //button_instance->set_icon(get_icon("Add", ei)); //button_open->set_icon(get_icon("Folder", ei)); button_tree->set_icon(get_icon("Filesystem", ei)); - _update_file_display_toggle_button(); - button_display_mode->connect("pressed", this, "_change_file_display"); + _update_file_list_display_mode_button(); + button_file_list_display_mode->connect("pressed", this, "_change_file_display"); //file_options->set_icon( get_icon("Tools","ei")); files->connect("item_activated", this, "_select_file"); button_hist_next->connect("pressed", this, "_fw_history"); button_hist_prev->connect("pressed", this, "_bw_history"); - search_box->add_icon_override("right_icon", get_icon("Search", ei)); + search_box->set_right_icon(get_icon("Search", ei)); + search_box->set_clear_button_enabled(true); button_hist_next->set_icon(get_icon("Forward", ei)); button_hist_prev->set_icon(get_icon("Back", ei)); @@ -207,6 +223,8 @@ void FileSystemDock::_notification(int p_what) { button_tree->connect("pressed", this, "_go_to_tree", varray(), CONNECT_DEFERRED); current_path->connect("text_entered", this, "navigate_to_path"); + _update_display_mode(); + if (EditorFileSystem::get_singleton()->is_scanning()) { _set_scanning_mode(); } else { @@ -240,28 +258,29 @@ void FileSystemDock::_notification(int p_what) { } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - + // Update icons String ei = "EditorIcons"; - int new_mode = int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode")); - - //_update_icons - button_reload->set_icon(get_icon("Reload", ei)); button_favorite->set_icon(get_icon("Favorites", ei)); button_tree->set_icon(get_icon("Filesystem", ei)); button_hist_next->set_icon(get_icon("Forward", ei)); button_hist_prev->set_icon(get_icon("Back", ei)); - search_box->add_icon_override("right_icon", get_icon("Search", ei)); + search_box->set_right_icon(get_icon("Search", ei)); + search_box->set_clear_button_enabled(true); - if (new_mode != display_mode) { - set_display_mode(new_mode); + // Change size mode + int new_file_list_mode = int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode")); + if (new_file_list_mode != file_list_display_mode) { + set_file_list_display_mode(new_file_list_mode); } else { - _update_file_display_toggle_button(); + _update_file_list_display_mode_button(); _update_files(true); } - _update_tree(true); + // Change full tree mode + _update_display_mode(); + } break; } } @@ -287,7 +306,7 @@ void FileSystemDock::_dir_selected() { current_path->set_text(path); _push_to_history(); - if (!low_height_mode) { + if (display_mode == DISPLAY_SPLIT) { _update_files(false); } } @@ -358,7 +377,7 @@ void FileSystemDock::navigate_to_path(const String &p_path) { current_path->set_text(path); _push_to_history(); - if (!low_height_mode) { + if (display_mode == DISPLAY_SPLIT) { _update_tree(true); _update_files(false); } else { @@ -388,24 +407,24 @@ void FileSystemDock::_thumbnail_done(const String &p_path, const Ref<Texture> &p } } -void FileSystemDock::_update_file_display_toggle_button() { +void FileSystemDock::_update_file_list_display_mode_button() { - if (button_display_mode->is_pressed()) { - display_mode = DISPLAY_LIST; - button_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons")); - button_display_mode->set_tooltip(TTR("View items as a grid of thumbnails.")); + if (button_file_list_display_mode->is_pressed()) { + file_list_display_mode = FILE_LIST_DISPLAY_LIST; + button_file_list_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons")); + button_file_list_display_mode->set_tooltip(TTR("View items as a grid of thumbnails.")); } else { - display_mode = DISPLAY_THUMBNAILS; - button_display_mode->set_icon(get_icon("FileList", "EditorIcons")); - button_display_mode->set_tooltip(TTR("View items as a list.")); + file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS; + button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons")); + button_file_list_display_mode->set_tooltip(TTR("View items as a list.")); } } void FileSystemDock::_change_file_display() { - _update_file_display_toggle_button(); + _update_file_list_display_mode_button(); - EditorSettings::get_singleton()->set("docks/filesystem/display_mode", display_mode); + EditorSettings::get_singleton()->set("docks/filesystem/display_mode", file_list_display_mode); _update_files(true); } @@ -470,8 +489,8 @@ void FileSystemDock::_update_files(bool p_keep_selection) { bool always_show_folders = EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders"); - bool use_thumbnails = (display_mode == DISPLAY_THUMBNAILS); - bool use_folders = search_box->get_text().length() == 0 && (low_height_mode || always_show_folders); + bool use_thumbnails = (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS); + bool use_folders = search_box->get_text().length() == 0 && ((display_mode == DISPLAY_FILE_LIST_ONLY || display_mode == DISPLAY_TREE_ONLY) || always_show_folders); if (use_thumbnails) { @@ -615,24 +634,28 @@ void FileSystemDock::_select_file(int p_idx) { } } -void FileSystemDock::_go_to_tree() { +void FileSystemDock::_go_to_file_list() { - if (low_height_mode) { - tree->show(); - button_favorite->show(); - file_list_vb->hide(); + if (display_mode == DISPLAY_TREE_ONLY) { + file_list_view = true; + _update_display_mode(); + } else { + bool collapsed = tree->get_selected()->is_collapsed(); + tree->get_selected()->set_collapsed(!collapsed); + _update_files(false); } +} +void FileSystemDock::_go_to_tree() { - _update_tree(true); + file_list_view = false; tree->grab_focus(); + _update_display_mode(); tree->ensure_cursor_is_visible(); - //button_open->hide(); - //file_options->hide(); } void FileSystemDock::_preview_invalidated(const String &p_path) { - if (display_mode == DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && search_box->get_text() == String() && file_list_vb->is_visible_in_tree()) { + if (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && search_box->get_text() == String() && file_list_vb->is_visible_in_tree()) { for (int i = 0; i < files->get_item_count(); i++) { @@ -1319,6 +1342,9 @@ void FileSystemDock::_file_option(int p_option) { String fpath = files->get_item_metadata(idx); OS::get_singleton()->set_clipboard(fpath); } break; + case FILE_NEW_RESOURCE: { + new_resource_dialog->popup_create(true); + } break; } } @@ -1393,22 +1419,19 @@ void FileSystemDock::_folder_option(int p_option) { } } -void FileSystemDock::_go_to_file_list() { +void FileSystemDock::_resource_created() const { + Object *c = new_resource_dialog->instance_selected(); - if (low_height_mode) { - tree->hide(); - file_list_vb->show(); - button_favorite->hide(); - } else { - bool collapsed = tree->get_selected()->is_collapsed(); - tree->get_selected()->set_collapsed(!collapsed); - } + ERR_FAIL_COND(!c); + Resource *r = Object::cast_to<Resource>(c); + ERR_FAIL_COND(!r); - //file_options->show(); + REF res(r); + editor->push_item(c); - _update_files(false); + RES current_res = RES(r); - //emit_signal("open",path); + editor->save_resource_as(current_res, path); } void FileSystemDock::_dir_rmb_pressed(const Vector2 &p_pos) { @@ -1430,7 +1453,7 @@ void FileSystemDock::_dir_rmb_pressed(const Vector2 &p_pos) { } folder_options->add_separator(); folder_options->add_item(TTR("New Folder..."), FOLDER_NEW_FOLDER); - folder_options->add_item(TTR("Show In File Manager"), FOLDER_SHOW_IN_EXPLORER); + folder_options->add_item(TTR("Open In File Manager"), FOLDER_SHOW_IN_EXPLORER); } folder_options->set_position(tree->get_global_position() + p_pos); folder_options->popup(); @@ -1454,7 +1477,7 @@ void FileSystemDock::fix_dependencies(const String &p_for_file) { void FileSystemDock::focus_on_filter() { - if (low_height_mode && tree->is_visible()) { + if (display_mode == DISPLAY_FILE_LIST_ONLY && tree->is_visible()) { // Tree mode, switch to files list with search box tree->hide(); file_list_vb->show(); @@ -1464,12 +1487,12 @@ void FileSystemDock::focus_on_filter() { search_box->grab_focus(); } -void FileSystemDock::set_display_mode(int p_mode) { +void FileSystemDock::set_file_list_display_mode(int p_mode) { - if (p_mode == display_mode) + if (p_mode == file_list_display_mode) return; - button_display_mode->set_pressed(p_mode == DISPLAY_LIST); + button_file_list_display_mode->set_pressed(p_mode == FILE_LIST_DISPLAY_LIST); _change_file_display(); } @@ -1738,7 +1761,11 @@ void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) { file_options->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); file_options->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); - file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER); + file_options->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + + String fpath = files->get_item_metadata(p_item); + String item_text = fpath.ends_with("/") ? TTR("Open In File Manager") : TTR("Show In File Manager"); + file_options->add_item(item_text, FILE_SHOW_IN_EXPLORER); file_options->set_position(files->get_global_position() + p_pos); file_options->popup(); @@ -1750,6 +1777,7 @@ void FileSystemDock::_rmb_pressed(const Vector2 &p_pos) { file_options->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); file_options->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); + file_options->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER); file_options->set_position(files->get_global_position() + p_pos); file_options->popup(); @@ -1862,7 +1890,8 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_file_option"), &FileSystemDock::_file_option); ClassDB::bind_method(D_METHOD("_folder_option"), &FileSystemDock::_folder_option); ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm); - ClassDB::bind_method(D_METHOD("_move_operation_confirm"), &FileSystemDock::_move_operation_confirm); + ClassDB::bind_method(D_METHOD("_resource_created"), &FileSystemDock::_resource_created); + ClassDB::bind_method(D_METHOD("_move_operation_confirm", "to_path", "overwrite"), &FileSystemDock::_move_operation_confirm, DEFVAL(false)); ClassDB::bind_method(D_METHOD("_move_with_overwrite"), &FileSystemDock::_move_with_overwrite); ClassDB::bind_method(D_METHOD("_rename_operation_confirm"), &FileSystemDock::_rename_operation_confirm); ClassDB::bind_method(D_METHOD("_duplicate_operation_confirm"), &FileSystemDock::_duplicate_operation_confirm); @@ -1962,9 +1991,11 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { */ file_options = memnew(PopupMenu); + file_options->set_hide_on_window_lose_focus(true); add_child(file_options); folder_options = memnew(PopupMenu); + folder_options->set_hide_on_window_lose_focus(true); add_child(folder_options); split_box = memnew(VSplitContainer); @@ -2002,9 +2033,9 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { search_box->connect("text_changed", this, "_search_changed"); path_hb->add_child(search_box); - button_display_mode = memnew(ToolButton); - button_display_mode->set_toggle_mode(true); - path_hb->add_child(button_display_mode); + button_file_list_display_mode = memnew(ToolButton); + button_file_list_display_mode->set_toggle_mode(true); + path_hb->add_child(button_file_list_display_mode); files = memnew(ItemList); files->set_v_size_flags(SIZE_EXPAND_FILL); @@ -2087,6 +2118,11 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { make_script_dialog_text->set_title(TTR("Create Script")); add_child(make_script_dialog_text); + new_resource_dialog = memnew(CreateDialog); + add_child(new_resource_dialog); + new_resource_dialog->set_base_type("Resource"); + new_resource_dialog->connect("create", this, "_resource_created"); + updating_tree = false; initialized = false; import_dock_needs_update = false; @@ -2095,8 +2131,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { history_max_size = 20; history.push_back("res://"); - low_height_mode = false; - display_mode = DISPLAY_THUMBNAILS; + display_mode = DISPLAY_SPLIT; + file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS; } FileSystemDock::~FileSystemDock() { |