From 7bfcabc466788e2c9272e41f41a92332017a4ab4 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Thu, 25 Aug 2022 01:47:05 +0300 Subject: [PATCH] Close project tabs with middle mouse click --- src/UI/Tabs.gd | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/UI/Tabs.gd b/src/UI/Tabs.gd index 013b79a02..ba2dad36a 100644 --- a/src/UI/Tabs.gd +++ b/src/UI/Tabs.gd @@ -5,6 +5,26 @@ onready var unsaved_changes_dialog: ConfirmationDialog = Global.control.find_nod ) +# Thanks to https://github.com/godotengine/godot/issues/64498#issuecomment-1217992089 +func _gui_input(event: InputEvent) -> void: + if not event is InputEventMouseButton: + return + if !event.pressed or event.button_index != BUTTON_MIDDLE: + return + var rect := get_rect() + var w := rect.position.x + var w_limit := rect.size.x + for i in get_tab_count(): + if i < get_tab_offset(): + continue + w += get_tab_rect(i).size.x + if w_limit < w: + return + if get_tab_rect(i).has_point(event.position): + _on_Tabs_tab_close(i) + return + + func _on_Tabs_tab_changed(tab: int) -> void: Global.current_project_index = tab