Skip to content

Commit

Permalink
Add a disabled line edit in keyboard shortcut selector to grab focus,…
Browse files Browse the repository at this point in the history
… fixes the first part of #5
  • Loading branch information
OverloadedOrama committed May 12, 2022
1 parent 5c02c02 commit 461dc83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
24 changes: 20 additions & 4 deletions addons/keychain/ShortcutSelectorDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ var listened_input: InputEvent

onready var root: Node = get_parent()
onready var input_type_l: Label = $VBoxContainer/InputTypeLabel
onready var entered_shortcut: Label = $VBoxContainer/EnteredShortcutLabel
onready var entered_shortcut: LineEdit = $VBoxContainer/EnteredShortcut
onready var option_button: OptionButton = $VBoxContainer/OptionButton
onready var already_exists: Label = $VBoxContainer/AlreadyExistsLabel


func _ready() -> void:
set_process_input(false)
get_ok().focus_mode = Control.FOCUS_NONE
get_cancel().focus_mode = Control.FOCUS_NONE
if input_type == InputTypes.KEYBOARD:
get_ok().focus_neighbour_top = entered_shortcut.get_path()
get_cancel().focus_neighbour_top = entered_shortcut.get_path()
entered_shortcut.focus_neighbour_bottom = get_ok().get_path()
else:
get_ok().focus_neighbour_top = option_button.get_path()
get_cancel().focus_neighbour_top = option_button.get_path()
option_button.focus_neighbour_bottom = get_ok().get_path()

get_close_button().focus_mode = Control.FOCUS_NONE


Expand Down Expand Up @@ -148,7 +155,8 @@ func _on_ShortcutSelectorDialog_about_to_show() -> void:
listened_input = null
already_exists.text = ""
entered_shortcut.text = ""
set_process_input(true)
yield(get_tree(), "idle_frame")
entered_shortcut.grab_focus()
else:
if !listened_input:
_on_OptionButton_item_selected(0)
Expand All @@ -172,3 +180,11 @@ func _on_OptionButton_item_selected(index: int) -> void:
listened_input.axis = index / 2
listened_input.axis_value = -1.0 if index % 2 == 0 else 1.0
_show_assigned_state(listened_input)


func _on_EnteredShortcut_focus_entered() -> void:
set_process_input(true)


func _on_EnteredShortcut_focus_exited() -> void:
set_process_input(false)
14 changes: 9 additions & 5 deletions addons/keychain/ShortcutSelectorDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ margin_right = 333.0
margin_bottom = 14.0
text = "Press a key or a key combination to set the shortcut"

[node name="EnteredShortcutLabel" type="Label" parent="VBoxContainer"]
[node name="EnteredShortcut" type="LineEdit" parent="VBoxContainer"]
visible = false
margin_top = 18.0
margin_right = 333.0
margin_bottom = 32.0
align = 1
editable = false
virtual_keyboard_enabled = false

[node name="OptionButton" type="OptionButton" parent="VBoxContainer"]
margin_top = 36.0
margin_top = 18.0
margin_right = 333.0
margin_bottom = 56.0
margin_bottom = 38.0
mouse_default_cursor_shape = 2

[node name="AlreadyExistsLabel" type="Label" parent="VBoxContainer"]
margin_top = 60.0
margin_top = 42.0
margin_right = 333.0
margin_bottom = 74.0
margin_bottom = 56.0
align = 1

[connection signal="about_to_show" from="." to="." method="_on_ShortcutSelectorDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_ShortcutSelectorDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_ShortcutSelectorDialog_popup_hide"]
[connection signal="focus_entered" from="VBoxContainer/EnteredShortcut" to="." method="_on_EnteredShortcut_focus_entered"]
[connection signal="focus_exited" from="VBoxContainer/EnteredShortcut" to="." method="_on_EnteredShortcut_focus_exited"]
[connection signal="item_selected" from="VBoxContainer/OptionButton" to="." method="_on_OptionButton_item_selected"]

0 comments on commit 461dc83

Please sign in to comment.