Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hotkeys to switch between tabs #1109

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 2 additions & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
29 changes: 29 additions & 0 deletions src/UI/Tabs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down