diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 114 |
1 files changed, 67 insertions, 47 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index a729befe8e..fb591b51df 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -71,11 +71,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->select(0); } - if ((path.begins_with(lpath) && path != lpath)) { - subdirectory_item->set_collapsed(false); - } else { - subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0); - } + subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0); if (searched_string.length() > 0 && dname.to_lower().find(searched_string) >= 0) { parent_should_expand = true; } @@ -115,6 +111,10 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory file_item->select(0); file_item->set_as_cursor(0); } + String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); + if (main_scene == file_metadata) { + file_item->set_custom_color(0, get_color("accent_color", "Editor")); + } Array udata; udata.push_back(tree_update_id); udata.push_back(file_item); @@ -333,10 +333,11 @@ void FileSystemDock::_notification(int p_what) { case NOTIFICATION_DRAG_BEGIN: { Dictionary dd = get_viewport()->gui_get_drag_data(); if (tree->is_visible_in_tree() && dd.has("type")) { - if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { + if (dd.has("favorite")) { + if ((String(dd["favorite"]) == "all")) + tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN); - } else if ((String(dd["type"]) == "favorite")) { - tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); } } } break; @@ -477,6 +478,7 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa } void FileSystemDock::navigate_to_path(const String &p_path) { + file_list_search_box->clear(); _navigate_to_path(p_path); } @@ -1563,6 +1565,15 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } } break; + case FILE_MAIN_SCENE: { + // Set as main scene with selected scene file. + if (p_selected.size() == 1) { + ProjectSettings::get_singleton()->set("application/run/main_scene", p_selected[0]); + ProjectSettings::get_singleton()->save(); + _update_tree(_compute_uncollapsed_paths()); + } + } break; + case FILE_INSTANCE: { // Instance all selected scenes. Vector<String> paths; @@ -1709,7 +1720,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected reimport.push_back(p_selected[i]); } - ERR_FAIL_COND(reimport.size() == 0); + ERR_FAIL_COND_MSG(reimport.size() == 0, "You need to select files to reimport them."); } break; case FILE_NEW_FOLDER: { @@ -1838,7 +1849,7 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) all_not_favorites &= !is_favorite; selected = tree->get_next_selected(selected); } - if (all_favorites) { + if (!all_not_favorites) { paths = _tree_get_selected(false); } else { paths = _tree_get_selected(); @@ -1856,12 +1867,9 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) if (paths.empty()) return Variant(); - if (!all_favorites && !all_not_favorites) - return Variant(); - Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from); - if (all_favorites) { - drag_data["type"] = "favorite"; + if (!all_not_favorites) { + drag_data["favorite"] = all_favorites ? "all" : "mixed"; } return drag_data; } @@ -1869,7 +1877,11 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { Dictionary drag_data = p_data; - if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { + if (drag_data.has("favorite")) { + + if (String(drag_data["favorite"]) != "all") { + return false; + } // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); @@ -1936,7 +1948,11 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Vector<String> dirs = EditorSettings::get_singleton()->get_favorites(); - if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { + if (drag_data.has("favorite")) { + + if (String(drag_data["favorite"]) != "all") { + return; + } // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); if (!ti) @@ -2087,7 +2103,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options) { // Add options for files and folders. - ERR_FAIL_COND(p_paths.empty()); + ERR_FAIL_COND_MSG(p_paths.empty(), "Path cannot be empty."); Vector<String> filenames; Vector<String> foldernames; @@ -2099,6 +2115,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str bool all_folders = true; bool all_favorites = true; bool all_not_favorites = true; + for (int i = 0; i < p_paths.size(); i++) { String fpath = p_paths[i]; if (fpath.ends_with("/")) { @@ -2128,25 +2145,28 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (all_files) { if (all_files_scenes) { if (filenames.size() == 1) { - p_popup->add_item(TTR("Open Scene"), FILE_OPEN); - p_popup->add_item(TTR("New Inherited Scene"), FILE_INHERIT); + p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scene"), FILE_OPEN); + p_popup->add_icon_item(get_icon("CreateNewSceneFrom", "EditorIcons"), TTR("New Inherited Scene"), FILE_INHERIT); + if (ProjectSettings::get_singleton()->get("application/run/main_scene") != filenames[0]) { + p_popup->add_icon_item(get_icon("PlayScene", "EditorIcons"), TTR("Set As Main Scene"), FILE_MAIN_SCENE); + } } else { - p_popup->add_item(TTR("Open Scenes"), FILE_OPEN); + p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scenes"), FILE_OPEN); } - p_popup->add_item(TTR("Instance"), FILE_INSTANCE); + p_popup->add_icon_item(get_icon("Instance", "EditorIcons"), TTR("Instance"), FILE_INSTANCE); p_popup->add_separator(); } else if (filenames.size() == 1) { - p_popup->add_item(TTR("Open"), FILE_OPEN); + p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open"), FILE_OPEN); p_popup->add_separator(); } } if (p_paths.size() >= 1) { if (!all_favorites) { - p_popup->add_item(TTR("Add to Favorites"), FILE_ADD_FAVORITE); + p_popup->add_icon_item(get_icon("Favorites", "EditorIcons"), TTR("Add to Favorites"), FILE_ADD_FAVORITE); } if (!all_not_favorites) { - p_popup->add_item(TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); + p_popup->add_icon_item(get_icon("NonFavorite", "EditorIcons"), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); } p_popup->add_separator(); } @@ -2159,36 +2179,36 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } } else if (all_folders && foldernames.size() > 0) { - p_popup->add_item(TTR("Open"), FILE_OPEN); + p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open"), FILE_OPEN); p_popup->add_separator(); } if (p_paths.size() == 1) { - p_popup->add_item(TTR("Copy Path"), FILE_COPY_PATH); + p_popup->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Path"), FILE_COPY_PATH); if (p_paths[0] != "res://") { - p_popup->add_item(TTR("Rename..."), FILE_RENAME); - p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + p_popup->add_icon_item(get_icon("Rename", "EditorIcons"), TTR("Rename..."), FILE_RENAME); + p_popup->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Duplicate..."), FILE_DUPLICATE); } } if (p_paths.size() > 1 || p_paths[0] != "res://") { - p_popup->add_item(TTR("Move To..."), FILE_MOVE); - p_popup->add_item(TTR("Delete"), FILE_REMOVE); + p_popup->add_icon_item(get_icon("MoveUp", "EditorIcons"), TTR("Move To..."), FILE_MOVE); + p_popup->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Delete"), FILE_REMOVE); } if (p_paths.size() == 1) { p_popup->add_separator(); if (p_display_path_dependent_options) { - p_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); - p_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); - p_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); - p_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + p_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER); + p_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE); + p_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT); + p_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE); p_popup->add_separator(); } String fpath = p_paths[0]; String item_text = fpath.ends_with("/") ? TTR("Open in File Manager") : TTR("Show in File Manager"); - p_popup->add_item(item_text, FILE_SHOW_IN_EXPLORER); + p_popup->add_icon_item(get_icon("Filesystem", "EditorIcons"), item_text, FILE_SHOW_IN_EXPLORER); } } @@ -2198,8 +2218,8 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { if (paths.size() == 1) { if (paths[0].ends_with("/")) { - tree_popup->add_item(TTR("Expand All"), FOLDER_EXPAND_ALL); - tree_popup->add_item(TTR("Collapse All"), FOLDER_COLLAPSE_ALL); + tree_popup->add_icon_item(get_icon("GuiTreeArrowDown", "EditorIcons"), TTR("Expand All"), FOLDER_EXPAND_ALL); + tree_popup->add_icon_item(get_icon("GuiTreeArrowRight", "EditorIcons"), TTR("Collapse All"), FOLDER_COLLAPSE_ALL); tree_popup->add_separator(); } } @@ -2219,10 +2239,10 @@ void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) { path = "res://"; tree_popup->clear(); tree_popup->set_size(Size2(1, 1)); - tree_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); - tree_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); - tree_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); - tree_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + tree_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER); + tree_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE); + tree_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT); + tree_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE); tree_popup->set_position(tree->get_global_position() + p_pos); tree_popup->popup(); } @@ -2262,12 +2282,12 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { file_list_popup->clear(); file_list_popup->set_size(Size2(1, 1)); - file_list_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); - file_list_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); - file_list_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); - file_list_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + file_list_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER); + file_list_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE); + file_list_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT); + file_list_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE); file_list_popup->add_separator(); - file_list_popup->add_item(TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER); + file_list_popup->add_icon_item(get_icon("Filesystem", "EditorIcons"), TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER); file_list_popup->set_position(files->get_global_position() + p_pos); file_list_popup->popup(); } |