Add global signal-catching for better handling of cases where focus is lost.

This commit is contained in:
Nolan Darilek 2019-10-03 09:34:22 -05:00
parent 0e8b6ae9e8
commit 0783dfb548
2 changed files with 33 additions and 8 deletions

View File

@ -171,9 +171,6 @@ func menu_button_focus():
tokens.append("menu")
TTS.speak(tokens.join(": "), false)
func panel_focus():
TTS.speak("panel", true)
func popup_menu_focus():
TTS.speak("menu", false)
@ -384,8 +381,6 @@ func focus():
label_focus()
elif node is LineEdit:
line_edit_focus()
elif node is Panel:
panel_focus()
elif node is PopupMenu:
popup_menu_focus()
elif node is TabContainer:
@ -411,6 +406,7 @@ func unfocus():
func click_focus():
if node.has_focus():
return
if node.focus_mode == Control.FOCUS_ALL:
print("Grabbing focus: %s" % node)
node.grab_focus()
@ -464,6 +460,8 @@ func is_focusable(node):
return false
if node.get_class() == "CollisionShape2DEditor":
return false
if node is Panel:
return false
if node is TabContainer:
return true
if node.get_class() == "EditorInspectorSection":

View File

@ -3,9 +3,34 @@ extends Node
var Accessible = preload("Accessible.gd")
var focus_restore_timer = Timer.new()
func focused(node):
focus_restore_timer.stop()
func click_focused(node):
pass
func restore_focus():
var focus = find_focusable_control(get_tree().root)
if focus:
focus.grab_focus()
focus.grab_click_focus()
func unfocused(node):
focus_restore_timer.start(0.2)
func augment_node(node):
if node is Control:
Accessible.new(node)
if not node.is_connected("focus_entered", self, "focused"):
node.connect("focus_entered", self, "focused", [node])
if not node.is_connected("mouse_entered", self, "click_focused"):
node.connect("mouse_entered", self, "click_focused", [node])
if not node.is_connected("focus_exited", self, "unfocused"):
node.connect("focus_exited", self, "unfocused", [node])
if not node.is_connected("mouse_exited", self, "unfocused"):
node.connect("mouse_exited", self, "unfocused", [node])
func augment_tree(node):
augment_node(node)
@ -34,7 +59,6 @@ func find_focusable_control(node):
return null
func set_initial_scene_focus(scene):
print("Set focus in scene")
self.augment_tree(get_tree().root)
var focus = find_focusable_control(get_tree().root)
if not focus:
@ -43,5 +67,8 @@ func set_initial_scene_focus(scene):
focus.grab_focus()
func _enter_tree():
focus_restore_timer.one_shot = true
focus_restore_timer.connect("timeout", self, "restore_focus")
add_child(focus_restore_timer)
TTS.rate = 255
get_tree().connect("node_added", self, "augment_tree")