Merge pull request #63576 from KoBeWi/list_clicker

Simplify script list click logic
This commit is contained in:
Rémi Verschelde 2022-09-21 15:38:41 +02:00
commit 53d2a9acdd
2 changed files with 10 additions and 21 deletions

View file

@ -3059,26 +3059,15 @@ void ScriptEditor::shortcut_input(const Ref<InputEvent> &p_event) {
}
}
void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) {
Ref<InputEventMouseButton> mb = ev;
if (mb.is_valid() && mb->is_pressed()) {
switch (mb->get_button_index()) {
case MouseButton::MIDDLE: {
// Right-click selects automatically; middle-click does not.
int idx = script_list->get_item_at_position(mb->get_position(), true);
if (idx >= 0) {
script_list->select(idx);
_script_selected(idx);
_menu_option(FILE_CLOSE);
}
} break;
void ScriptEditor::_script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index) {
if (p_mouse_button_index == MouseButton::MIDDLE) {
script_list->select(p_item);
_script_selected(p_item);
_menu_option(FILE_CLOSE);
}
case MouseButton::RIGHT: {
_make_script_list_context_menu();
} break;
default:
break;
}
if (p_mouse_button_index == MouseButton::RIGHT) {
_make_script_list_context_menu();
}
}
@ -3688,7 +3677,7 @@ ScriptEditor::ScriptEditor() {
script_list->set_v_size_flags(SIZE_EXPAND_FILL);
script_split->set_split_offset(70 * EDSCALE);
_sort_list_on_update = true;
script_list->connect("gui_input", callable_mp(this, &ScriptEditor::_script_list_gui_input), CONNECT_DEFERRED);
script_list->connect("item_clicked", callable_mp(this, &ScriptEditor::_script_list_clicked), CONNECT_DEFERRED);
script_list->set_allow_rmb_select(true);
script_list->set_drag_forwarding(this);

View file

@ -426,7 +426,7 @@ class ScriptEditor : public PanelContainer {
virtual void input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
void _script_list_gui_input(const Ref<InputEvent> &ev);
void _script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
void _make_script_list_context_menu();
void _help_search(String p_text);