Skip to content

Commit e50cf88

Browse files
committed
Allow tab_rmb_clicked signal to always be emitted
1 parent 6fd949a commit e50cf88

File tree

5 files changed

+40
-52
lines changed

5 files changed

+40
-52
lines changed

doc/classes/TabBar.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
<signal name="tab_rmb_clicked">
337337
<param index="0" name="tab" type="int" />
338338
<description>
339-
Emitted when a tab is right-clicked. [member select_with_rmb] must be enabled.
339+
Emitted when a tab is right-clicked.
340340
</description>
341341
</signal>
342342
<signal name="tab_selected">

editor/docks/editor_dock_manager.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,16 @@ void EditorDockManager::_dock_split_dragged(int p_offset) {
289289
EditorNode::get_singleton()->save_editor_layout_delayed();
290290
}
291291

292-
void EditorDockManager::_dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container) {
293-
Ref<InputEventMouseButton> mb = p_input;
294-
295-
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
296-
int tab_id = p_dock_container->get_tab_bar()->get_hovered_tab();
297-
if (tab_id < 0) {
298-
return;
299-
}
300-
301-
EditorDock *hovered_dock = Object::cast_to<EditorDock>(p_dock_container->get_tab_control(tab_id));
302-
if (hovered_dock == nullptr) {
303-
return;
304-
}
305-
306-
// Right click context menu.
307-
dock_context_popup->set_dock(hovered_dock);
308-
dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + mb->get_position());
309-
dock_context_popup->popup();
292+
void EditorDockManager::_dock_container_popup(int p_tab_idx, TabContainer *p_dock_container) {
293+
EditorDock *hovered_dock = Object::cast_to<EditorDock>(p_dock_container->get_tab_control(p_tab_idx));
294+
if (hovered_dock == nullptr) {
295+
return;
310296
}
297+
298+
// Right click context menu.
299+
dock_context_popup->set_dock(hovered_dock);
300+
dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + p_dock_container->get_local_mouse_position());
301+
dock_context_popup->popup();
311302
}
312303

313304
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
981972
p_tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
982973
p_tab_container->set_popup(dock_context_popup);
983974
p_tab_container->connect("pre_popup_pressed", callable_mp(dock_context_popup, &DockContextPopup::select_current_dock_in_dock_slot).bind(p_dock_slot));
975+
p_tab_container->get_tab_bar()->connect("tab_rmb_clicked", callable_mp(this, &EditorDockManager::_dock_container_popup).bind(p_tab_container));
984976
p_tab_container->set_drag_to_rearrange_enabled(true);
985977
p_tab_container->set_tabs_rearrange_group(1);
986978
p_tab_container->connect("tab_changed", callable_mp(this, &EditorDockManager::_update_layout).unbind(1));
987979
p_tab_container->connect("active_tab_rearranged", callable_mp(this, &EditorDockManager::_update_layout).unbind(1));
988980
p_tab_container->connect("child_order_changed", callable_mp(this, &EditorDockManager::_dock_container_update_visibility).bind(p_tab_container));
989981
p_tab_container->set_use_hidden_tabs_for_min_size(true);
990-
p_tab_container->get_tab_bar()->connect(SceneStringName(gui_input), callable_mp(this, &EditorDockManager::_dock_container_gui_input).bind(p_tab_container));
991982
p_tab_container->hide();
992983

993984
// Create dock dragging hint.

editor/docks/editor_dock_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class EditorDockManager : public Object {
106106
EditorDock *_get_dock_tab_dragged();
107107
void _dock_drag_stopped();
108108
void _dock_split_dragged(int p_offset);
109-
void _dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container);
109+
void _dock_container_popup(int p_tab_idx, TabContainer *p_dock_container);
110110
void _dock_container_update_visibility(TabContainer *p_dock_container);
111111
void _update_layout();
112112

editor/gui/editor_bottom_panel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void EditorBottomPanel::_on_button_visibility_changed(Button *p_button, Control
199199
}
200200

201201
EditorBottomPanel::EditorBottomPanel() {
202-
get_tab_bar()->connect(SceneStringName(gui_input), callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::_dock_container_gui_input).bind(this));
202+
get_tab_bar()->connect("tab_rmb_clicked", callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::_dock_container_popup).bind(this));
203203
get_tab_bar()->connect("tab_changed", callable_mp(this, &EditorBottomPanel::_on_tab_changed));
204204
set_tabs_position(TabPosition::POSITION_BOTTOM);
205205
set_deselect_enabled(true);

scene/gui/tab_bar.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
223223
}
224224
}
225225

226-
if (mb->is_pressed() && (mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT))) {
226+
if (mb->is_pressed()) {
227227
Point2 pos = mb->get_position();
228+
bool selecting = mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT);
228229

229-
if (buttons_visible) {
230+
if (buttons_visible && selecting) {
230231
if (is_layout_rtl()) {
231232
if (pos.x < theme_cache.decrement_icon->get_width()) {
232233
if (missing_right) {
@@ -268,47 +269,43 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
268269
return;
269270
}
270271

271-
int found = -1;
272-
for (int i = offset; i <= max_drawn_tab; i++) {
273-
if (tabs[i].hidden) {
274-
continue;
275-
}
276-
277-
if (tabs[i].rb_rect.has_point(pos)) {
278-
rb_pressing = true;
279-
_update_hover();
280-
queue_redraw();
272+
int found = get_tab_idx_at_point(pos);
273+
if (found != -1) {
274+
// Clicking right button icon.
275+
if (tabs[found].rb_rect.has_point(pos)) {
276+
if (selecting) {
277+
rb_pressing = true;
278+
_update_hover();
279+
queue_redraw();
280+
}
281281
return;
282282
}
283283

284-
if (tabs[i].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current))) {
285-
cb_pressing = true;
286-
_update_hover();
287-
queue_redraw();
284+
// Clicking close button.
285+
if (tabs[found].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && found == current))) {
286+
if (selecting) {
287+
cb_pressing = true;
288+
_update_hover();
289+
queue_redraw();
290+
}
288291
return;
289292
}
290293

291-
if (pos.x >= get_tab_rect(i).position.x && pos.x < get_tab_rect(i).position.x + tabs[i].size_cache) {
292-
if (!tabs[i].disabled) {
293-
found = i;
294+
// Selecting a tab.
295+
if (selecting) {
296+
if (deselect_enabled && get_current_tab() == found) {
297+
set_current_tab(-1);
298+
} else {
299+
set_current_tab(found);
294300
}
295-
break;
296-
}
297-
}
298301

299-
if (found != -1) {
300-
if (deselect_enabled && get_current_tab() == found) {
301-
set_current_tab(-1);
302-
} else {
303-
set_current_tab(found);
302+
emit_signal(SNAME("tab_clicked"), found);
304303
}
305304

305+
// Right mouse button clicked on a tab.
306306
if (mb->get_button_index() == MouseButton::RIGHT) {
307-
// Right mouse button clicked.
308307
emit_signal(SNAME("tab_rmb_clicked"), found);
309308
}
310-
311-
emit_signal(SNAME("tab_clicked"), found);
312309
}
313310
}
314311
}

0 commit comments

Comments
 (0)