Commit 8605bb1b authored by Jacek Sowiński's avatar Jacek Sowiński

Append parent contexts to subtodo

This works identically to append_parent_projects option. Code was
generated by simply `s/project/context/`
parent 5718e113
...@@ -28,3 +28,5 @@ ignore_weekends = 1 ...@@ -28,3 +28,5 @@ ignore_weekends = 1
[dep] [dep]
; Add parent projects when adding sub todo items ; Add parent projects when adding sub todo items
append_parent_projects = 0 append_parent_projects = 0
; Add parent contexts when adding sub todo items
append_parent_contexts = 0
...@@ -61,6 +61,7 @@ class _Config: ...@@ -61,6 +61,7 @@ class _Config:
# dep # dep
'append_parent_projects': '0', 'append_parent_projects': '0',
'append_parent_contexts': '0',
} }
self.config = {} self.config = {}
...@@ -148,6 +149,12 @@ class _Config: ...@@ -148,6 +149,12 @@ class _Config:
except ValueError: except ValueError:
return self.defaults['append_parent_projects'] == '1' return self.defaults['append_parent_projects'] == '1'
def append_parent_contexts(self):
try:
return self.cp.getboolean('dep', 'append_parent_contexts')
except ValueError:
return self.defaults['append_parent_contexts'] == '1'
def _get_tag(self, p_tag): def _get_tag(self, p_tag):
try: try:
return self.config[p_tag] return self.config[p_tag]
......
...@@ -141,6 +141,15 @@ class TodoList(TodoListBase): ...@@ -141,6 +141,15 @@ class TodoList(TodoListBase):
for project in p_from_todo.projects() - p_to_todo.projects(): for project in p_from_todo.projects() - p_to_todo.projects():
self.append(p_to_todo, "+{}".format(project)) self.append(p_to_todo, "+{}".format(project))
def append_contexts_to_subtodo():
"""
Appends contexts in the parent todo item that are not present in
the sub todo item.
"""
if config().append_parent_contexts():
for context in p_from_todo.contexts() - p_to_todo.contexts():
self.append(p_to_todo, "@{}".format(context))
if p_from_todo != p_to_todo and not self._depgraph.has_edge( if p_from_todo != p_to_todo and not self._depgraph.has_edge(
hash(p_from_todo), hash(p_to_todo)): hash(p_from_todo), hash(p_to_todo)):
...@@ -155,6 +164,7 @@ class TodoList(TodoListBase): ...@@ -155,6 +164,7 @@ class TodoList(TodoListBase):
self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id) self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id)
self._update_parent_cache() self._update_parent_cache()
append_projects_to_subtodo() append_projects_to_subtodo()
append_contexts_to_subtodo()
self.dirty = True self.dirty = True
def remove_dependency(self, p_from_todo, p_to_todo): def remove_dependency(self, p_from_todo, p_to_todo):
......
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