diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6f30d5a492d..962a4e29cd2 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -5565,6 +5565,7 @@ AnimationTrackEditor::AnimationTrackEditor() { undo_redo = EditorNode::get_singleton()->get_undo_redo(); main_panel = memnew(PanelContainer); + main_panel->set_focus_mode(FOCUS_ALL); // allow panel to have focus so that shortcuts work as expected. add_child(main_panel); main_panel->set_v_size_flags(SIZE_EXPAND_FILL); HBoxContainer *timeline_scroll = memnew(HBoxContainer); @@ -5698,6 +5699,7 @@ AnimationTrackEditor::AnimationTrackEditor() { timeline->set_zoom(zoom); edit = memnew(MenuButton); + edit->set_shortcut_context(this); edit->set_text(TTR("Edit")); edit->set_flat(false); edit->set_disabled(true); @@ -5710,12 +5712,8 @@ AnimationTrackEditor::AnimationTrackEditor() { edit->get_popup()->add_separator(); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD | KEY_D), EDIT_DUPLICATE_SELECTION); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection_transposed", TTR("Duplicate Transposed"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_D), EDIT_DUPLICATE_TRANSPOSED); - edit->get_popup()->set_item_shortcut_disabled(edit->get_popup()->get_item_index(EDIT_DUPLICATE_SELECTION), true); - edit->get_popup()->set_item_shortcut_disabled(edit->get_popup()->get_item_index(EDIT_DUPLICATE_TRANSPOSED), true); edit->get_popup()->add_separator(); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/delete_selection", TTR("Delete Selection"), KEY_DELETE), EDIT_DELETE_SELECTION); - edit->get_popup()->set_item_shortcut_disabled(edit->get_popup()->get_item_index(EDIT_DELETE_SELECTION), true); - //this shortcut will be checked from the track itself. so no need to enable it here (will conflict with scenetree dock) edit->get_popup()->add_separator(); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/goto_next_step", TTR("Go to Next Step"), KEY_MASK_CMD | KEY_RIGHT), EDIT_GOTO_NEXT_STEP); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 64ff96bee4c..225f7c7fb0f 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -531,12 +531,6 @@ void EditorAudioBus::_effect_add(int p_which) { } void EditorAudioBus::_gui_input(const Ref &p_event) { - Ref k = p_event; - if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && !k->is_echo()) { - accept_event(); - emit_signal("delete_request"); - } - Ref mb = p_event; if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y); @@ -803,12 +797,6 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { hbc->add_child(bypass); hbc->add_spacer(); - bus_options = memnew(MenuButton); - bus_options->set_h_size_flags(SIZE_SHRINK_END); - bus_options->set_anchor(MARGIN_RIGHT, 0.0); - bus_options->set_tooltip(TTR("Bus options")); - hbc->add_child(bus_options); - Ref sbempty = memnew(StyleBoxEmpty); for (int i = 0; i < hbc->get_child_count(); i++) { Control *child = Object::cast_to(hbc->get_child(i)); @@ -931,9 +919,16 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { effect_options->set_item_icon(effect_options->get_item_count() - 1, icon); } + bus_options = memnew(MenuButton); + bus_options->set_shortcut_context(this); + bus_options->set_h_size_flags(SIZE_SHRINK_END); + bus_options->set_anchor(MARGIN_RIGHT, 0.0); + bus_options->set_tooltip(TTR("Bus options")); + hbc->add_child(bus_options); + bus_popup = bus_options->get_popup(); - bus_popup->add_item(TTR("Duplicate")); - bus_popup->add_item(TTR("Delete")); + bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/duplicate_selected_bus", TTR("Duplicate Bus"), KEY_MASK_CMD | KEY_D)); + bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/delete_selected_bus", TTR("Delete Bus"), KEY_DELETE)); bus_popup->set_item_disabled(1, is_master); bus_popup->add_item(TTR("Reset Volume")); bus_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_bus_popup_pressed)); diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 6fbafc7ff3e..e1263ad7d10 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -160,12 +160,14 @@ EditorLog::EditorLog() { hb->add_child(copybutton); copybutton->set_text(TTR("Copy")); copybutton->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KEY_MASK_CMD | KEY_C)); + copybutton->set_shortcut_context(this); copybutton->connect("pressed", callable_mp(this, &EditorLog::_copy_request)); clearbutton = memnew(Button); hb->add_child(clearbutton); clearbutton->set_text(TTR("Clear")); clearbutton->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K)); + clearbutton->set_shortcut_context(this); clearbutton->connect("pressed", callable_mp(this, &EditorLog::_clear_request)); log = memnew(RichTextLabel); diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index c88cd8ea5fb..a7afba6c0d3 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -554,6 +554,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { node_info_hb->add_child(editor_path); object_menu = memnew(MenuButton); + object_menu->set_shortcut_context(this); object_menu->set_icon(get_theme_icon("Tools", "EditorIcons")); node_info_hb->add_child(object_menu); object_menu->set_tooltip(TTR("Object properties.")); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 1e56e3d11f2..3290b96cf0f 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1210,9 +1210,11 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref &p_ev) { } else { _play_bw_pressed(); } + accept_event(); } break; case KEY_S: { _stop_pressed(); + accept_event(); } break; case KEY_D: { if (!k->get_shift()) { @@ -1220,6 +1222,7 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref &p_ev) { } else { _play_pressed(); } + accept_event(); } break; } } @@ -1545,6 +1548,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay delete_dialog->connect("confirmed", callable_mp(this, &AnimationPlayerEditor::_animation_remove_confirmed)); tool_anim = memnew(MenuButton); + tool_anim->set_shortcut_context(this); tool_anim->set_flat(false); tool_anim->set_tooltip(TTR("Animation Tools")); tool_anim->set_text(TTR("Animation")); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 5742becf3a6..9ecf5193a2d 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -580,7 +580,7 @@ void EditorAssetLibrary::_notification(int p_what) { } } -void EditorAssetLibrary::_unhandled_input(const Ref &p_event) { +void EditorAssetLibrary::_unhandled_key_input(const Ref &p_event) { const Ref key = p_event; if (key.is_valid() && key->is_pressed()) { @@ -1281,7 +1281,7 @@ void EditorAssetLibrary::disable_community_support() { } void EditorAssetLibrary::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &EditorAssetLibrary::_unhandled_input); + ClassDB::bind_method("_unhandled_key_input", &EditorAssetLibrary::_unhandled_key_input); ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); } @@ -1454,7 +1454,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { description = nullptr; set_process(true); - set_process_unhandled_input(true); + set_process_unhandled_key_input(true); // Global shortcuts since there is no main element to be focused. downloads_scroll = memnew(ScrollContainer); downloads_scroll->set_enable_h_scroll(true); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index f7ad53f87b7..9761dbba1e7 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -298,7 +298,7 @@ class EditorAssetLibrary : public PanelContainer { protected: static void _bind_methods(); void _notification(int p_what); - void _unhandled_input(const Ref &p_event); + void _unhandled_key_input(const Ref &p_event); public: void disable_community_support(); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6acf80a2c10..dbd61a3a961 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5722,6 +5722,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_hb->add_child(zoom_minus); zoom_minus->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_zoom_minus)); zoom_minus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_minus", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS)); + zoom_minus->set_shortcut_context(this); zoom_minus->set_focus_mode(FOCUS_NONE); zoom_reset = memnew(Button); @@ -5734,6 +5735,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_reset->add_theme_color_override("font_color", Color(1, 1, 1)); zoom_reset->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_zoom_reset)); zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset"), KEY_MASK_CMD | KEY_0)); + zoom_reset->set_shortcut_context(this); zoom_reset->set_focus_mode(FOCUS_NONE); zoom_reset->set_text_align(Button::TextAlign::ALIGN_CENTER); // Prevent the button's size from changing when the text size changes @@ -5744,6 +5746,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_hb->add_child(zoom_plus); zoom_plus->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_zoom_plus)); zoom_plus->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_plus", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL)); // Usually direct access key for PLUS + zoom_plus->set_shortcut_context(this); zoom_plus->set_focus_mode(FOCUS_NONE); updating_scroll = false; @@ -5755,6 +5758,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { select_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_SELECT)); select_button->set_pressed(true); select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode", TTR("Select Mode"), KEY_Q)); + select_button->set_shortcut_context(this); select_button->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate") + "\n" + TTR("Alt+Drag: Move") + "\n" + TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).") + "\n" + TTR("Alt+RMB: Depth list selection")); hb->add_child(memnew(VSeparator)); @@ -5765,6 +5769,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { move_button->set_toggle_mode(true); move_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_MOVE)); move_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/move_mode", TTR("Move Mode"), KEY_W)); + move_button->set_shortcut_context(this); move_button->set_tooltip(TTR("Move Mode")); rotate_button = memnew(Button); @@ -5773,6 +5778,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { rotate_button->set_toggle_mode(true); rotate_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_ROTATE)); rotate_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/rotate_mode", TTR("Rotate Mode"), KEY_E)); + rotate_button->set_shortcut_context(this); rotate_button->set_tooltip(TTR("Rotate Mode")); scale_button = memnew(Button); @@ -5781,6 +5787,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { scale_button->set_toggle_mode(true); scale_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_SCALE)); scale_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/scale_mode", TTR("Scale Mode"), KEY_S)); + scale_button->set_shortcut_context(this); scale_button->set_tooltip(TTR("Scale Mode")); hb->add_child(memnew(VSeparator)); @@ -5805,6 +5812,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { pan_button->set_toggle_mode(true); pan_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_PAN)); pan_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/pan_mode", TTR("Pan Mode"), KEY_G)); + pan_button->set_shortcut_context(this); pan_button->set_tooltip(TTR("Pan Mode")); ruler_button = memnew(Button); @@ -5813,6 +5821,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { ruler_button->set_toggle_mode(true); ruler_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_tool_select), make_binds(TOOL_RULER)); ruler_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/ruler_mode", TTR("Ruler Mode"), KEY_R)); + ruler_button->set_shortcut_context(this); ruler_button->set_tooltip(TTR("Ruler Mode")); hb->add_child(memnew(VSeparator)); @@ -5824,6 +5833,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { smart_snap_button->connect("toggled", callable_mp(this, &CanvasItemEditor::_button_toggle_smart_snap)); smart_snap_button->set_tooltip(TTR("Toggle smart snapping.")); smart_snap_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/use_smart_snap", TTR("Use Smart Snap"), KEY_MASK_SHIFT | KEY_S)); + smart_snap_button->set_shortcut_context(this); grid_snap_button = memnew(Button); grid_snap_button->set_flat(true); @@ -5832,8 +5842,10 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { grid_snap_button->connect("toggled", callable_mp(this, &CanvasItemEditor::_button_toggle_grid_snap)); grid_snap_button->set_tooltip(TTR("Toggle grid snapping.")); grid_snap_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/use_grid_snap", TTR("Use Grid Snap"), KEY_MASK_SHIFT | KEY_G)); + grid_snap_button->set_shortcut_context(this); snap_config_menu = memnew(MenuButton); + snap_config_menu->set_shortcut_context(this); hb->add_child(snap_config_menu); snap_config_menu->set_h_size_flags(SIZE_SHRINK_END); snap_config_menu->set_tooltip(TTR("Snapping Options")); @@ -5893,6 +5905,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { hb->add_child(memnew(VSeparator)); skeleton_menu = memnew(MenuButton); + skeleton_menu->set_shortcut_context(this); hb->add_child(skeleton_menu); skeleton_menu->set_tooltip(TTR("Skeleton Options")); skeleton_menu->set_switch_on_hover(true); @@ -5921,6 +5934,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { hb->add_child(memnew(VSeparator)); view_menu = memnew(MenuButton); + view_menu->set_shortcut_context(this); view_menu->set_text(TTR("View")); hb->add_child(view_menu); view_menu->get_popup()->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_popup_callback)); @@ -5945,6 +5959,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE); presets_menu = memnew(MenuButton); + presets_menu->set_shortcut_context(this); presets_menu->set_text(TTR("Layout")); hb->add_child(presets_menu); presets_menu->hide(); @@ -5978,6 +5993,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_loc_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_POS)); key_loc_button->set_tooltip(TTR("Translation mask for inserting keys.")); animation_hb->add_child(key_loc_button); + key_rot_button = memnew(Button); key_rot_button->set_toggle_mode(true); key_rot_button->set_flat(true); @@ -5986,6 +6002,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_rot_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_ROT)); key_rot_button->set_tooltip(TTR("Rotation mask for inserting keys.")); animation_hb->add_child(key_rot_button); + key_scale_button = memnew(Button); key_scale_button->set_toggle_mode(true); key_scale_button->set_flat(true); @@ -5993,23 +6010,27 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_scale_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_SCALE)); key_scale_button->set_tooltip(TTR("Scale mask for inserting keys.")); animation_hb->add_child(key_scale_button); + key_insert_button = memnew(Button); key_insert_button->set_flat(true); key_insert_button->set_focus_mode(FOCUS_NONE); key_insert_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_KEY)); key_insert_button->set_tooltip(TTR("Insert keys (based on mask).")); key_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key", TTR("Insert Key"), KEY_INSERT)); + key_insert_button->set_shortcut_context(this); animation_hb->add_child(key_insert_button); + key_auto_insert_button = memnew(Button); key_auto_insert_button->set_flat(true); key_auto_insert_button->set_toggle_mode(true); key_auto_insert_button->set_focus_mode(FOCUS_NONE); - //key_auto_insert_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_KEY)); key_auto_insert_button->set_tooltip(TTR("Auto insert keys when objects are translated, rotated or scaled (based on mask).\nKeys are only added to existing tracks, no new tracks will be created.\nKeys must be inserted manually for the first time.")); key_auto_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_auto_insert_key", TTR("Auto Insert Key"))); + key_auto_insert_button->set_shortcut_context(this); animation_hb->add_child(key_auto_insert_button); animation_menu = memnew(MenuButton); + animation_menu->set_shortcut_context(this); animation_menu->set_tooltip(TTR("Animation Key and Pose Options")); animation_hb->add_child(animation_menu); animation_menu->get_popup()->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_popup_callback)); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index fa7300c9303..42bb2ae3762 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -3903,8 +3903,9 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito view_menu = memnew(MenuButton); view_menu->set_flat(false); - vbox->add_child(view_menu); view_menu->set_h_size_flags(0); + view_menu->set_shortcut_context(this); + vbox->add_child(view_menu); display_submenu = memnew(PopupMenu); view_menu->get_popup()->add_child(display_submenu); @@ -6217,6 +6218,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_SELECT; tool_button[TOOL_MODE_SELECT]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_MODE_SELECT]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), KEY_Q)); + tool_button[TOOL_MODE_SELECT]->set_shortcut_context(this); tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); hbc_menu->add_child(memnew(VSeparator)); @@ -6228,6 +6230,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_MOVE; tool_button[TOOL_MODE_MOVE]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_MODE_MOVE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_move", TTR("Move Mode"), KEY_W)); + tool_button[TOOL_MODE_MOVE]->set_shortcut_context(this); tool_button[TOOL_MODE_ROTATE] = memnew(Button); hbc_menu->add_child(tool_button[TOOL_MODE_ROTATE]); @@ -6236,6 +6239,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_ROTATE; tool_button[TOOL_MODE_ROTATE]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_MODE_ROTATE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Rotate Mode"), KEY_E)); + tool_button[TOOL_MODE_ROTATE]->set_shortcut_context(this); tool_button[TOOL_MODE_SCALE] = memnew(Button); hbc_menu->add_child(tool_button[TOOL_MODE_SCALE]); @@ -6244,6 +6248,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_SCALE; tool_button[TOOL_MODE_SCALE]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_MODE_SCALE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_scale", TTR("Scale Mode"), KEY_R)); + tool_button[TOOL_MODE_SCALE]->set_shortcut_context(this); hbc_menu->add_child(memnew(VSeparator)); @@ -6292,6 +6297,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_LOCAL_COORDS; tool_option_button[TOOL_OPT_LOCAL_COORDS]->connect("toggled", callable_mp(this, &Node3DEditor::_menu_item_toggled), button_binds); tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_shortcut(ED_SHORTCUT("spatial_editor/local_coords", TTR("Use Local Space"), KEY_T)); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_shortcut_context(this); tool_option_button[TOOL_OPT_USE_SNAP] = memnew(Button); hbc_menu->add_child(tool_option_button[TOOL_OPT_USE_SNAP]); @@ -6300,6 +6306,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_TOOL_USE_SNAP; tool_option_button[TOOL_OPT_USE_SNAP]->connect("toggled", callable_mp(this, &Node3DEditor::_menu_item_toggled), button_binds); tool_option_button[TOOL_OPT_USE_SNAP]->set_shortcut(ED_SHORTCUT("spatial_editor/snap", TTR("Use Snap"), KEY_Y)); + tool_option_button[TOOL_OPT_USE_SNAP]->set_shortcut_context(this); hbc_menu->add_child(memnew(VSeparator)); @@ -6337,6 +6344,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { transform_menu = memnew(MenuButton); transform_menu->set_text(TTR("Transform")); transform_menu->set_switch_on_hover(true); + transform_menu->set_shortcut_context(this); hbc_menu->add_child(transform_menu); p = transform_menu->get_popup(); @@ -6351,6 +6359,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { view_menu = memnew(MenuButton); view_menu->set_text(TTR("View")); view_menu->set_switch_on_hover(true); + view_menu->set_shortcut_context(this); hbc_menu->add_child(view_menu); p = view_menu->get_popup(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8dd7d6d6e2c..93d13c97104 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2637,7 +2637,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } } -void ScriptEditor::_unhandled_input(const Ref &p_event) { +void ScriptEditor::_unhandled_key_input(const Ref &p_event) { if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) { return; } @@ -3165,7 +3165,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_update_script_connections", &ScriptEditor::_update_script_connections); ClassDB::bind_method("_help_class_open", &ScriptEditor::_help_class_open); ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts); - ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input); + ClassDB::bind_method("_unhandled_key_input", &ScriptEditor::_unhandled_key_input); ClassDB::bind_method("_update_members_overview", &ScriptEditor::_update_members_overview); ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts); @@ -3292,12 +3292,13 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); - set_process_unhandled_input(true); + set_process_unhandled_key_input(true); file_menu = memnew(MenuButton); - menu_hb->add_child(file_menu); file_menu->set_text(TTR("File")); file_menu->set_switch_on_hover(true); + file_menu->set_shortcut_context(this); + menu_hb->add_child(file_menu); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script...")), FILE_NEW); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New Text File...")), FILE_NEW_TEXTFILE); @@ -3352,10 +3353,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptEditor::_menu_option)); script_search_menu = memnew(MenuButton); - menu_hb->add_child(script_search_menu); script_search_menu->set_text(TTR("Search")); script_search_menu->set_switch_on_hover(true); + script_search_menu->set_shortcut_context(this); script_search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptEditor::_menu_option)); + menu_hb->add_child(script_search_menu); MenuButton *debug_menu = memnew(MenuButton); menu_hb->add_child(debug_menu); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 32f47239efa..f1453c3d20c 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -402,7 +402,7 @@ class ScriptEditor : public PanelContainer { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); - void _unhandled_input(const Ref &p_event); + void _unhandled_key_input(const Ref &p_event); void _script_list_gui_input(const Ref &ev); void _make_script_list_context_menu(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 7feb7cb3d3f..c2460ead69a 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1845,6 +1845,7 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu = memnew(MenuButton); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); + edit_menu->set_shortcut_context(this); convert_case = memnew(PopupMenu); convert_case->set_name("convert_case"); @@ -1864,10 +1865,12 @@ ScriptTextEditor::ScriptTextEditor() { search_menu = memnew(MenuButton); search_menu->set_text(TTR("Search")); search_menu->set_switch_on_hover(true); + search_menu->set_shortcut_context(this); goto_menu = memnew(MenuButton); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); + goto_menu->set_shortcut_context(this); bookmarks_menu = memnew(PopupMenu); bookmarks_menu->set_name("Bookmarks"); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 0063bec9de0..5b0e1ce5b50 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -581,6 +581,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { HBoxContainer *hbc = memnew(HBoxContainer); edit_menu = memnew(MenuButton); + edit_menu->set_shortcut_context(this); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); @@ -605,6 +606,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option)); search_menu = memnew(MenuButton); + search_menu->set_shortcut_context(this); search_menu->set_text(TTR("Search")); search_menu->set_switch_on_hover(true); @@ -615,6 +617,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option)); MenuButton *goto_menu = memnew(MenuButton); + goto_menu->set_shortcut_context(this); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); goto_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option)); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 8935b698b67..9894d0e1b03 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -563,6 +563,7 @@ TextEditor::TextEditor() { edit_hb = memnew(HBoxContainer); search_menu = memnew(MenuButton); + search_menu->set_shortcut_context(this); edit_hb->add_child(search_menu); search_menu->set_text(TTR("Search")); search_menu->set_switch_on_hover(true); @@ -577,6 +578,7 @@ TextEditor::TextEditor() { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES); edit_menu = memnew(MenuButton); + edit_menu->set_shortcut_context(this); edit_hb->add_child(edit_menu); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); @@ -631,6 +633,7 @@ TextEditor::TextEditor() { set_syntax_highlighter(plain_highlighter); MenuButton *goto_menu = memnew(MenuButton); + goto_menu->set_shortcut_context(this); edit_hb->add_child(goto_menu); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 7b516175b23..d4309777cd1 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -2109,6 +2109,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { paint_button = memnew(Button); paint_button->set_flat(true); paint_button->set_shortcut(ED_SHORTCUT("tile_map_editor/paint_tile", TTR("Paint Tile"), KEY_P)); + paint_button->set_shortcut_context(this); paint_button->set_tooltip(TTR("RMB: Erase")); paint_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_NONE)); paint_button->set_toggle_mode(true); @@ -2117,6 +2118,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { line_button = memnew(Button); line_button->set_flat(true); line_button->set_shortcut(ED_SHORTCUT("tile_map_editor/line_fill", TTR("Line Fill"), KEY_L)); + line_button->set_shortcut_context(this); line_button->set_tooltip(TTR("RMB: Erase")); line_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_LINE_PAINT)); line_button->set_toggle_mode(true); @@ -2125,6 +2127,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { rectangle_button = memnew(Button); rectangle_button->set_flat(true); rectangle_button->set_shortcut(ED_SHORTCUT("tile_map_editor/rectangle_fill", TTR("Rectangle Fill"), KEY_O)); + rectangle_button->set_shortcut_context(this); rectangle_button->set_tooltip(TTR("Shift+LMB: Keep 1:1 proporsions\nRMB: Erase")); rectangle_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_RECTANGLE_PAINT)); rectangle_button->set_toggle_mode(true); @@ -2133,6 +2136,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { bucket_fill_button = memnew(Button); bucket_fill_button->set_flat(true); bucket_fill_button->set_shortcut(ED_SHORTCUT("tile_map_editor/bucket_fill", TTR("Bucket Fill"), KEY_B)); + bucket_fill_button->set_shortcut_context(this); bucket_fill_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_BUCKET)); bucket_fill_button->set_toggle_mode(true); toolbar->add_child(bucket_fill_button); @@ -2140,6 +2144,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { picker_button = memnew(Button); picker_button->set_flat(true); picker_button->set_shortcut(ED_SHORTCUT("tile_map_editor/pick_tile", TTR("Pick Tile"), KEY_I)); + picker_button->set_shortcut_context(this); picker_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_PICKING)); picker_button->set_toggle_mode(true); toolbar->add_child(picker_button); @@ -2147,6 +2152,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { select_button = memnew(Button); select_button->set_flat(true); select_button->set_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_M)); + select_button->set_shortcut_context(this); select_button->connect("pressed", callable_mp(this, &TileMapEditor::_button_tool_select), make_binds(TOOL_SELECTING)); select_button->set_toggle_mode(true); toolbar->add_child(select_button); @@ -2171,9 +2177,9 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { // Menu. options = memnew(MenuButton); + options->set_shortcut_context(this); options->set_text("TileMap"); options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("TileMap", "EditorIcons")); - options->set_process_unhandled_key_input(false); toolbar_right->add_child(options); PopupMenu *p = options->get_popup(); @@ -2190,6 +2196,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { rotate_left_button->set_focus_mode(FOCUS_NONE); rotate_left_button->connect("pressed", callable_mp(this, &TileMapEditor::_rotate), varray(-1)); rotate_left_button->set_shortcut(ED_SHORTCUT("tile_map_editor/rotate_left", TTR("Rotate Left"), KEY_A)); + rotate_left_button->set_shortcut_context(this); tool_hb->add_child(rotate_left_button); rotate_right_button = memnew(Button); @@ -2198,6 +2205,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { rotate_right_button->set_focus_mode(FOCUS_NONE); rotate_right_button->connect("pressed", callable_mp(this, &TileMapEditor::_rotate), varray(1)); rotate_right_button->set_shortcut(ED_SHORTCUT("tile_map_editor/rotate_right", TTR("Rotate Right"), KEY_S)); + rotate_right_button->set_shortcut_context(this); tool_hb->add_child(rotate_right_button); flip_horizontal_button = memnew(Button); @@ -2206,6 +2214,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { flip_horizontal_button->set_focus_mode(FOCUS_NONE); flip_horizontal_button->connect("pressed", callable_mp(this, &TileMapEditor::_flip_horizontal)); flip_horizontal_button->set_shortcut(ED_SHORTCUT("tile_map_editor/flip_horizontal", TTR("Flip Horizontally"), KEY_X)); + flip_horizontal_button->set_shortcut_context(this); tool_hb->add_child(flip_horizontal_button); flip_vertical_button = memnew(Button); @@ -2214,6 +2223,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { flip_vertical_button->set_focus_mode(FOCUS_NONE); flip_vertical_button->connect("pressed", callable_mp(this, &TileMapEditor::_flip_vertical)); flip_vertical_button->set_shortcut(ED_SHORTCUT("tile_map_editor/flip_vertical", TTR("Flip Vertically"), KEY_Z)); + flip_vertical_button->set_shortcut_context(this); tool_hb->add_child(flip_vertical_button); clear_transform_button = memnew(Button); @@ -2222,6 +2232,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { clear_transform_button->set_focus_mode(FOCUS_NONE); clear_transform_button->connect("pressed", callable_mp(this, &TileMapEditor::_clear_transform)); clear_transform_button->set_shortcut(ED_SHORTCUT("tile_map_editor/clear_transform", TTR("Clear Transform"), KEY_W)); + clear_transform_button->set_shortcut_context(this); tool_hb->add_child(clear_transform_button); clear_transform_button->set_disabled(true); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 714f38bd561..f41f1141b6b 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -407,6 +407,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { tool_hb->move_child(tools[SELECT_NEXT], WORKSPACE_CREATE_SINGLE); tools[SELECT_NEXT]->set_flat(true); tools[SELECT_NEXT]->set_shortcut(ED_SHORTCUT("tileset_editor/next_shape", TTR("Next Coordinate"), KEY_PAGEDOWN)); + tools[SELECT_NEXT]->set_shortcut_context(this); tools[SELECT_NEXT]->connect("pressed", callable_mp(this, &TileSetEditor::_on_tool_clicked), varray(SELECT_NEXT)); tools[SELECT_NEXT]->set_tooltip(TTR("Select the next shape, subtile, or Tile.")); tools[SELECT_PREVIOUS] = memnew(Button); @@ -414,6 +415,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { tool_hb->move_child(tools[SELECT_PREVIOUS], WORKSPACE_CREATE_SINGLE); tools[SELECT_PREVIOUS]->set_flat(true); tools[SELECT_PREVIOUS]->set_shortcut(ED_SHORTCUT("tileset_editor/previous_shape", TTR("Previous Coordinate"), KEY_PAGEUP)); + tools[SELECT_PREVIOUS]->set_shortcut_context(this); tools[SELECT_PREVIOUS]->set_tooltip(TTR("Select the previous shape, subtile, or Tile.")); tools[SELECT_PREVIOUS]->connect("pressed", callable_mp(this, &TileSetEditor::_on_tool_clicked), varray(SELECT_PREVIOUS)); @@ -460,6 +462,16 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { tool_editmode[EDITMODE_ICON]->set_shortcut(ED_SHORTCUT("tileset_editor/editmode_icon", TTR("Icon Mode"), KEY_7)); tool_editmode[EDITMODE_Z_INDEX]->set_shortcut(ED_SHORTCUT("tileset_editor/editmode_z_index", TTR("Z Index Mode"), KEY_8)); + tool_editmode[EDITMODE_REGION]->set_shortcut_context(this); + tool_editmode[EDITMODE_REGION]->set_shortcut_context(this); + tool_editmode[EDITMODE_COLLISION]->set_shortcut_context(this); + tool_editmode[EDITMODE_OCCLUSION]->set_shortcut_context(this); + tool_editmode[EDITMODE_NAVIGATION]->set_shortcut_context(this); + tool_editmode[EDITMODE_BITMASK]->set_shortcut_context(this); + tool_editmode[EDITMODE_PRIORITY]->set_shortcut_context(this); + tool_editmode[EDITMODE_ICON]->set_shortcut_context(this); + tool_editmode[EDITMODE_Z_INDEX]->set_shortcut_context(this); + main_vb->add_child(tool_hb); separator_editmode = memnew(HSeparator); main_vb->add_child(separator_editmode); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index f26d44d75af..c2431253a79 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -1841,7 +1841,7 @@ void ProjectManager::_notification(int p_what) { } } break; case NOTIFICATION_VISIBILITY_CHANGED: { - set_process_unhandled_input(is_visible_in_tree()); + set_process_unhandled_key_input(is_visible_in_tree()); } break; case NOTIFICATION_WM_CLOSE_REQUEST: { _dim_window(); @@ -1880,7 +1880,7 @@ void ProjectManager::_update_project_buttons() { erase_missing_btn->set_disabled(!_project_list->is_any_project_missing()); } -void ProjectManager::_unhandled_input(const Ref &p_ev) { +void ProjectManager::_unhandled_key_input(const Ref &p_ev) { Ref k = p_ev; if (k.is_valid()) { @@ -2344,7 +2344,7 @@ void ProjectManager::_on_search_term_changed(const String &p_term) { void ProjectManager::_bind_methods() { ClassDB::bind_method("_exit_dialog", &ProjectManager::_exit_dialog); - ClassDB::bind_method("_unhandled_input", &ProjectManager::_unhandled_input); + ClassDB::bind_method("_unhandled_key_input", &ProjectManager::_unhandled_key_input); ClassDB::bind_method("_update_project_buttons", &ProjectManager::_update_project_buttons); } diff --git a/editor/project_manager.h b/editor/project_manager.h index 212d693f1db..eb4b7c1d29e 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -110,7 +110,7 @@ class ProjectManager : public Control { void _install_project(const String &p_zip_path, const String &p_title); void _dim_window(); - void _unhandled_input(const Ref &p_ev); + void _unhandled_key_input(const Ref &p_ev); void _files_dropped(PackedStringArray p_files, int p_screen); void _on_order_option_changed(int p_idx); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 83e16a2dd23..9b45c398b9a 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -2959,6 +2959,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel quick_open = memnew(EditorQuickOpen); add_child(quick_open); quick_open->connect("quick_open", callable_mp(this, &SceneTreeDock::_quick_open)); + set_process_unhandled_key_input(true); delete_dialog = memnew(ConfirmationDialog); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 1bb96a47f3f..80e712e1ef1 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -4728,6 +4728,7 @@ VisualScriptEditor::VisualScriptEditor() { saved_position = Vector2(0, 0); edit_menu = memnew(MenuButton); + edit_menu->set_shortcut_context(this); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/delete_selected"), EDIT_DELETE_NODES); @@ -4929,7 +4930,6 @@ VisualScriptEditor::VisualScriptEditor() { updating_members = false; set_process_input(true); - set_process_unhandled_input(true); default_value_edit = memnew(CustomPropertyEditor); add_child(default_value_edit); diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 84e9fc187c1..fab0dea804b 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -317,14 +317,18 @@ bool BaseButton::is_keep_pressed_outside() const { void BaseButton::set_shortcut(const Ref &p_shortcut) { shortcut = p_shortcut; - set_process_unhandled_input(shortcut.is_valid()); + set_process_unhandled_key_input(shortcut.is_valid()); } Ref BaseButton::get_shortcut() const { return shortcut; } -void BaseButton::_unhandled_input(Ref p_event) { +void BaseButton::_unhandled_key_input(Ref p_event) { + if (!_is_focus_owner_in_shorcut_context()) { + return; + } + if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { on_action_event(p_event); accept_event(); @@ -361,9 +365,34 @@ Ref BaseButton::get_button_group() const { return button_group; } +void BaseButton::set_shortcut_context(Node *p_node) { + ERR_FAIL_NULL_MSG(p_node, "Shortcut context node can't be null."); + shortcut_context = p_node->get_instance_id(); +} + +Node *BaseButton::get_shortcut_context() const { + Object *ctx_obj = ObjectDB::get_instance(shortcut_context); + Node *ctx_node = Object::cast_to(ctx_obj); + + return ctx_node; +} + +bool BaseButton::_is_focus_owner_in_shorcut_context() const { + if (shortcut_context == ObjectID()) { + // No context, therefore global - always "in" context. + return true; + } + + Node *ctx_node = get_shortcut_context(); + Control *vp_focus = get_focus_owner(); + + // If the context is valid and the viewport focus is valid, check if the context is the focus or is a parent of it. + return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_a_parent_of(vp_focus)); +} + void BaseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &BaseButton::_gui_input); - ClassDB::bind_method(D_METHOD("_unhandled_input"), &BaseButton::_unhandled_input); + ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &BaseButton::_unhandled_key_input); ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed); ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed); ClassDB::bind_method(D_METHOD("is_hovered"), &BaseButton::is_hovered); @@ -387,6 +416,9 @@ void BaseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_button_group", "button_group"), &BaseButton::set_button_group); ClassDB::bind_method(D_METHOD("get_button_group"), &BaseButton::get_button_group); + ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &BaseButton::set_shortcut_context); + ClassDB::bind_method(D_METHOD("get_shortcut_context"), &BaseButton::get_shortcut_context); + BIND_VMETHOD(MethodInfo("_pressed")); BIND_VMETHOD(MethodInfo("_toggled", PropertyInfo(Variant::BOOL, "button_pressed"))); @@ -426,6 +458,7 @@ BaseButton::BaseButton() { set_focus_mode(FOCUS_ALL); action_mode = ACTION_MODE_BUTTON_RELEASE; button_mask = BUTTON_MASK_LEFT; + shortcut_context = ObjectID(); } BaseButton::~BaseButton() { diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 33f19949cdd..661801216d5 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -50,6 +50,7 @@ private: bool shortcut_in_tooltip; bool keep_pressed_outside; Ref shortcut; + ObjectID shortcut_context; ActionMode action_mode; struct Status { @@ -75,9 +76,11 @@ protected: virtual void toggled(bool p_pressed); static void _bind_methods(); virtual void _gui_input(Ref p_event); - virtual void _unhandled_input(Ref p_event); + virtual void _unhandled_key_input(Ref p_event); void _notification(int p_what); + bool _is_focus_owner_in_shorcut_context() const; + public: enum DrawMode { DRAW_NORMAL, @@ -122,6 +125,9 @@ public: void set_button_group(const Ref &p_group); Ref get_button_group() const; + void set_shortcut_context(Node *p_node); + Node *get_shortcut_context() const; + BaseButton(); ~BaseButton(); }; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 0381f69bcb2..96bf2577a86 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2729,6 +2729,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("minimum_size_changed"), &Control::minimum_size_changed); BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); + BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size")); MethodInfo get_drag_data = MethodInfo("get_drag_data", PropertyInfo(Variant::VECTOR2, "position")); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index d65e98ea46e..bccea315c4a 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -34,6 +34,10 @@ #include "scene/main/window.h" void MenuButton::_unhandled_key_input(Ref p_event) { + if (!_is_focus_owner_in_shorcut_context()) { + return; + } + if (disable_shortcuts) { return; } @@ -43,9 +47,6 @@ void MenuButton::_unhandled_key_input(Ref p_event) { return; } - //bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); - //if (popup->activate_item_by_event(p_event, global_only)) - // accept_event(); if (popup->activate_item_by_event(p_event, false)) { accept_event(); } @@ -100,7 +101,6 @@ void MenuButton::_notification(int p_what) { void MenuButton::_bind_methods() { ClassDB::bind_method(D_METHOD("get_popup"), &MenuButton::get_popup); - ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input); ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items); ClassDB::bind_method(D_METHOD("_get_items"), &MenuButton::_get_items); ClassDB::bind_method(D_METHOD("set_switch_on_hover", "enable"), &MenuButton::set_switch_on_hover); @@ -123,6 +123,7 @@ MenuButton::MenuButton() { set_toggle_mode(true); set_disable_shortcuts(false); set_process_unhandled_key_input(true); + set_enabled_focus_mode(FOCUS_NONE); set_action_mode(ACTION_MODE_BUTTON_PRESS); popup = memnew(PopupMenu); diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 6330899ad37..65b46d5b697 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -42,7 +42,6 @@ class MenuButton : public Button { bool disable_shortcuts; PopupMenu *popup; - void _unhandled_key_input(Ref p_event); Array _get_items() const; void _set_items(const Array &p_items); @@ -51,6 +50,7 @@ class MenuButton : public Button { protected: void _notification(int p_what); static void _bind_methods(); + virtual void _unhandled_key_input(Ref p_event) override; public: virtual void pressed() override; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index f4498507f17..e770dd22e95 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1804,15 +1804,7 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che void Viewport::_gui_input_event(Ref p_event) { ERR_FAIL_COND(p_event.is_null()); - //? - /* - if (!is_visible()) { - return; //simple and plain - } - */ - Ref mb = p_event; - if (mb.is_valid()) { gui.key_event_accepted = false; @@ -2000,7 +1992,6 @@ void Viewport::_gui_input_event(Ref p_event) { } Ref mm = p_event; - if (mm.is_valid()) { gui.key_event_accepted = false; Point2 mpos = mm->get_position(); @@ -3043,7 +3034,10 @@ void Viewport::unhandled_input(const Ref &p_event, bool p_local_coor ev = p_event; } + // Unhandled Input get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", ev, this); + + // Unhandled key Input - used for performance reasons - This is called a lot less then _unhandled_input since it ignores MouseMotion, etc if (!is_input_handled() && Object::cast_to(*ev) != nullptr) { get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", ev, this); }