summaryrefslogtreecommitdiffstats
path: root/editor/plugins/script_editor_plugin.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-03 16:13:47 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-03 16:13:47 +0200
commit79da448d5fb01cd1b0461b3bded1e4b9049d69b6 (patch)
treecbb92afc6b9eb072683c4b0f20eec3b0cc218536 /editor/plugins/script_editor_plugin.cpp
parent5a374548fa80bef1745392196c6755547012ba9b (diff)
parent6b2348adacb5bb7affb1d50a2c71ce2b3d3c5e70 (diff)
downloadredot-engine-79da448d5fb01cd1b0461b3bded1e4b9049d69b6.tar.gz
Merge pull request #94582 from citizenll/feat_context_menu_plugin4.x
Add support for custom items to editor right-click context menus
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r--editor/plugins/script_editor_plugin.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index d7de5a7223..5d3f1b5bf0 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -57,6 +57,7 @@
#include "editor/gui/editor_toaster.h"
#include "editor/inspector_dock.h"
#include "editor/node_dock.h"
+#include "editor/plugins/editor_context_menu_plugin.h"
#include "editor/plugins/shader_editor_plugin.h"
#include "editor/plugins/text_shader_editor.h"
#include "editor/themes/editor_scale.h"
@@ -1398,6 +1399,16 @@ void ScriptEditor::_menu_option(int p_option) {
}
}
+ // Context menu options.
+ if (p_option >= EditorData::CONTEXT_MENU_ITEM_ID_BASE) {
+ Ref<Resource> resource;
+ if (current) {
+ resource = current->get_edited_resource();
+ }
+ EditorNode::get_editor_data().script_editor_options_pressed(EditorData::CONTEXT_SLOT_SCRIPT_EDITOR, p_option, resource);
+ return;
+ }
+
if (current) {
switch (p_option) {
case FILE_SAVE: {
@@ -3304,6 +3315,11 @@ void ScriptEditor::shortcut_input(const Ref<InputEvent> &p_event) {
_menu_option(WINDOW_MOVE_DOWN);
accept_event();
}
+ // Context menu shortcuts.
+ int match_option = EditorNode::get_editor_data().match_context_menu_shortcut(EditorData::CONTEXT_SLOT_SCRIPT_EDITOR, p_event);
+ if (match_option) {
+ _menu_option(match_option);
+ }
}
void ScriptEditor::_script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index) {
@@ -3362,6 +3378,17 @@ void ScriptEditor::_make_script_list_context_menu() {
context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_MOVE_DOWN), tab_container->get_current_tab() >= tab_container->get_tab_count() - 1);
context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_SORT), tab_container->get_tab_count() <= 1);
+ // Context menu plugin.
+ Vector<String> selected_paths;
+ if (se) {
+ Ref<Resource> scr = se->get_edited_resource();
+ if (scr.is_valid()) {
+ String path = scr->get_path();
+ selected_paths.push_back(path);
+ }
+ }
+ EditorNode::get_editor_data().add_options_from_plugins(context_menu, EditorData::CONTEXT_SLOT_SCRIPT_EDITOR, selected_paths);
+
context_menu->set_position(get_screen_position() + get_local_mouse_position());
context_menu->reset_size();
context_menu->popup();