Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcuts rework - fixed issues with input propagation and triggering of unwanted shortcuts. #42109

Merged
merged 5 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
30 changes: 12 additions & 18 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,21 +531,15 @@ void EditorAudioBus::_effect_add(int p_which) {
}

void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> 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<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y);
bus_popup->set_position(get_global_position() + pos);
bus_popup->popup();
}
}

void EditorAudioBus::_unhandled_key_input(Ref<InputEvent> p_event) {
void EditorAudioBus::_effects_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_DELETE) {
TreeItem *current_effect = effects->get_selected();
Expand Down Expand Up @@ -749,7 +743,6 @@ void EditorAudioBus::_bind_methods() {
ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input);
ClassDB::bind_method("_unhandled_key_input", &EditorAudioBus::_unhandled_key_input);
ClassDB::bind_method("get_drag_data_fw", &EditorAudioBus::get_drag_data_fw);
ClassDB::bind_method("can_drop_data_fw", &EditorAudioBus::can_drop_data_fw);
ClassDB::bind_method("drop_data_fw", &EditorAudioBus::drop_data_fw);
Expand All @@ -773,7 +766,6 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
add_child(vb);

set_v_size_flags(SIZE_EXPAND_FILL);
set_process_unhandled_key_input(true);

track_name = memnew(LineEdit);
track_name->connect("text_entered", callable_mp(this, &EditorAudioBus::_name_changed));
Expand Down Expand Up @@ -805,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<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
for (int i = 0; i < hbc->get_child_count(); i++) {
Control *child = Object::cast_to<Control>(hbc->get_child(i));
Expand Down Expand Up @@ -906,6 +892,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
effects->set_allow_rmb_select(true);
effects->set_focus_mode(FOCUS_CLICK);
effects->set_allow_reselect(true);
effects->connect("gui_input", callable_mp(this, &EditorAudioBus::_effects_gui_input));

send = memnew(OptionButton);
send->set_clip_text(true);
Expand All @@ -932,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));
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_audio_buses.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class EditorAudioBus : public PanelContainer {
mutable bool hovering_drop;

void _gui_input(const Ref<InputEvent> &p_event);
void _unhandled_key_input(Ref<InputEvent> p_event);
void _effects_gui_input(Ref<InputEvent> p_event);
void _bus_popup_pressed(int p_option);

void _name_changed(const String &p_new_name);
Expand Down
14 changes: 0 additions & 14 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ void EditorHelp::_init_colors() {
class_desc->add_theme_constant_override("line_separation", Math::round(5 * EDSCALE));
}

void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this was removed because the search popup is actually handled through ScriptEditor::_menu_option, via the Search menu button in the script editor. This code would never be hit.

image

if (!is_visible_in_tree()) {
return;
}

Ref<InputEventKey> k = p_ev;

if (k.is_valid() && k->get_control() && k->get_keycode() == KEY_F) {
search->grab_focus();
search->select_all();
}
}

void EditorHelp::_search(bool p_search_previous) {
if (p_search_previous) {
find_bar->search_prev();
Expand Down Expand Up @@ -1598,7 +1585,6 @@ void EditorHelp::set_scroll(int p_scroll) {
void EditorHelp::_bind_methods() {
ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input);
ClassDB::bind_method("_search", &EditorHelp::_search);
ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);

Expand Down
2 changes: 0 additions & 2 deletions editor/editor_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class EditorHelp : public VBoxContainer {
void _request_help(const String &p_string);
void _search(bool p_search_previous = false);

void _unhandled_key_input(const Ref<InputEvent> &p_ev);

String _fix_constant(const String &p_constant) const;

protected:
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions editor/inspector_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,16 +1210,19 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
} else {
_play_bw_pressed();
}
accept_event();
} break;
case KEY_S: {
_stop_pressed();
accept_event();
} break;
case KEY_D: {
if (!k->get_shift()) {
_play_from_pressed();
} else {
_play_pressed();
}
accept_event();
} break;
}
}
Expand Down Expand Up @@ -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"));
Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/asset_library_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void EditorAssetLibrary::_notification(int p_what) {
}
}

void EditorAssetLibrary::_unhandled_input(const Ref<InputEvent> &p_event) {
void EditorAssetLibrary::_unhandled_key_input(const Ref<InputEvent> &p_event) {
const Ref<InputEventKey> key = p_event;

if (key.is_valid() && key->is_pressed()) {
Expand Down Expand Up @@ -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")));
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/asset_library_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class EditorAssetLibrary : public PanelContainer {
protected:
static void _bind_methods();
void _notification(int p_what);
void _unhandled_input(const Ref<InputEvent> &p_event);
void _unhandled_key_input(const Ref<InputEvent> &p_event);

public:
void disable_community_support();
Expand Down
Loading