37
class TreeModel(Gtk.TreeStore):
39
def __init__ (self, branch, line_graph_data):
40
Gtk.TreeStore.__init__(self)
37
class BranchTreeModel(Gtk.ListStore):
38
"""A model of branch's merge history."""
40
def __init__(self, branch, line_graph_data):
41
super(BranchTreeModel, self).__init__(
43
GObject.TYPE_PYOBJECT,
44
GObject.TYPE_PYOBJECT,
45
GObject.TYPE_PYOBJECT,
51
GObject.TYPE_PYOBJECT,
52
GObject.TYPE_PYOBJECT,
53
GObject.TYPE_PYOBJECT,
54
GObject.TYPE_PYOBJECT,
41
56
self.revisions = {}
42
57
self.branch = branch
43
58
self.repository = branch.repository
44
self.line_graph_data = line_graph_data
46
59
if self.branch.supports_tags():
47
60
self.tags = self.branch.tags.get_reverse_tag_dict()
63
self.set_line_graph_data(line_graph_data)
51
65
def add_tag(self, tag, revid):
52
66
self.branch.tags.set_tag(tag, revid)
56
70
self.tags[revid] = [tag]
58
def on_get_flags(self):
59
return Gtk.TREE_MODEL_LIST_ONLY
61
def on_get_n_columns(self):
64
def on_get_column_type(self, index):
65
if index == REVID: return GObject.TYPE_STRING
66
if index == NODE: return GObject.TYPE_PYOBJECT
67
if index == LINES: return GObject.TYPE_PYOBJECT
68
if index == LAST_LINES: return GObject.TYPE_PYOBJECT
69
if index == REVNO: return GObject.TYPE_STRING
70
if index == SUMMARY: return GObject.TYPE_STRING
71
if index == MESSAGE: return GObject.TYPE_STRING
72
if index == COMMITTER: return GObject.TYPE_STRING
73
if index == TIMESTAMP: return GObject.TYPE_STRING
74
if index == REVISION: return GObject.TYPE_PYOBJECT
75
if index == PARENTS: return GObject.TYPE_PYOBJECT
76
if index == CHILDREN: return GObject.TYPE_PYOBJECT
77
if index == TAGS: return GObject.TYPE_PYOBJECT
78
if index == AUTHORS: return GObject.TYPE_STRING
80
def on_get_iter(self, path):
81
# XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
84
def on_get_path(self, rowref):
87
def on_get_value(self, rowref, column):
88
if len(self.line_graph_data) > 0:
89
(revid, node, lines, parents,
90
children, revno_sequence) = self.line_graph_data[rowref]
72
def _line_graph_item_to_model_row(self, rowref, data):
73
revid, node, lines, parents, children, revno_sequence = data
75
last_lines = self.line_graph_data[rowref - 1][2]
92
(revid, node, lines, parents,
93
children, revno_sequence) = (None, (0, 0), (), (),
95
if column == REVID: return revid
96
if column == NODE: return node
97
if column == LINES: return lines
98
if column == PARENTS: return parents
99
if column == CHILDREN: return children
100
if column == LAST_LINES:
102
return self.line_graph_data[rowref-1][2]
104
if column == REVNO: return ".".join(["%d" % (revno)
105
for revno in revno_sequence])
107
if column == TAGS: return self.tags.get(revid, [])
78
revno = ".".join(["%d" % (revno) for revno in revno_sequence])
79
tags = self.tags.get(revid, [])
109
80
if not revid or revid == NULL_REVISION:
111
if revid not in self.revisions:
82
elif revid not in self.revisions:
112
83
revision = self.repository.get_revisions([revid])[0]
113
84
self.revisions[revid] = revision
115
86
revision = self.revisions[revid]
117
if column == REVISION: return revision
118
if column == SUMMARY: return escape(revision.get_summary())
119
if column == MESSAGE: return escape(revision.message)
120
if column == COMMITTER: return parse_username(revision.committer)[0]
121
if column == TIMESTAMP:
122
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
123
if column == AUTHORS:
125
parse_username(author)[0] for author in revision.get_apparent_authors()])
127
def on_iter_next(self, rowref):
128
if rowref < len(self.line_graph_data) - 1:
132
def on_iter_children(self, parent):
133
if parent is None: return 0
136
def on_iter_has_child(self, rowref):
139
def on_iter_n_children(self, rowref):
140
if rowref is None: return len(self.line_graph_data)
143
def on_iter_nth_child(self, parent, n):
144
if parent is None: return n
147
def on_iter_parent(self, child):
88
summary = message = committer = timestamp = authors = None
90
summary = escape(revision.get_summary())
91
message = escape(revision.message)
92
committer = parse_username(revision.committer)[0]
94
"%Y-%m-%d %H:%M", localtime(revision.timestamp))
96
parse_username(author)[0]
97
for author in revision.get_apparent_authors()])
98
return (revid, node, lines, last_lines, revno, summary, message,
99
committer, timestamp, revision, parents, children, tags,
102
def set_line_graph_data(self, line_graph_data):
104
self.line_graph_data = line_graph_data
105
for rowref, data in enumerate(self.line_graph_data):
106
row = self._line_graph_item_to_model_row(rowref, data)