77
75
self.treeview.set_search_column(4)
78
76
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
79
77
self.treeview.connect("row-activated", self._treeview_row_activated_cb)
80
self.treeview.connect("button-release-event",
81
self._treeview_row_mouseclick)
82
78
scrollwin.add(self.treeview)
83
79
self.treeview.show()
85
cell = gtk.CellRendererText()
86
#cell.set_property("width-chars", 40)
87
#cell.set_property("ellipsize", pango.ELLIPSIZE_END)
88
column = gtk.TreeViewColumn("Revision No")
89
column.set_resizable(True)
90
column.pack_start(cell, expand=True)
91
column.add_attribute(cell, "text", treemodel.REVNO)
92
self.treeview.append_column(column)
94
81
cell = CellRendererGraph()
95
82
column = gtk.TreeViewColumn()
96
83
column.set_resizable(True)
97
84
column.pack_start(cell, expand=False)
98
column.add_attribute(cell, "node", treemodel.NODE)
99
column.add_attribute(cell, "in-lines", treemodel.LAST_LINES)
100
column.add_attribute(cell, "out-lines", treemodel.LINES)
85
column.add_attribute(cell, "node", 1)
86
column.add_attribute(cell, "in-lines", 2)
87
column.add_attribute(cell, "out-lines", 3)
101
88
self.treeview.append_column(column)
103
90
cell = gtk.CellRendererText()
170
157
def set_branch(self, branch, start, maxnum):
171
158
"""Set the branch and start position for this window.
173
160
Creates a new TreeModel and populates it with information about
174
161
the new branch before updating the window title and model of the
177
164
self.branch = branch
166
# [ revision, node, last_lines, lines, message, committer, timestamp ]
167
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
168
gobject.TYPE_PYOBJECT,
169
gobject.TYPE_PYOBJECT,
170
gobject.TYPE_PYOBJECT,
176
(self.revisions, colours, self.children, self.parent_ids,
177
merge_sorted) = distances(branch, start)
178
for (index, (revision, node, lines)) in enumerate(graph(
179
self.revisions, colours, merge_sorted)):
180
# FIXME: at this point we should be able to show the graph order
181
# and lines with no message or commit data - and then incrementally
182
# fill the timestamp, committer etc data as desired.
183
message = revision.message.split("\n")[0]
184
if revision.committer is not None:
185
timestamp = format_date(revision.timestamp, revision.timezone)
188
self.model.append([revision, node, last_lines, lines,
189
message, revision.committer, timestamp])
190
self.index[revision] = index
192
if maxnum is not None and index > maxnum:
178
195
self.set_title(branch.nick + " - bzrk")
179
gobject.idle_add(self.populate_model, start, maxnum)
181
def populate_model(self, start, maxnum):
182
(linegraphdata, index) = linegraph(self.branch,
185
self.model = TreeModel(self.branch, linegraphdata)
187
196
self.treeview.set_model(self.model)
189
198
def _treeview_cursor_cb(self, *args):
190
199
"""Callback for when the treeview cursor changes."""
191
200
(path, col) = self.treeview.get_cursor()
192
iter = self.model.get_iter(path)
193
revision = self.model.get_value(iter, treemodel.REVISION)
194
parents = self.model.get_value(iter, treemodel.PARENTS)
195
children = self.model.get_value(iter, treemodel.CHILDREN)
201
revision = self.model[path][0]
197
self.back_button.set_sensitive(len(parents) > 0)
198
self.fwd_button.set_sensitive(len(children) > 0)
200
if self.branch.supports_tags():
201
tagdict = self.branch.tags.get_reverse_tag_dict()
202
if tagdict.has_key(revision.revision_id):
203
tags = tagdict[revision.revision_id]
204
self.logview.set_revision(revision, tags, children)
203
self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
204
self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
205
self.logview.set_revision(revision)
206
207
def _back_clicked_cb(self, *args):
207
208
"""Callback for when the back button is clicked."""
208
209
(path, col) = self.treeview.get_cursor()
209
210
revision = self.model[path][0]
210
parents = self.model[path][4]
211
if not len(self.parent_ids[revision]):
214
for parent_id in parents:
215
parent = self.revisions[self.index[parent_id]]
214
for parent_id in self.parent_ids[revision]:
215
parent = self.revisions[parent_id]
216
216
if same_branch(revision, parent):
217
self.treeview.set_cursor(self.index[parent_id])
217
self.treeview.set_cursor(self.index[parent])
220
self.treeview.set_cursor(self.index[parents[0]])
220
next = self.revisions[self.parent_ids[revision][0]]
221
self.treeview.set_cursor(self.index[next])
221
222
self.treeview.grab_focus()
223
224
def _fwd_clicked_cb(self, *args):
224
225
"""Callback for when the forward button is clicked."""
225
226
(path, col) = self.treeview.get_cursor()
226
227
revision = self.model[path][0]
227
children = self.model[path][5]
228
if not len(children):
228
if not len(self.children[revision]):
231
for child_id in children:
232
child = self.revisions[self.index[child_id]]
231
for child in self.children[revision]:
233
232
if same_branch(child, revision):
234
self.treeview.set_cursor(self.index[child_id])
233
self.treeview.set_cursor(self.index[child])
237
self.treeview.set_cursor(self.index[children[0]])
236
prev = list(self.children[revision])[0]
237
self.treeview.set_cursor(self.index[prev])
238
238
self.treeview.grab_focus()
240
240
def _go_clicked_cb(self, revid):
241
241
"""Callback for when the go button for a parent is clicked."""
242
self.treeview.set_cursor(self.index[revid])
242
self.treeview.set_cursor(self.index[self.revisions[revid]])
243
243
self.treeview.grab_focus()
245
245
def show_diff(self, branch, revid, parentid):
246
246
"""Open a new window to show a diff between the given revisions."""
247
247
from bzrlib.plugins.gtk.diff import DiffWindow
248
248
window = DiffWindow()
249
(parent_tree, rev_tree) = branch.repository.revision_trees([parentid,
249
rev_tree = branch.repository.revision_tree(revid)
250
parent_tree = branch.repository.revision_tree(parentid)
251
251
description = revid + " - " + branch.nick
252
252
window.set_diff(description, rev_tree, parent_tree)
257
257
self.show_diff(self.branch, revid, parentid)
258
258
self.treeview.grab_focus()
260
def _treeview_row_mouseclick(self, widget, event):
261
from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
262
if event.button == 3:
263
menu = RevisionPopupMenu(self.branch.repository,
264
[x.revision_id for x in self.selected_revisions()],
266
menu.popup(None, None, None, event.button, event.get_time())
268
def selected_revision(self, path):
269
return self.model[path][0]
271
def selected_revisions(self):
272
return [self.selected_revision(path) for path in \
273
self.treeview.get_selection().get_selected_rows()[1]]
275
260
def _treeview_row_activated_cb(self, widget, path, col):
276
261
# TODO: more than one parent
277
262
"""Callback for when a treeview row gets activated."""
278
revision = self.selected_revision(path)
263
revision = self.model[path][0]
279
264
if len(self.parent_ids[revision]) == 0:
280
265
# Ignore revisions without parent