taskwiki: Move methods that affect whole buffer into common namespace

This commit is contained in:
Tomas Babej 2015-03-21 14:11:41 +01:00
parent 0b02d85049
commit 5d32666cce
2 changed files with 23 additions and 20 deletions

View file

@ -4,7 +4,7 @@ execute 'pyfile ' . s:plugin_path . '/taskwiki/taskwiki.py'
augroup taskwiki augroup taskwiki
" when saving the file sync the tasks from vimwiki to TW " when saving the file sync the tasks from vimwiki to TW
autocmd! autocmd!
execute "autocmd BufWrite *.".expand('%:e')." python update_to_tw()" execute "autocmd BufWrite *.".expand('%:e')." py WholeBuffer.update_to_tw()"
augroup END augroup END
command! -range TaskWikiInfo :<line1>,<line2>py SelectedTasks().info() command! -range TaskWikiInfo :<line1>,<line2>py SelectedTasks().info()

View file

@ -24,28 +24,31 @@ tw = TaskWarrior()
cache = cache.TaskCache(tw) cache = cache.TaskCache(tw)
def update_from_tw(): class WholeBuffer(object):
""" @staticmethod
Updates all the incomplete tasks in the vimwiki file if the info from TW is different. def update_from_tw():
""" """
Updates all the incomplete tasks in the vimwiki file if the info from TW is different.
"""
cache.load_buffer() cache.load_buffer()
cache.update_tasks() cache.update_tasks()
cache.update_buffer() cache.update_buffer()
cache.evaluate_viewports() cache.evaluate_viewports()
@staticmethod
def update_to_tw():
"""
Updates all tasks that differ from their TaskWarrior representation.
"""
def update_to_tw(): cache.reset()
""" cache.load_buffer()
Updates all tasks that differ from their TaskWarrior representation. cache.update_tasks()
""" cache.save_tasks()
cache.update_buffer()
cache.evaluate_viewports()
cache.reset()
cache.load_buffer()
cache.update_tasks()
cache.save_tasks()
cache.update_buffer()
cache.evaluate_viewports()
class SelectedTasks(object): class SelectedTasks(object):
def __init__(self): def __init__(self):
@ -107,4 +110,4 @@ class SelectedTasks(object):
if __name__ == '__main__': if __name__ == '__main__':
update_from_tw() WholeBuffer.update_from_tw()