diff --git a/doc/classes/TabBar.xml b/doc/classes/TabBar.xml index 19e2e9e3b72..9e09a593ae1 100644 --- a/doc/classes/TabBar.xml +++ b/doc/classes/TabBar.xml @@ -336,7 +336,7 @@ - Emitted when a tab is right-clicked. [member select_with_rmb] must be enabled. + Emitted when a tab is right-clicked. diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cpp index f10e49bf6c2..5c99e8fb615 100644 --- a/editor/docks/editor_dock_manager.cpp +++ b/editor/docks/editor_dock_manager.cpp @@ -289,25 +289,16 @@ void EditorDockManager::_dock_split_dragged(int p_offset) { EditorNode::get_singleton()->save_editor_layout_delayed(); } -void EditorDockManager::_dock_container_gui_input(const Ref &p_input, TabContainer *p_dock_container) { - Ref mb = p_input; - - if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { - int tab_id = p_dock_container->get_tab_bar()->get_hovered_tab(); - if (tab_id < 0) { - return; - } - - EditorDock *hovered_dock = Object::cast_to(p_dock_container->get_tab_control(tab_id)); - if (hovered_dock == nullptr) { - return; - } - - // Right click context menu. - dock_context_popup->set_dock(hovered_dock); - dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + mb->get_position()); - dock_context_popup->popup(); +void EditorDockManager::_dock_container_popup(int p_tab_idx, TabContainer *p_dock_container) { + EditorDock *hovered_dock = Object::cast_to(p_dock_container->get_tab_control(p_tab_idx)); + if (hovered_dock == nullptr) { + return; } + + // Right click context menu. + dock_context_popup->set_dock(hovered_dock); + dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + p_dock_container->get_local_mouse_position()); + dock_context_popup->popup(); } void EditorDockManager::_dock_container_update_visibility(TabContainer *p_dock_container) { @@ -981,13 +972,13 @@ void EditorDockManager::register_dock_slot(DockSlot p_dock_slot, TabContainer *p p_tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); p_tab_container->set_popup(dock_context_popup); p_tab_container->connect("pre_popup_pressed", callable_mp(dock_context_popup, &DockContextPopup::select_current_dock_in_dock_slot).bind(p_dock_slot)); + p_tab_container->get_tab_bar()->connect("tab_rmb_clicked", callable_mp(this, &EditorDockManager::_dock_container_popup).bind(p_tab_container)); p_tab_container->set_drag_to_rearrange_enabled(true); p_tab_container->set_tabs_rearrange_group(1); p_tab_container->connect("tab_changed", callable_mp(this, &EditorDockManager::_update_layout).unbind(1)); p_tab_container->connect("active_tab_rearranged", callable_mp(this, &EditorDockManager::_update_layout).unbind(1)); p_tab_container->connect("child_order_changed", callable_mp(this, &EditorDockManager::_dock_container_update_visibility).bind(p_tab_container)); p_tab_container->set_use_hidden_tabs_for_min_size(true); - p_tab_container->get_tab_bar()->connect(SceneStringName(gui_input), callable_mp(this, &EditorDockManager::_dock_container_gui_input).bind(p_tab_container)); p_tab_container->hide(); // Create dock dragging hint. diff --git a/editor/docks/editor_dock_manager.h b/editor/docks/editor_dock_manager.h index 2a73b43d147..e426a64e61e 100644 --- a/editor/docks/editor_dock_manager.h +++ b/editor/docks/editor_dock_manager.h @@ -106,7 +106,7 @@ private: EditorDock *_get_dock_tab_dragged(); void _dock_drag_stopped(); void _dock_split_dragged(int p_offset); - void _dock_container_gui_input(const Ref &p_input, TabContainer *p_dock_container); + void _dock_container_popup(int p_tab_idx, TabContainer *p_dock_container); void _dock_container_update_visibility(TabContainer *p_dock_container); void _update_layout(); diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index 34cf31a30b8..36d59b7af75 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -238,7 +238,7 @@ void EditorBottomPanel::_on_button_visibility_changed(Button *p_button, Control } EditorBottomPanel::EditorBottomPanel() { - get_tab_bar()->connect(SceneStringName(gui_input), callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::_dock_container_gui_input).bind(this)); + get_tab_bar()->connect("tab_rmb_clicked", callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::_dock_container_popup).bind(this)); get_tab_bar()->connect("tab_changed", callable_mp(this, &EditorBottomPanel::_on_tab_changed)); set_tabs_position(TabPosition::POSITION_BOTTOM); set_deselect_enabled(true); diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 36bb60b2db5..34ff8aa40f2 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -223,10 +223,11 @@ void TabBar::gui_input(const Ref &p_event) { } } - if (mb->is_pressed() && (mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT))) { + if (mb->is_pressed()) { Point2 pos = mb->get_position(); + bool selecting = mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT); - if (buttons_visible) { + if (buttons_visible && selecting) { if (is_layout_rtl()) { if (pos.x < theme_cache.decrement_icon->get_width()) { if (missing_right) { @@ -268,47 +269,43 @@ void TabBar::gui_input(const Ref &p_event) { return; } - int found = -1; - for (int i = offset; i <= max_drawn_tab; i++) { - if (tabs[i].hidden) { - continue; - } - - if (tabs[i].rb_rect.has_point(pos)) { - rb_pressing = true; - _update_hover(); - queue_redraw(); - return; - } - - if (tabs[i].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current))) { - cb_pressing = true; - _update_hover(); - queue_redraw(); - return; - } - - if (pos.x >= get_tab_rect(i).position.x && pos.x < get_tab_rect(i).position.x + tabs[i].size_cache) { - if (!tabs[i].disabled) { - found = i; - } - break; - } - } - + int found = get_tab_idx_at_point(pos); if (found != -1) { - if (deselect_enabled && get_current_tab() == found) { - set_current_tab(-1); - } else { - set_current_tab(found); + // Clicking right button icon. + if (tabs[found].rb_rect.has_point(pos)) { + if (selecting) { + rb_pressing = true; + _update_hover(); + queue_redraw(); + } + return; } + // Clicking close button. + if (tabs[found].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && found == current))) { + if (selecting) { + cb_pressing = true; + _update_hover(); + queue_redraw(); + } + return; + } + + // Selecting a tab. + if (selecting) { + if (deselect_enabled && get_current_tab() == found) { + set_current_tab(-1); + } else { + set_current_tab(found); + } + + emit_signal(SNAME("tab_clicked"), found); + } + + // Right mouse button clicked on a tab. if (mb->get_button_index() == MouseButton::RIGHT) { - // Right mouse button clicked. emit_signal(SNAME("tab_rmb_clicked"), found); } - - emit_signal(SNAME("tab_clicked"), found); } } }