1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Add hotkeys to switch between tabs (#1109)

* Added hotkey to switch tab

* Linting
This commit is contained in:
Variable 2024-09-29 02:15:37 +05:00 committed by GitHub
parent 597db5d44e
commit 564b199fa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -888,6 +888,16 @@ gaussian_blur={
"deadzone": 0.5,
"events": []
}
next_project={
"deadzone": 0.5,
"events": [null, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
previous_project={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[input_devices]

View file

@ -787,6 +787,8 @@ func _initialize_keychain() -> void:
&"open_editor_data_folder": Keychain.InputAction.new("", "Help menu", true),
&"changelog": Keychain.InputAction.new("", "Help menu", true),
&"about_pixelorama": Keychain.InputAction.new("", "Help menu", true),
&"previous_project": Keychain.InputAction.new("", "Canvas"),
&"next_project": Keychain.InputAction.new("", "Canvas"),
&"zoom_in": Keychain.InputAction.new("", "Canvas"),
&"zoom_out": Keychain.InputAction.new("", "Canvas"),
&"camera_left": Keychain.InputAction.new("", "Canvas"),

View file

@ -4,6 +4,35 @@ extends TabBar
var unsaved_changes_dialog: ConfirmationDialog = Global.control.find_child("UnsavedCanvasDialog")
func _input(_event: InputEvent) -> void:
# NOTE: This feature has an unavoidable bug which sometimes causes the undoredo
# system to fail, because user is trying to draw while switching project simultaneously.
# This is because the current project has changed and the system tries to commit to the
# wrong undoredo.
var tab_idx = current_tab
# If a project is currently worked upon, then don't switch it.
# This doesn't stop the bug completely but significantly reduces it's chances
# of appearing.
if (
Input.is_action_pressed("activate_left_tool")
or Input.is_action_pressed("activate_right_tool")
):
return
# Due to the bug mentioned above, we will use is_action_just_released
# instead of is_action_just_pressed. This won't remove the bug completely
# but will significantly reduce it's chancce of appearing.
if Input.is_action_just_released(&"next_project", true):
tab_idx += 1
if tab_idx >= tab_count:
tab_idx = 0
elif Input.is_action_just_released(&"previous_project", true):
tab_idx = current_tab - 1
if tab_idx < 0:
tab_idx -= 1
if tab_idx != current_tab:
current_tab = tab_idx
## Handles closing tab with middle-click
## Thanks to https://github.com/godotengine/godot/issues/64498#issuecomment-1217992089
func _gui_input(event: InputEvent) -> void: