Commit e784164a authored by Fjen Undso's avatar Fjen Undso
Browse files

gui/focusswitcher: remember last focused element

parent 76c72865
......@@ -6,16 +6,22 @@ class FocusSwitcher(Focusable):
self.elements = elements
self.prev_key = prev_key
self.next_key = next_key
self.last_focused = None
def toggle_focus(self):
if self.focus:
# we lose our focus, unfocus active element
# we lose our focus, unfocus active element and remember it
for e in self.elements:
if e.focus:
self.last_focused = e
e.toggle_focus()
else:
# set focus on first element
self.elements[0].toggle_focus()
if self.last_focused:
# restore focus on last active element
self.last_focused.toggle_focus()
else:
# last focused element undefined
self.elements[0].toggle_focus()
Focusable.toggle_focus(self)
def add(self, element):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment