/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/treemodel.py

  • Committer: Curtis Hovey
  • Date: 2011-09-03 13:46:52 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110903134652-foz5thvhwg0kcolr
Removed unused code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: UTF-8 -*-
2
 
"""Tree model.
3
 
 
4
 
"""
 
2
"""BranchTreeModel."""
5
3
 
6
4
__copyright__ = "Copyright � 2005 Canonical Ltd."
7
5
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
19
17
    localtime,
20
18
    )
21
19
 
 
20
 
22
21
REVID = 0
23
22
NODE = 1
24
23
LINES = 2
35
34
AUTHORS = 13
36
35
 
37
36
 
38
 
class BranchTreeModel(Gtk.TreeStore):
 
37
class BranchTreeModel(Gtk.ListStore):
39
38
    """A model of branch's merge history."""
40
39
 
41
40
    def __init__(self, branch, line_graph_data):
100
99
                authors = ", ".join([
101
100
                    parse_username(author)[0]
102
101
                    for author in revision.get_apparent_authors()])
103
 
            self.append(
104
 
                None,
105
 
                (revid, node, lines, last_lines, revno, summary, message,
 
102
            self.append((
 
103
                revid, node, lines, last_lines, revno, summary, message,
106
104
                committer, timestamp, revision, parents, children, tags,
107
105
                authors))
108
 
 
109
 
 
110
 
class TreeModel(Gtk.TreeStore):
111
 
 
112
 
    def __init__(self, branch, line_graph_data):
113
 
        Gtk.TreeStore.__init__(self)
114
 
        self.revisions = {}
115
 
        self.branch = branch
116
 
        self.repository = branch.repository
117
 
        self.line_graph_data = line_graph_data
118
 
 
119
 
        if self.branch.supports_tags():
120
 
            self.tags = self.branch.tags.get_reverse_tag_dict()
121
 
        else:
122
 
            self.tags = {}
123
 
 
124
 
    def add_tag(self, tag, revid):
125
 
        self.branch.tags.set_tag(tag, revid)
126
 
        try:
127
 
            self.tags[revid].append(tag)
128
 
        except KeyError:
129
 
            self.tags[revid] = [tag]
130
 
 
131
 
    def on_get_flags(self):
132
 
        return Gtk.TREE_MODEL_LIST_ONLY
133
 
 
134
 
    def on_get_n_columns(self):
135
 
        return 14
136
 
 
137
 
    def on_get_column_type(self, index):
138
 
        if index == REVID: return GObject.TYPE_STRING
139
 
        if index == NODE: return GObject.TYPE_PYOBJECT
140
 
        if index == LINES: return GObject.TYPE_PYOBJECT
141
 
        if index == LAST_LINES: return GObject.TYPE_PYOBJECT
142
 
        if index == REVNO: return GObject.TYPE_STRING
143
 
        if index == SUMMARY: return GObject.TYPE_STRING
144
 
        if index == MESSAGE: return GObject.TYPE_STRING
145
 
        if index == COMMITTER: return GObject.TYPE_STRING
146
 
        if index == TIMESTAMP: return GObject.TYPE_STRING
147
 
        if index == REVISION: return GObject.TYPE_PYOBJECT
148
 
        if index == PARENTS: return GObject.TYPE_PYOBJECT
149
 
        if index == CHILDREN: return GObject.TYPE_PYOBJECT
150
 
        if index == TAGS: return GObject.TYPE_PYOBJECT
151
 
        if index == AUTHORS: return GObject.TYPE_STRING
152
 
 
153
 
    def on_get_iter(self, path):
154
 
        # XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
155
 
        return path[0]
156
 
 
157
 
    def on_get_path(self, rowref):
158
 
        return rowref
159
 
 
160
 
    def on_get_value(self, rowref, column):
161
 
        if len(self.line_graph_data) > 0:
162
 
            (revid, node, lines, parents,
163
 
             children, revno_sequence) = self.line_graph_data[rowref]
164
 
        else:
165
 
            (revid, node, lines, parents,
166
 
             children, revno_sequence) = (None, (0, 0), (), (),
167
 
                                          (), ())
168
 
        if column == REVID: return revid
169
 
        if column == NODE: return node
170
 
        if column == LINES: return lines
171
 
        if column == PARENTS: return parents
172
 
        if column == CHILDREN: return children
173
 
        if column == LAST_LINES:
174
 
            if rowref>0:
175
 
                return self.line_graph_data[rowref-1][2]
176
 
            return []
177
 
        if column == REVNO: return ".".join(["%d" % (revno)
178
 
                                      for revno in revno_sequence])
179
 
 
180
 
        if column == TAGS: return self.tags.get(revid, [])
181
 
 
182
 
        if not revid or revid == NULL_REVISION:
183
 
            return None
184
 
        if revid not in self.revisions:
185
 
            revision = self.repository.get_revisions([revid])[0]
186
 
            self.revisions[revid] = revision
187
 
        else:
188
 
            revision = self.revisions[revid]
189
 
 
190
 
        if column == REVISION: return revision
191
 
        if column == SUMMARY: return escape(revision.get_summary())
192
 
        if column == MESSAGE: return escape(revision.message)
193
 
        if column == COMMITTER: return parse_username(revision.committer)[0]
194
 
        if column == TIMESTAMP:
195
 
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
196
 
        if column == AUTHORS:
197
 
            return ", ".join([
198
 
                parse_username(author)[0] for author in revision.get_apparent_authors()])
199
 
 
200
 
    def on_iter_next(self, rowref):
201
 
        if rowref < len(self.line_graph_data) - 1:
202
 
            return rowref+1
203
 
        return None
204
 
 
205
 
    def on_iter_children(self, parent):
206
 
        if parent is None: return 0
207
 
        return None
208
 
 
209
 
    def on_iter_has_child(self, rowref):
210
 
        return False
211
 
 
212
 
    def on_iter_n_children(self, rowref):
213
 
        if rowref is None: return len(self.line_graph_data)
214
 
        return 0
215
 
 
216
 
    def on_iter_nth_child(self, parent, n):
217
 
        if parent is None: return n
218
 
        return None
219
 
 
220
 
    def on_iter_parent(self, child):
221
 
        return None