Commit f2b7bd43 authored by Jacek Sowiński's avatar Jacek Sowiński

Add shortcut for postponing todo items

Shortcut calls postpone command and accepts similiar format as original
`topydo postpone`.

Examples:
- pressing 'pd' or 'p1d' will postpone selected task by one day.
- 'p3y' will postpone task by 3 years.
- 'p12w' will postpone task by 12 (twelve) weeks.
parent 84de4e30
......@@ -24,6 +24,8 @@ class TodoListWidget(urwid.LineBox):
# store a state for multi-key shortcuts (e.g. 'gg')
self.keystate = None
# store offset length for postpone command (e.g. '3' for 'p3w')
self._pp_offset = ''
self._title_widget = urwid.Text(p_title, align='center')
......@@ -102,9 +104,24 @@ class TodoListWidget(urwid.LineBox):
# make sure to accept normal shortcuts again
self.keystate = None
return
elif self.keystate == 'p':
if p_key not in ['d', 'w', 'm', 'y']:
if p_key.isdigit():
self._pp_offset += p_key
else:
self._pp_offset = ''
self.keystate = None
else:
self._postpone_selected_item(p_key)
self._pp_offset = ''
self.keystate = None
return
if p_key == 'x':
self._complete_selected_item()
elif p_key == 'p':
self.keystate = 'p'
elif p_key == 'j':
self.listbox.keypress(p_size, 'down')
elif p_key == 'k':
......@@ -134,3 +151,20 @@ class TodoListWidget(urwid.LineBox):
except AttributeError:
# No todo item selected
pass
def _postpone_selected_item(self, p_pattern):
"""
Postpones highlighted todo item by p_pattern with optional offset from
_pp_offset attribute.
"""
if self._pp_offset == '':
self._pp_offset = '1'
try:
todo = self.listbox.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "postpone {} {}".format(
str(self.view.todolist.number(todo)), self._pp_offset + p_pattern))
except AttributeError:
# No todo item selected
pass
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