Commit 06563a35 authored by Jacek Sowiński's avatar Jacek Sowiński

Remove 'save_cmd' and 'has_marked_todos' signals

This required to slightly change UIApplication._execute_handler so it
accepts now also a todo id as an argument.
parent 82c958cb
...@@ -169,14 +169,19 @@ class UIApplication(CLIApplicationBase): ...@@ -169,14 +169,19 @@ class UIApplication(CLIApplicationBase):
def _output(self, p_text): def _output(self, p_text):
self._print_to_console(p_text + "\n") self._print_to_console(p_text + "\n")
def _execute_handler(self, p_command, p_output=None): def _execute_handler(self, p_command, p_todo_id=None, p_output=None):
""" """
Executes a command, given as a string. Executes a command, given as a string.
""" """
if '{}' in p_command:
todos = ' '.join(self.marked_todos)
p_command = p_command.format(todos)
p_output = p_output or self._output p_output = p_output or self._output
self._last_cmd = (p_command, p_output == self._output)
if '{}' in p_command:
if self._has_marked_todos():
p_todo_id = ' '.join(self.marked_todos)
p_command = p_command.format(p_todo_id)
p_command = shlex.split(p_command) p_command = shlex.split(p_command)
(subcommand, args) = get_subcommand(p_command) (subcommand, args) = get_subcommand(p_command)
...@@ -211,29 +216,14 @@ class UIApplication(CLIApplicationBase): ...@@ -211,29 +216,14 @@ class UIApplication(CLIApplicationBase):
if dirty or self.marked_todos: if dirty or self.marked_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): def _repeat_last_cmd(self, p_todo_id=None):
try: try:
cmd, verbosity = self._last_cmd cmd, verbosity = self._last_cmd
except TypeError: except TypeError:
return return
if verbosity: self._execute_handler(cmd, p_todo_id,
output = self._output self._output if verbosity else lambda _: None)
else:
output = lambda _: None
if '{}' in cmd:
if not p_todo_id:
p_todo_id = ' '.join(self.marked_todos)
cmd = cmd.format(p_todo_id)
self._execute_handler(cmd, output)
def _reset_state(self): def _reset_state(self):
self.marked_todos = [] self.marked_todos = []
...@@ -360,13 +350,13 @@ class UIApplication(CLIApplicationBase): ...@@ -360,13 +350,13 @@ class UIApplication(CLIApplicationBase):
When no position is given, it is added to the end, otherwise inserted When no position is given, it is added to the end, otherwise inserted
before that position. before that position.
""" """
def execute_silent(p_cmd, p_todo_id=None):
self._execute_handler(p_cmd, p_todo_id, lambda _: None)
todolist = TodoListWidget(p_view, p_view.data['title'], self.keymap) todolist = TodoListWidget(p_view, p_view.data['title'], self.keymap)
no_output = lambda _: None
urwid.connect_signal(todolist, 'execute_command_silent', urwid.connect_signal(todolist, 'execute_command_silent',
lambda cmd: self._execute_handler(cmd, no_output)) execute_silent)
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, '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)
...@@ -375,8 +365,6 @@ class UIApplication(CLIApplicationBase): ...@@ -375,8 +365,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, 'toggle_mark', urwid.connect_signal(todolist, 'toggle_mark',
self._process_mark_toggle) self._process_mark_toggle)
urwid.connect_signal(todolist, 'has_marked_todos',
self._has_marked_todos)
options = self.columns.options( options = self.columns.options(
width_type='given', width_type='given',
......
...@@ -60,12 +60,10 @@ class TodoListWidget(urwid.LineBox): ...@@ -60,12 +60,10 @@ class TodoListWidget(urwid.LineBox):
'refresh', 'refresh',
'add_pending_action', 'add_pending_action',
'remove_pending_action', 'remove_pending_action',
'save_cmd',
'repeat_cmd', 'repeat_cmd',
'column_action', 'column_action',
'show_keystate', 'show_keystate',
'toggle_mark', 'toggle_mark',
'has_marked_todos',
]) ])
@property @property
...@@ -229,13 +227,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -229,13 +227,7 @@ class TodoListWidget(urwid.LineBox):
todo = self.listbox.focus.todo todo = self.listbox.focus.todo
todo_id = str(self.view.todolist.number(todo)) todo_id = str(self.view.todolist.number(todo))
result = urwid.emit_signal(self, 'has_marked_todos') urwid.emit_signal(self, p_execute_signal, p_cmd_str, todo_id)
if result:
cmd = p_cmd_str
else:
cmd = p_cmd_str.format(todo_id)
urwid.emit_signal(self, p_execute_signal, cmd)
# force screen redraw after editing # force screen redraw after editing
if p_cmd_str.startswith('edit'): if p_cmd_str.startswith('edit'):
...@@ -262,8 +254,6 @@ class TodoListWidget(urwid.LineBox): ...@@ -262,8 +254,6 @@ 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)
...@@ -365,7 +355,4 @@ class TodoListWidget(urwid.LineBox): ...@@ -365,7 +355,4 @@ class TodoListWidget(urwid.LineBox):
except AttributeError: except AttributeError:
todo_id = None todo_id = None
result = urwid.emit_signal(self, 'has_marked_todos')
if result:
todo_id = None
urwid.emit_signal(self, 'repeat_cmd', todo_id) 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