Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix root folder logic in the filesystem #100161

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3242,6 +3242,10 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
p_popup->add_separator();
}

// Check if the root path is selected, we must check p_paths[1] because the first string in
// the list of paths obtained by _tree_get_selected(...) is not always the root path.
bool root_path_not_selected = p_paths[0] != "res://" && (p_paths.size() <= 1 || p_paths[1] != "res://");

if (all_folders && foldernames.size() > 0) {
p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Expand Folder"), FILE_OPEN);

Expand All @@ -3252,7 +3256,8 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect

p_popup->add_separator();

if (p_paths[0] != "res://") {
// Only add the 'Set Folder Color...' option if the root path is not selected.
if (root_path_not_selected) {
PopupMenu *folder_colors_menu = memnew(PopupMenu);
folder_colors_menu->connect(SceneStringName(id_pressed), callable_mp(this, &FileSystemDock::_folder_color_index_pressed).bind(folder_colors_menu));

Expand All @@ -3272,25 +3277,31 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
}
}

// Add the options that are only available when a single item is selected.
if (p_paths.size() == 1) {
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionCopy")), ED_GET_SHORTCUT("filesystem_dock/copy_path"), FILE_COPY_PATH);
p_popup->add_shortcut(ED_GET_SHORTCUT("filesystem_dock/copy_absolute_path"), FILE_COPY_ABSOLUTE_PATH);
if (ResourceLoader::get_resource_uid(p_paths[0]) != ResourceUID::INVALID_ID) {
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Instance")), ED_GET_SHORTCUT("filesystem_dock/copy_uid"), FILE_COPY_UID);
}
if (p_paths[0] != "res://") {
if (root_path_not_selected) {
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Rename")), ED_GET_SHORTCUT("filesystem_dock/rename"), FILE_RENAME);
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Duplicate")), ED_GET_SHORTCUT("filesystem_dock/duplicate"), FILE_DUPLICATE);
}
}

if (p_paths.size() > 1 || p_paths[0] != "res://") {
// Add the options that are only available when the root path is not selected.
if (root_path_not_selected) {
p_popup->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Move/Duplicate To..."), FILE_MOVE);
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Remove")), ED_GET_SHORTCUT("filesystem_dock/delete"), FILE_REMOVE);
}

p_popup->add_separator();
// Only add a separator if we have actually placed any options in the menu since the last separator.
if (p_paths.size() == 1 || root_path_not_selected) {
p_popup->add_separator();
}

// Add the options that are available when one or more items are selected.
if (p_paths.size() >= 1) {
if (!all_favorites) {
p_popup->add_icon_item(get_editor_theme_icon(SNAME("Favorites")), TTR("Add to Favorites"), FILE_ADD_FAVORITE);
Expand All @@ -3299,7 +3310,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
p_popup->add_icon_item(get_editor_theme_icon(SNAME("NonFavorite")), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE);
}

if (p_paths.size() > 1 || p_paths[0] != "res://") {
if (root_path_not_selected) {
cached_valid_conversion_targets = _get_valid_conversions_for_file_paths(p_paths);

int relative_id = 0;
Expand Down