Commit 947ec5ae authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add first support for todo items with a base36 ID.

parent 43122a1c
...@@ -44,6 +44,8 @@ class TodoList(TodoListBase.TodoListBase): ...@@ -44,6 +44,8 @@ class TodoList(TodoListBase.TodoListBase):
self._todos = [] self._todos = []
self._tododict = {} # hash(todo) to todo lookup self._tododict = {} # hash(todo) to todo lookup
self._depgraph = Graph.DirectedGraph() self._depgraph = Graph.DirectedGraph()
self._todo_id_map = {}
self._id_todo_map = {}
self.add_list(p_todostrings) self.add_list(p_todostrings)
self.dirty = False self.dirty = False
...@@ -87,6 +89,7 @@ class TodoList(TodoListBase.TodoListBase): ...@@ -87,6 +89,7 @@ class TodoList(TodoListBase.TodoListBase):
self._tododict[hash(todo)] = todo self._tododict[hash(todo)] = todo
self._maintain_dep_graph(todo) self._maintain_dep_graph(todo)
self._update_todo_ids()
self._update_parent_cache() self._update_parent_cache()
self.dirty = True self.dirty = True
......
...@@ -22,6 +22,7 @@ from datetime import date ...@@ -22,6 +22,7 @@ from datetime import date
import re import re
import Filter import Filter
from HashListValues import hash_list_values
from PrettyPrinter import pretty_print_list from PrettyPrinter import pretty_print_list
import Todo import Todo
import View import View
...@@ -44,6 +45,8 @@ class TodoListBase(object): ...@@ -44,6 +45,8 @@ class TodoListBase(object):
The string will be parsed. The string will be parsed.
""" """
self._todos = [] self._todos = []
self._todo_id_map = {}
self._id_todo_map = {}
self.add_list(p_todostrings) self.add_list(p_todostrings)
self.dirty = False self.dirty = False
...@@ -100,6 +103,7 @@ class TodoListBase(object): ...@@ -100,6 +103,7 @@ class TodoListBase(object):
for todo in p_todos: for todo in p_todos:
self._todos.append(todo) self._todos.append(todo)
self._update_todo_ids()
self.dirty = True self.dirty = True
def delete(self, p_todo): def delete(self, p_todo):
...@@ -187,6 +191,16 @@ class TodoListBase(object): ...@@ -187,6 +191,16 @@ class TodoListBase(object):
""" """
return lambda p_todo_str, p_todo: "%3d %s" % (self.number(p_todo), p_todo_str) return lambda p_todo_str, p_todo: "%3d %s" % (self.number(p_todo), p_todo_str)
def _update_todo_ids(self):
# the idea is to have a hash that is independent of the position of the
# todo. Use the text (without tags) of the todo to keep the id as stable
# as possible (not influenced by priorities or due dates, etc.)
uids = hash_list_values(self._todos, lambda t: hash(t.text()))
for (todo, uid) in uids:
self._todo_id_map[todo] = uid
self._id_todo_map[uid] = todo
def __str__(self): def __str__(self):
return '\n'.join(pretty_print_list(self._todos)) return '\n'.join(pretty_print_list(self._todos))
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