From 94669955d836950708be2ee2501d752aeba52f5b Mon Sep 17 00:00:00 2001 From: Ozelot Vanilla Date: Mon, 2 Jun 2025 15:37:12 +0900 Subject: [PATCH] fix: EditorContextMenuPlugin CONTEXT_SLOT_FILESYSTEM_CREATE does not receive path information for some menu Also add explanation in `EditorContextMenuPlugin`'s doc for fixing path information passing (Accept PR #106820 suggestion by: Tomasz Chabora ) --- doc/classes/EditorContextMenuPlugin.xml | 2 +- editor/filesystem_dock.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/classes/EditorContextMenuPlugin.xml b/doc/classes/EditorContextMenuPlugin.xml index a476ac47544..834abe208f4 100644 --- a/doc/classes/EditorContextMenuPlugin.xml +++ b/doc/classes/EditorContextMenuPlugin.xml @@ -89,7 +89,7 @@ Context menu of Script editor's script tabs. [method _popup_menu] will be called with the path to the currently edited script, while option callback will receive reference to that script. - The "Create..." submenu of FileSystem dock's context menu, or the "New" section of the main context menu when empty space is clicked. [method _popup_menu] and option callback will be called with list of paths of the currently selected files. When clicking the empty space, the list of paths for popup method will be empty. + The "Create..." submenu of FileSystem dock's context menu, or the "New" section of the main context menu when empty space is clicked. [method _popup_menu] and option callback will be called with the path of the currently selected folder, wrapped in a list. When clicking the empty space, the list of paths for popup method will be empty. Context menu of Script editor's code editor. [method _popup_menu] will be called with the path to the [CodeEdit] node. You can fetch it using this code: diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index e9f8d4cb0d7..bd216436b27 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2613,7 +2613,12 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected default: { if (p_option >= EditorContextMenuPlugin::BASE_ID) { if (!EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_option, p_selected)) { - EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_option, p_selected); + // For create new file option, pass the path location of mouse click position instead, to plugin callback. + String fpath = current_path; + if (!fpath.ends_with("/")) { + fpath = fpath.get_base_dir(); + } + EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_option, { fpath }); } } else if (p_option >= CONVERT_BASE_ID) { selected_conversion_id = p_option - CONVERT_BASE_ID;