def sync_with_taskwarrior(self): # This is called at the point where all the tasks in the vim # are already synced. This should load the tasks from TW matching # the filter, and add the tasks that are new. Optionally remove the # tasks that are not longer belonging there. # Get sets of tasks to add and to delete to_add, to_del = self.get_tasks_to_add_and_del() # Remove tasks that no longer match the filter for task in to_del: # Find matching vimwikitasks in the self.tasks set # There might be more if the viewport contained multiple # representations of the same task if task.saved: matching_vimwikitasks = [ t for t in self.tasks if t.uuid == short.ShortUUID(task['uuid'], task.backend) ] else: # For the tasks that are not saved yet, only one # representation can exist, so use object-comparison matching_vimwikitasks = [ t for t in self.tasks if t.task == task ] # Remove the tasks from viewport's set and from buffer for vimwikitask in matching_vimwikitasks: self.tasks.remove(vimwikitask) self.cache.remove_line(vimwikitask['line_number']) # Add the tasks that match the filter and are not listed added_tasks = 0 existing_tasks = len(self.tasks) sorted_to_add = list(to_add) sorted_to_add.sort(key=lambda x: x['entry']) for task in sorted_to_add: added_tasks += 1 added_at = self.line_number + existing_tasks + added_tasks # Add the task object to cache self.cache.task[short.ShortUUID(task['uuid'], self.tw)] = task # Create the VimwikiTask vimwikitask = vwtask.VimwikiTask.from_task(self.cache, task) vimwikitask['line_number'] = added_at self.tasks.add(vimwikitask) # Update the buffer self.cache.insert_line(str(vimwikitask), added_at) # Save it to cache self.cache.vwtask[added_at] = vimwikitask sort.TaskSorter(self.cache, self.tasks, self.sort).execute()
def sort(self, sortstring): sort.TaskSorter(cache(), self.tasks, sortstring).execute() cache().buffer.push()