Cache: Add API for looking a viewport up by a task it contains

This commit is contained in:
Tomas Babej 2015-12-21 02:03:39 +01:00
parent ac9c44d118
commit f79734aed9

View file

@ -65,6 +65,7 @@ class TaskCache(object):
def __init__(self):
self.task_cache = dict()
self.vimwikitask_cache = dict()
self.viewport_cache = dict()
self.warriors = WarriorStore()
self.buffer_has_authority = True
@ -159,6 +160,7 @@ class TaskCache(object):
def reset(self):
self.task_cache = dict()
self.vimwikitask_cache = dict()
self.viewport_cache = dict()
def load_vwtasks(self, buffer_has_authority=True):
# Set the authority flag, which determines which data (Buffer or TW)
@ -231,6 +233,21 @@ class TaskCache(object):
port.load_tasks()
port.sync_with_taskwarrior()
# Save the viewport in the cache
self.viewport_cache[i] = port
def get_viewport_by_task(self, task):
"""
Looks for a viewport containing the given task by iterating over the cached
items.
Returns the viewport, or None if not found.
"""
for port in self.viewport_cache.values():
if task in port.viewport_tasks:
return port
def rebuild_vimwikitask_cache(self):
new_cache = dict()