mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #94582 from citizenll/feat_context_menu_plugin4.x
Add support for custom items to editor right-click context menus
This commit is contained in:
commit
79da448d5f
12 changed files with 470 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue