From f47778ad5286d2ad9d03a6cf7ff519aab4483de0 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 26 Oct 2025 12:20:24 +0100 Subject: [PATCH] Fix potential conflicts in FileSystem context menu plugins --- editor/docks/filesystem_dock.cpp | 7 ++++--- editor/inspector/editor_context_menu_plugin.cpp | 4 ++-- editor/inspector/editor_context_menu_plugin.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/editor/docks/filesystem_dock.cpp b/editor/docks/filesystem_dock.cpp index cd22fa640d..4de3e599db 100644 --- a/editor/docks/filesystem_dock.cpp +++ b/editor/docks/filesystem_dock.cpp @@ -3360,7 +3360,8 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect new_menu->set_item_shortcut(-1, ED_GET_SHORTCUT("filesystem_dock/new_textfile")); const PackedStringArray folder_path = { p_paths[0].get_base_dir() }; - EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(new_menu, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, folder_path); + // Options for CONTEXT_SLOT_FILESYSTEM_CREATE are added with an offset, to avoid conflicts in case plugins add options for both FileSystem slots. + EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(new_menu, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, folder_path, 500); p_popup->add_separator(); } @@ -3589,7 +3590,7 @@ void FileSystemDock::_tree_empty_click(const Vector2 &p_pos, MouseButton p_butto tree_popup->set_item_shortcut(-1, ED_GET_SHORTCUT("filesystem_dock/new_textfile")); // To keep consistency with options added to "Create New..." menu (for plugin which has slot as CONTEXT_SLOT_FILESYSTEM_CREATE). - EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(tree_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, Vector()); + EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(tree_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, Vector(), 500); #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) // Opening the system file manager is not supported on the Android and web editors. tree_popup->add_separator(); @@ -3673,7 +3674,7 @@ void FileSystemDock::_file_list_empty_clicked(const Vector2 &p_pos, MouseButton file_list_popup->set_item_shortcut(-1, ED_GET_SHORTCUT("filesystem_dock/new_textfile")); // To keep consistency with options added to "Create New..." menu (for plugin which has slot as CONTEXT_SLOT_FILESYSTEM_CREATE). - EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(file_list_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, Vector()); + EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(file_list_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, Vector(), 500); file_list_popup->add_separator(); file_list_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Terminal")), ED_GET_SHORTCUT("filesystem_dock/open_in_terminal"), FILE_MENU_OPEN_IN_TERMINAL); file_list_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_MENU_SHOW_IN_EXPLORER); diff --git a/editor/inspector/editor_context_menu_plugin.cpp b/editor/inspector/editor_context_menu_plugin.cpp index 7af5029c7b..a8a22aafe3 100644 --- a/editor/inspector/editor_context_menu_plugin.cpp +++ b/editor/inspector/editor_context_menu_plugin.cpp @@ -117,10 +117,10 @@ bool EditorContextMenuPluginManager::has_plugins_for_slot(ContextMenuSlot p_slot return false; } -void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector &p_paths) { +void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector &p_paths, int p_id_offset) { bool separator_added = false; const int icon_size = p_popup->get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); - int id = EditorContextMenuPlugin::BASE_ID; + int id = EditorContextMenuPlugin::BASE_ID + p_id_offset; for (Ref &plugin : plugin_list) { if (plugin->slot != p_slot) { diff --git a/editor/inspector/editor_context_menu_plugin.h b/editor/inspector/editor_context_menu_plugin.h index 084b822bd0..49142c99fb 100644 --- a/editor/inspector/editor_context_menu_plugin.h +++ b/editor/inspector/editor_context_menu_plugin.h @@ -103,7 +103,7 @@ public: void remove_plugin(const Ref &p_plugin); bool has_plugins_for_slot(ContextMenuSlot p_slot); - void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector &p_paths); + void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector &p_paths, int p_id_offset = 0); Callable match_custom_shortcut(ContextMenuSlot p_slot, const Ref &p_event); bool activate_custom_option(ContextMenuSlot p_slot, int p_option, const Variant &p_arg);