Commit 4e04bcdc authored by Jacek Sowiński's avatar Jacek Sowiński

Add new method for executing cmds on todo items

_command_on_selected: accepts string containing command (with potential
arguments) to execute and replace field (for further substitution with
todo id) as an argument.
parent 0b1ab7c4
...@@ -153,20 +153,28 @@ class TodoListWidget(urwid.LineBox): ...@@ -153,20 +153,28 @@ class TodoListWidget(urwid.LineBox):
def selectable(self): def selectable(self):
return True return True
def _complete_selected_item(self): def _command_on_selected(self, p_cmd_str):
""" """
Marks the highlighted todo item as complete. Executes command specified by p_cmd_str on selected todo item.
p_cmd_str should be string with one replacement field ('{}') which will
be substituted by id of selected todo item.
""" """
try: try:
todo = self.listbox.focus.todo todo = self.listbox.focus.todo
self.view.todolist.number(todo) todo_id = str(self.view.todolist.number(todo))
urwid.emit_signal(self, 'execute_command', "do {}".format( urwid.emit_signal(self, 'execute_command', p_cmd_str.format(todo_id))
str(self.view.todolist.number(todo))))
except AttributeError: except AttributeError:
# No todo item selected # No todo item selected
pass pass
def _complete_selected_item(self):
"""
Marks the highlighted todo item as complete.
"""
self._command_on_selected('do {}')
def _postpone_selected_item(self, p_pattern): def _postpone_selected_item(self, p_pattern):
""" """
Postpones highlighted todo item by p_pattern with optional offset from Postpones highlighted todo item by p_pattern with optional offset from
...@@ -174,56 +182,29 @@ class TodoListWidget(urwid.LineBox): ...@@ -174,56 +182,29 @@ class TodoListWidget(urwid.LineBox):
""" """
if self._pp_offset == '': if self._pp_offset == '':
self._pp_offset = '1' self._pp_offset = '1'
try:
todo = self.listbox.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "postpone {} {}".format( pattern = self._pp_offset + p_pattern
str(self.view.todolist.number(todo)), self._pp_offset + p_pattern)) cmd_str = 'postpone {t_id} {pattern}'.format(t_id='{}', pattern=pattern)
except AttributeError:
# No todo item selected self._command_on_selected(cmd_str)
pass
def _remove_selected_item(self): def _remove_selected_item(self):
""" """
Removes the highlighted todo item. Removes the highlighted todo item.
""" """
try: self._command_on_selected('del {}')
todo = self.listbox.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "del {}".format(
str(self.view.todolist.number(todo))))
except AttributeError:
# No todo item selected
pass
def _edit_selected_item(self): def _edit_selected_item(self):
""" """
Opens the highlighted todo item in $EDITOR for editing. Opens the highlighted todo item in $EDITOR for editing.
""" """
try: self._command_on_selected('edit {}')
todo = self.listbox.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "edit {}".format(
str(self.view.todolist.number(todo))))
except AttributeError:
# No todo item selected
pass
def _pri_selected_item(self, p_priority): def _pri_selected_item(self, p_priority):
""" """
Sets the priority of the highlighted todo item with value from Sets the priority of the highlighted todo item with value from
p_priority. p_priority.
""" """
try: cmd_str = 'pri {t_id} {priority}'.format(t_id='{}', priority=p_priority)
todo = self.listbox.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "pri {} {}".format(
str(self.view.todolist.number(todo)), p_priority))
except AttributeError:
# No todo item selected
pass
self._command_on_selected(cmd_str)
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