/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 viz/branchwin.py

  • Committer: Gary van der Merwe
  • Date: 2007-08-14 20:35:23 UTC
  • mto: (256.2.37 gtk)
  • mto: This revision was merged to the branch mainline in revision 289.
  • Revision ID: garyvdm@gmail.com-20070814203523-oly04hlgzwbgsuho
First go at using bzrlib graph code

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from bzrlib.osutils import format_date
17
17
 
18
 
from graph import distances, graph, same_branch
 
18
from graph import linegraph, same_branch
19
19
from graphcell import CellRendererGraph
20
20
 
21
21
 
95
95
        column = gtk.TreeViewColumn("Message")
96
96
        column.set_resizable(True)
97
97
        column.pack_start(cell, expand=True)
98
 
        column.add_attribute(cell, "text", 4)
 
98
        column.add_attribute(cell, "text", 6)
99
99
        self.treeview.append_column(column)
100
100
 
101
101
        cell = gtk.CellRendererText()
104
104
        column = gtk.TreeViewColumn("Committer")
105
105
        column.set_resizable(True)
106
106
        column.pack_start(cell, expand=True)
107
 
        column.add_attribute(cell, "text", 5)
 
107
        column.add_attribute(cell, "text", 7)
108
108
        self.treeview.append_column(column)
109
109
 
110
110
        cell = gtk.CellRendererText()
112
112
        column = gtk.TreeViewColumn("Date")
113
113
        column.set_resizable(True)
114
114
        column.pack_start(cell, expand=True)
115
 
        column.add_attribute(cell, "text", 6)
 
115
        column.add_attribute(cell, "text", 8)
116
116
        self.treeview.append_column(column)
117
117
 
118
118
        return scrollwin
158
158
 
159
159
    def set_branch(self, branch, start, maxnum):
160
160
        """Set the branch and start position for this window.
161
 
 
 
161
        
162
162
        Creates a new TreeModel and populates it with information about
163
163
        the new branch before updating the window title and model of the
164
164
        treeview itself.
165
165
        """
166
166
        self.branch = branch
167
 
 
 
167
        
168
168
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
169
169
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
170
170
                                   gobject.TYPE_PYOBJECT,
171
171
                                   gobject.TYPE_PYOBJECT,
172
172
                                   gobject.TYPE_PYOBJECT,
 
173
                                   gobject.TYPE_PYOBJECT,
 
174
                                   gobject.TYPE_PYOBJECT,
173
175
                                   str, str, str)
174
176
        self.index = {}
175
 
        index = 0
176
 
 
 
177
        revids = [revision for revision in \
 
178
                  reversed( \
 
179
                    branch.repository.get_ancestry(branch.last_revision()) \
 
180
                  ) \
 
181
                  if revision is not None]
 
182
        self.revisions = branch.repository.get_revisions(revids)
 
183
        revisionparents = branch.repository.get_graph().get_parents(revids)
 
184
        
 
185
            
 
186
        
177
187
        last_lines = []
178
 
        (self.revisions, colours, self.children, self.parent_ids,
179
 
            merge_sorted) = distances(branch.repository, start)
180
 
        for (index, (revision, node, lines)) in enumerate(graph(
181
 
                self.revisions, colours, merge_sorted)):
 
188
        for (index,(revision, node, lines, parents, children)) in \
 
189
                enumerate(linegraph(self.revisions, revisionparents, maxnum)):
182
190
            # FIXME: at this point we should be able to show the graph order
183
191
            # and lines with no message or commit data - and then incrementally
184
192
            # fill the timestamp, committer etc data as desired.
 
193
            
185
194
            message = revision.message.split("\n")[0]
 
195
            
186
196
            if revision.committer is not None:
187
197
                timestamp = format_date(revision.timestamp, revision.timezone)
188
198
            else:
189
199
                timestamp = None
190
200
            self.model.append([revision, node, last_lines, lines,
 
201
                               parents, children, 
191
202
                               message, revision.committer, timestamp])
192
 
            self.index[revision] = index
 
203
            self.index[revision.revision_id] = index
193
204
            last_lines = lines
194
 
            if maxnum is not None and index > maxnum:
195
 
                break
196
 
 
 
205
        
197
206
        self.set_title(branch.nick + " - bzrk")
198
207
        self.treeview.set_model(self.model)
199
 
 
200
208
    def _treeview_cursor_cb(self, *args):
201
209
        """Callback for when the treeview cursor changes."""
202
210
        (path, col) = self.treeview.get_cursor()
203
211
        revision = self.model[path][0]
 
212
        parents = self.model[path][4]
 
213
        children = self.model[path][5]
204
214
 
205
 
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
206
 
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
 
215
        self.back_button.set_sensitive(len(parents) > 0)
 
216
        self.fwd_button.set_sensitive(len(children) > 0)
207
217
        tags = []
208
218
        if self.branch.supports_tags():
209
219
            tagdict = self.branch.tags.get_reverse_tag_dict()
215
225
        """Callback for when the back button is clicked."""
216
226
        (path, col) = self.treeview.get_cursor()
217
227
        revision = self.model[path][0]
218
 
        if not len(self.parent_ids[revision]):
 
228
        parents = self.model[path][4]
 
229
        if not len(parents):
219
230
            return
220
231
 
221
 
        for parent_id in self.parent_ids[revision]:
222
 
            parent = self.revisions[parent_id]
 
232
        for parent_id in parents:
 
233
            parent = self.revisions[self.index[parent_id]]
223
234
            if same_branch(revision, parent):
224
 
                self.treeview.set_cursor(self.index[parent])
 
235
                self.treeview.set_cursor(self.index[parent_id])
225
236
                break
226
237
        else:
227
 
            next = self.revisions[self.parent_ids[revision][0]]
228
 
            self.treeview.set_cursor(self.index[next])
 
238
            self.treeview.set_cursor(self.index[parents[0]])
229
239
        self.treeview.grab_focus()
230
240
 
231
241
    def _fwd_clicked_cb(self, *args):
232
242
        """Callback for when the forward button is clicked."""
233
243
        (path, col) = self.treeview.get_cursor()
234
244
        revision = self.model[path][0]
235
 
        if not len(self.children[revision]):
 
245
        children = self.model[path][5]
 
246
        if not len(children):
236
247
            return
237
248
 
238
 
        for child in self.children[revision]:
 
249
        for child_id in children:
 
250
            child = self.revisions[self.index[child_id]]
239
251
            if same_branch(child, revision):
240
 
                self.treeview.set_cursor(self.index[child])
 
252
                self.treeview.set_cursor(self.index[child_id])
241
253
                break
242
254
        else:
243
 
            prev = list(self.children[revision])[0]
244
 
            self.treeview.set_cursor(self.index[prev])
 
255
            self.treeview.set_cursor(self.index[children[0]])
245
256
        self.treeview.grab_focus()
246
257
 
247
258
    def _go_clicked_cb(self, revid):
248
259
        """Callback for when the go button for a parent is clicked."""
249
 
        self.treeview.set_cursor(self.index[self.revisions[revid]])
 
260
        self.treeview.set_cursor(self.index[revid])
250
261
        self.treeview.grab_focus()
251
262
 
252
263
    def show_diff(self, branch, revid, parentid):
289
300
        parent_id = self.parent_ids[revision][0]
290
301
        self.show_diff(self.branch, revision.revision_id, parent_id)
291
302
        self.treeview.grab_focus()
 
303
 
 
304
 
 
305