Commit 6b139387 authored by Jacek Sowiński's avatar Jacek Sowiński

Add new 'reset' action for resetting state

It does 2 things:

1. Clears marked statuses for todo items
2. Resets keystates in all columns
parent ef360c2f
...@@ -93,3 +93,4 @@ L = swap_left ...@@ -93,3 +93,4 @@ L = swap_left
R = swap_right R = swap_right
<Left> = prev_column <Left> = prev_column
<Right> = next_column <Right> = next_column
<Esc> = reset
...@@ -142,6 +142,7 @@ class _Config: ...@@ -142,6 +142,7 @@ class _Config:
'R': 'swap_right', 'R': 'swap_right',
'<Left>': 'prev_column', '<Left>': 'prev_column',
'<Right>': 'next_column', '<Right>': 'next_column',
'<Esc>': 'reset',
}, },
} }
......
...@@ -192,8 +192,6 @@ class UIApplication(CLIApplicationBase): ...@@ -192,8 +192,6 @@ class UIApplication(CLIApplicationBase):
if command.execute() != False: if command.execute() != False:
self._post_execute() self._post_execute()
self._clear_pending_todos()
except TypeError: except TypeError:
# TODO: show error message # TODO: show error message
pass pass
...@@ -201,14 +199,19 @@ class UIApplication(CLIApplicationBase): ...@@ -201,14 +199,19 @@ class UIApplication(CLIApplicationBase):
def _update_all_columns(self): def _update_all_columns(self):
for column, _ in self.columns.contents: for column, _ in self.columns.contents:
column.update() column.update()
column.keystate = None
def _post_execute(self): def _post_execute(self):
# store dirty flag because base _post_execute will reset it after flush # store dirty flag because base _post_execute will reset it after flush
dirty = self.todolist.dirty dirty = self.todolist.dirty
super()._post_execute() super()._post_execute()
if dirty: if dirty or self.pending_todos:
self._update_all_columns() self._reset_state()
def _reset_state(self):
self.pending_todos = []
self._update_all_columns()
def _blur_commandline(self): def _blur_commandline(self):
self.mainwindow.focus_item = 0 self.mainwindow.focus_item = 0
...@@ -278,13 +281,13 @@ class UIApplication(CLIApplicationBase): ...@@ -278,13 +281,13 @@ class UIApplication(CLIApplicationBase):
'copy_column': self._copy_column, 'copy_column': self._copy_column,
'swap_left': self._swap_column_left, 'swap_left': self._swap_column_left,
'swap_right': self._swap_column_right, 'swap_right': self._swap_column_right,
'reset': self._reset_state,
} }
dispatch[p_action]() dispatch[p_action]()
def _handle_input(self, p_input): def _handle_input(self, p_input):
dispatch = { dispatch = {
':': self._focus_commandline, ':': self._focus_commandline,
'esc': self._clear_pending_todos,
} }
try: try:
...@@ -344,7 +347,6 @@ class UIApplication(CLIApplicationBase): ...@@ -344,7 +347,6 @@ class UIApplication(CLIApplicationBase):
urwid.connect_signal(todolist, 'show_keystate', self._print_keystate) urwid.connect_signal(todolist, 'show_keystate', self._print_keystate)
urwid.connect_signal(todolist, 'append_pending_todos', self._pending_todos_handler) urwid.connect_signal(todolist, 'append_pending_todos', self._pending_todos_handler)
urwid.connect_signal(todolist, 'check_pending_todos', self._is_pending) urwid.connect_signal(todolist, 'check_pending_todos', self._is_pending)
urwid.connect_signal(todolist, 'clear_pending_todos', self._clear_pending_todos)
options = self.columns.options( options = self.columns.options(
width_type='given', width_type='given',
...@@ -461,11 +463,6 @@ class UIApplication(CLIApplicationBase): ...@@ -461,11 +463,6 @@ class UIApplication(CLIApplicationBase):
return sz return sz
def _clear_pending_todos(self, p_refresh=True):
self.pending_todos = []
if p_refresh:
self._update_all_columns()
def _is_pending(self): def _is_pending(self):
if len(self.pending_todos) > 0: if len(self.pending_todos) > 0:
return True return True
......
...@@ -64,7 +64,6 @@ class TodoListWidget(urwid.LineBox): ...@@ -64,7 +64,6 @@ class TodoListWidget(urwid.LineBox):
'show_keystate', 'show_keystate',
'append_pending_todos', 'append_pending_todos',
'check_pending_todos', 'check_pending_todos',
'clear_pending_todos',
]) ])
@property @property
...@@ -270,8 +269,8 @@ class TodoListWidget(urwid.LineBox): ...@@ -270,8 +269,8 @@ class TodoListWidget(urwid.LineBox):
Currently supported actions are: 'up', 'down', 'home', 'end', Currently supported actions are: 'up', 'down', 'home', 'end',
'first_column', 'last_column', 'prev_column', 'next_column', 'first_column', 'last_column', 'prev_column', 'next_column',
'append_column', 'insert_column', 'edit_column', 'delete_column', 'append_column', 'insert_column', 'edit_column', 'delete_column',
'copy_column', swap_right', 'swap_left', 'postpone', 'postpone_s', 'pri' 'copy_column', swap_right', 'swap_left', 'postpone', 'postpone_s',
and 'mark'. 'pri', 'mark' and 'reset'.
""" """
column_actions = ['first_column', column_actions = ['first_column',
'last_column', 'last_column',
...@@ -284,6 +283,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -284,6 +283,7 @@ class TodoListWidget(urwid.LineBox):
'copy_column', 'copy_column',
'swap_left', 'swap_left',
'swap_right', 'swap_right',
'reset',
] ]
if p_action_str in column_actions: if p_action_str in column_actions:
......
Markdown is supported
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