Browse Source

Merge pull request #107440 from lodetrick/tabcontainer-popup

Allow `tab_rmb_clicked` to always work
Thaddeus Crews 1 month ago
parent
commit
b52e3f7e6b

+ 1 - 1
doc/classes/TabBar.xml

@@ -336,7 +336,7 @@
 		<signal name="tab_rmb_clicked">
 		<signal name="tab_rmb_clicked">
 			<param index="0" name="tab" type="int" />
 			<param index="0" name="tab" type="int" />
 			<description>
 			<description>
-				Emitted when a tab is right-clicked. [member select_with_rmb] must be enabled.
+				Emitted when a tab is right-clicked.
 			</description>
 			</description>
 		</signal>
 		</signal>
 		<signal name="tab_selected">
 		<signal name="tab_selected">

+ 10 - 19
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();
 	EditorNode::get_singleton()->save_editor_layout_delayed();
 }
 }
 
 
-void EditorDockManager::_dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container) {
-	Ref<InputEventMouseButton> 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<EditorDock>(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<EditorDock>(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) {
 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_v_size_flags(Control::SIZE_EXPAND_FILL);
 	p_tab_container->set_popup(dock_context_popup);
 	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->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_drag_to_rearrange_enabled(true);
 	p_tab_container->set_tabs_rearrange_group(1);
 	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("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("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->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->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();
 	p_tab_container->hide();
 
 
 	// Create dock dragging hint.
 	// Create dock dragging hint.

+ 1 - 1
editor/docks/editor_dock_manager.h

@@ -106,7 +106,7 @@ private:
 	EditorDock *_get_dock_tab_dragged();
 	EditorDock *_get_dock_tab_dragged();
 	void _dock_drag_stopped();
 	void _dock_drag_stopped();
 	void _dock_split_dragged(int p_offset);
 	void _dock_split_dragged(int p_offset);
-	void _dock_container_gui_input(const Ref<InputEvent> &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 _dock_container_update_visibility(TabContainer *p_dock_container);
 	void _update_layout();
 	void _update_layout();
 
 

+ 1 - 1
editor/gui/editor_bottom_panel.cpp

@@ -238,7 +238,7 @@ void EditorBottomPanel::_on_button_visibility_changed(Button *p_button, Control
 }
 }
 
 
 EditorBottomPanel::EditorBottomPanel() {
 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));
 	get_tab_bar()->connect("tab_changed", callable_mp(this, &EditorBottomPanel::_on_tab_changed));
 	set_tabs_position(TabPosition::POSITION_BOTTOM);
 	set_tabs_position(TabPosition::POSITION_BOTTOM);
 	set_deselect_enabled(true);
 	set_deselect_enabled(true);

+ 27 - 30
scene/gui/tab_bar.cpp

@@ -223,10 +223,11 @@ void TabBar::gui_input(const Ref<InputEvent> &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();
 			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 (is_layout_rtl()) {
 					if (pos.x < theme_cache.decrement_icon->get_width()) {
 					if (pos.x < theme_cache.decrement_icon->get_width()) {
 						if (missing_right) {
 						if (missing_right) {
@@ -268,47 +269,43 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
 				return;
 				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();
+			int found = get_tab_idx_at_point(pos);
+			if (found != -1) {
+				// Clicking right button icon.
+				if (tabs[found].rb_rect.has_point(pos)) {
+					if (selecting) {
+						rb_pressing = true;
+						_update_hover();
+						queue_redraw();
+					}
 					return;
 					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();
+				// 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;
 					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;
+				// Selecting a tab.
+				if (selecting) {
+					if (deselect_enabled && get_current_tab() == found) {
+						set_current_tab(-1);
+					} else {
+						set_current_tab(found);
 					}
 					}
-					break;
-				}
-			}
 
 
-			if (found != -1) {
-				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) {
 				if (mb->get_button_index() == MouseButton::RIGHT) {
-					// Right mouse button clicked.
 					emit_signal(SNAME("tab_rmb_clicked"), found);
 					emit_signal(SNAME("tab_rmb_clicked"), found);
 				}
 				}
-
-				emit_signal(SNAME("tab_clicked"), found);
 			}
 			}
 		}
 		}
 	}
 	}