Skip to content

Commit df6c8ce

Browse files
authored
Merge pull request #221 from endlessm/create-variable-keynav
Improve keyboard accessibility in create_variable_dialog
2 parents 35eaa56 + 703c66d commit df6c8ce

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

addons/block_code/ui/picker/categories/variable_category/create_variable_button.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ signal create_variable(var_name: String, var_type: String)
77

88

99
func _on_create_button_pressed():
10-
_create_variable_dialog.visible = true
10+
_create_variable_dialog.popup()
1111

1212

1313
func _on_create_variable_dialog_create_variable(var_name, var_type):

addons/block_code/ui/picker/categories/variable_category/create_variable_dialog.gd

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ const available_types = ["STRING", "BOOL", "INT", "FLOAT", "VECTOR2", "COLOR"]
1414

1515
func _ready():
1616
_type_option.clear()
17+
_type_option.focus_next = get_cancel_button().get_path()
18+
get_cancel_button().focus_previous = _type_option.get_path()
19+
get_ok_button().focus_next = _variable_input.get_path()
20+
_variable_input.focus_previous = get_ok_button().get_path()
1721

1822
for type in available_types:
1923
_type_option.add_item(type)
2024

21-
check_errors(_variable_input.text)
25+
_clear()
2226

2327

2428
func _clear():
2529
_variable_input.text = ""
26-
check_errors(_variable_input.text)
30+
get_ok_button().disabled = check_errors(_variable_input.text)
2731
_type_option.select(0)
2832

2933

@@ -93,10 +97,25 @@ func check_errors(new_var_name: String) -> bool:
9397

9498

9599
func _on_confirmed():
96-
if not check_errors(_variable_input.text):
97-
create_variable.emit(_variable_input.text, _type_option.get_item_text(_type_option.selected))
100+
if check_errors(_variable_input.text):
101+
return
102+
103+
create_variable.emit(_variable_input.text, _type_option.get_item_text(_type_option.selected))
104+
hide()
98105
_clear()
99106

100107

101108
func _on_canceled():
102109
_clear()
110+
111+
112+
func _on_about_to_popup() -> void:
113+
_variable_input.grab_focus()
114+
115+
116+
func _on_focus_entered() -> void:
117+
_variable_input.grab_focus()
118+
119+
120+
func _on_variable_input_text_submitted(new_text: String) -> void:
121+
_on_confirmed()

addons/block_code/ui/picker/categories/variable_category/create_variable_dialog.tscn

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ initial_position = 1
88
size = Vector2i(300, 183)
99
visible = true
1010
ok_button_text = "Create"
11+
dialog_hide_on_ok = false
1112
script = ExtResource("1_b52me")
1213

1314
[node name="VBoxContainer" type="VBoxContainer" parent="."]
@@ -27,6 +28,8 @@ text = "Name "
2728
[node name="VariableInput" type="LineEdit" parent="VBoxContainer/GridContainer"]
2829
unique_name_in_owner = true
2930
layout_mode = 2
31+
focus_neighbor_bottom = NodePath("../TypeOption")
32+
focus_next = NodePath("../TypeOption")
3033

3134
[node name="Label2" type="Label" parent="VBoxContainer/GridContainer"]
3235
layout_mode = 2
@@ -36,10 +39,11 @@ text = "Type "
3639
unique_name_in_owner = true
3740
layout_mode = 2
3841
size_flags_horizontal = 3
39-
item_count = 6
42+
focus_neighbor_top = NodePath("../VariableInput")
43+
focus_previous = NodePath("../VariableInput")
4044
selected = 0
45+
item_count = 6
4146
popup/item_0/text = "STRING"
42-
popup/item_0/id = 0
4347
popup/item_1/text = "BOOL"
4448
popup/item_1/id = 1
4549
popup/item_2/text = "INT"
@@ -63,6 +67,9 @@ layout_mode = 2
6367
theme_override_constants/line_separation = 4
6468
fit_content = true
6569

70+
[connection signal="about_to_popup" from="." to="." method="_on_about_to_popup"]
6671
[connection signal="canceled" from="." to="." method="_on_canceled"]
6772
[connection signal="confirmed" from="." to="." method="_on_confirmed"]
73+
[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
6874
[connection signal="text_changed" from="VBoxContainer/GridContainer/VariableInput" to="." method="_on_variable_input_text_changed"]
75+
[connection signal="text_submitted" from="VBoxContainer/GridContainer/VariableInput" to="." method="_on_variable_input_text_submitted"]

0 commit comments

Comments
 (0)