Commit 1e2f92a8 authored by Jacek Sowiński's avatar Jacek Sowiński

Add 'repeat' action

Repeats last topydo command called from within `TodoListWidget.keypress`
(won't repeat commands called from cli).

Default mapping: '.'
parent 6b139387
...@@ -126,6 +126,7 @@ class _Config: ...@@ -126,6 +126,7 @@ class _Config:
'u': 'cmd revert', 'u': 'cmd revert',
'x': 'cmd do {}', 'x': 'cmd do {}',
'm': 'mark', 'm': 'mark',
'.': 'repeat',
'pp': 'postpone', 'pp': 'postpone',
'ps': 'postpone_s', 'ps': 'postpone_s',
'pr': 'pri', 'pr': 'pri',
......
...@@ -108,6 +108,8 @@ class UIApplication(CLIApplicationBase): ...@@ -108,6 +108,8 @@ class UIApplication(CLIApplicationBase):
self.keymap = config().column_keymap() self.keymap = config().column_keymap()
self._alarm = None self._alarm = None
self._last_cmd = None
# console widget # console widget
self.console = ConsoleWidget() self.console = ConsoleWidget()
get_terminal_size(self._console_width) get_terminal_size(self._console_width)
...@@ -209,6 +211,30 @@ class UIApplication(CLIApplicationBase): ...@@ -209,6 +211,30 @@ class UIApplication(CLIApplicationBase):
if dirty or self.pending_todos: if dirty or self.pending_todos:
self._reset_state() self._reset_state()
def _save_cmd(self, p_cmd, p_execute_signal):
verbosity = False
if p_execute_signal == 'execute_command':
verbosity = True
self._last_cmd = (p_cmd, verbosity)
def _repeat_last_cmd(self, p_todo_id=None):
try:
cmd, verbosity = self._last_cmd
except TypeError:
return
if verbosity:
output = self._output
else:
output = lambda _: None
if '{}' in cmd:
if not p_todo_id:
p_todo_id = ' '.join(self.pending_todos)
cmd = cmd.format(p_todo_id)
self._execute_handler(cmd, output)
def _reset_state(self): def _reset_state(self):
self.pending_todos = [] self.pending_todos = []
self._update_all_columns() self._update_all_columns()
...@@ -340,6 +366,8 @@ class UIApplication(CLIApplicationBase): ...@@ -340,6 +366,8 @@ class UIApplication(CLIApplicationBase):
urwid.connect_signal(todolist, 'execute_command_silent', urwid.connect_signal(todolist, 'execute_command_silent',
lambda cmd: self._execute_handler(cmd, no_output)) lambda cmd: self._execute_handler(cmd, no_output))
urwid.connect_signal(todolist, 'execute_command', self._execute_handler) urwid.connect_signal(todolist, 'execute_command', self._execute_handler)
urwid.connect_signal(todolist, 'save_cmd', self._save_cmd)
urwid.connect_signal(todolist, 'repeat_cmd', self._repeat_last_cmd)
urwid.connect_signal(todolist, 'refresh', self.mainloop.screen.clear) urwid.connect_signal(todolist, 'refresh', self.mainloop.screen.clear)
urwid.connect_signal(todolist, 'add_pending_action', self._set_alarm) urwid.connect_signal(todolist, 'add_pending_action', self._set_alarm)
urwid.connect_signal(todolist, 'remove_pending_action', self._remove_alarm) urwid.connect_signal(todolist, 'remove_pending_action', self._remove_alarm)
......
...@@ -60,6 +60,8 @@ class TodoListWidget(urwid.LineBox): ...@@ -60,6 +60,8 @@ class TodoListWidget(urwid.LineBox):
'refresh', 'refresh',
'add_pending_action', 'add_pending_action',
'remove_pending_action', 'remove_pending_action',
'save_cmd',
'repeat_cmd',
'column_action', 'column_action',
'show_keystate', 'show_keystate',
'append_pending_todos', 'append_pending_todos',
...@@ -259,6 +261,8 @@ class TodoListWidget(urwid.LineBox): ...@@ -259,6 +261,8 @@ class TodoListWidget(urwid.LineBox):
self._execute_on_selected(cmd, execute_signal) self._execute_on_selected(cmd, execute_signal)
else: else:
urwid.emit_signal(self, execute_signal, cmd) urwid.emit_signal(self, execute_signal, cmd)
urwid.emit_signal(self, 'save_cmd', cmd, execute_signal)
else: else:
self.execute_builtin_action(p_action_str, p_size) self.execute_builtin_action(p_action_str, p_size)
...@@ -270,7 +274,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -270,7 +274,7 @@ class TodoListWidget(urwid.LineBox):
'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', 'copy_column', swap_right', 'swap_left', 'postpone', 'postpone_s',
'pri', 'mark' and 'reset'. 'pri', 'mark', 'reset' and 'repeat'.
""" """
column_actions = ['first_column', column_actions = ['first_column',
'last_column', 'last_column',
...@@ -300,6 +304,8 @@ class TodoListWidget(urwid.LineBox): ...@@ -300,6 +304,8 @@ class TodoListWidget(urwid.LineBox):
pass pass
elif p_action_str == 'mark': elif p_action_str == 'mark':
self._append_pending_todos() self._append_pending_todos()
elif p_action_str == 'repeat':
self._repeat_cmd()
def _add_pending_action(self, p_action, p_size): def _add_pending_action(self, p_action, p_size):
""" """
...@@ -350,3 +356,15 @@ class TodoListWidget(urwid.LineBox): ...@@ -350,3 +356,15 @@ class TodoListWidget(urwid.LineBox):
self._pp_offset = None self._pp_offset = None
result = False result = False
return result return result
def _repeat_cmd(self):
try:
todo = self.listbox.focus.todo
todo_id = str(self.view.todolist.number(todo))
except AttributeError:
todo_id = None
result = urwid.emit_signal(self, 'check_pending_todos')
if result:
todo_id = None
urwid.emit_signal(self, 'repeat_cmd', todo_id)
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