95
73
self.treeview = gtk.TreeView()
96
74
self.treeview.set_rules_hint(True)
97
75
self.treeview.set_search_column(4)
98
self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
76
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
99
77
self.treeview.connect("row-activated", self._treeview_row_activated_cb)
100
78
self.treeview.connect("button-release-event",
101
79
self._treeview_row_mouseclick)
102
self.treeview.set_property('fixed-height-mode', True)
103
80
scrollwin.add(self.treeview)
104
81
self.treeview.show()
106
cell = gtk.CellRendererText()
107
cell.set_property("width-chars", 15)
108
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
109
column = gtk.TreeViewColumn("Revision No")
83
cell = CellRendererGraph()
84
column = gtk.TreeViewColumn()
110
85
column.set_resizable(True)
111
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
112
column.set_fixed_width(cell.get_size(self.treeview)[2])
113
column.pack_start(cell, expand=True)
114
column.add_attribute(cell, "text", treemodel.REVNO)
86
column.pack_start(cell, expand=False)
87
column.add_attribute(cell, "node", 1)
88
column.add_attribute(cell, "in-lines", 2)
89
column.add_attribute(cell, "out-lines", 3)
115
90
self.treeview.append_column(column)
117
self.graph_cell = CellRendererGraph()
118
self.graph_column = gtk.TreeViewColumn()
119
self.graph_column.set_resizable(True)
120
self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
121
self.graph_column.pack_start(self.graph_cell, expand=False)
122
self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
123
self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
124
self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
125
self.treeview.append_column(self.graph_column)
127
92
cell = gtk.CellRendererText()
128
cell.set_property("width-chars", 65)
93
cell.set_property("width-chars", 40)
129
94
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
130
95
column = gtk.TreeViewColumn("Message")
131
96
column.set_resizable(True)
132
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
133
column.set_fixed_width(cell.get_size(self.treeview)[2])
134
97
column.pack_start(cell, expand=True)
135
column.add_attribute(cell, "text", treemodel.MESSAGE)
98
column.add_attribute(cell, "text", 4)
136
99
self.treeview.append_column(column)
138
101
cell = gtk.CellRendererText()
139
cell.set_property("width-chars", 15)
102
cell.set_property("width-chars", 40)
140
103
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
141
104
column = gtk.TreeViewColumn("Committer")
142
105
column.set_resizable(True)
143
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
144
column.set_fixed_width(cell.get_size(self.treeview)[2])
145
column.pack_start(cell, expand=True)
146
column.add_attribute(cell, "text", treemodel.COMMITER)
106
column.pack_start(cell, expand=True)
107
column.add_attribute(cell, "text", 5)
108
self.treeview.append_column(column)
110
cell = gtk.CellRendererText()
111
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
112
column = gtk.TreeViewColumn("Date")
113
column.set_resizable(True)
114
column.pack_start(cell, expand=True)
115
column.add_attribute(cell, "text", 6)
147
116
self.treeview.append_column(column)
197
166
self.branch = branch
198
self.set_title(branch.nick + " - revision history")
168
# [ revision, node, last_lines, lines, message, committer, timestamp ]
169
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
170
gobject.TYPE_PYOBJECT,
171
gobject.TYPE_PYOBJECT,
172
gobject.TYPE_PYOBJECT,
175
self.set_title(branch.nick + " - bzrk")
199
176
gobject.idle_add(self.populate_model, start, maxnum)
201
178
def populate_model(self, start, maxnum):
202
(linegraphdata, index, columns_len) = linegraph(self.branch,
205
self.model = TreeModel(self.branch, linegraphdata)
206
self.graph_cell.columns_len = columns_len
207
width = self.graph_cell.get_size(self.treeview)[2]
208
self.graph_column.set_fixed_width(width)
209
self.graph_column.set_max_width(width)
182
(self.revisions, colours, self.children, self.parent_ids,
183
merge_sorted) = distances(self.branch.repository, start)
184
for (index, (revision, node, lines)) in enumerate(graph(
185
self.revisions, colours, merge_sorted)):
186
# FIXME: at this point we should be able to show the graph order
187
# and lines with no message or commit data - and then incrementally
188
# fill the timestamp, committer etc data as desired.
189
message = revision.message.split("\n")[0]
190
if revision.committer is not None:
191
timestamp = format_date(revision.timestamp, revision.timezone)
194
self.model.append([revision, node, last_lines, lines,
195
message, revision.committer, timestamp])
196
self.index[revision] = index
198
if maxnum is not None and index > maxnum:
211
200
self.treeview.set_model(self.model)
212
self.treeview.get_selection().select_path(0)
213
self.loading_msg_box.hide()
216
def _treeselection_changed_cb(self, selection, *args):
217
"""Callback for when the treeview changes."""
218
(model, selected_rows) = selection.get_selected_rows()
219
if len(selected_rows) > 0:
220
iter = self.model.get_iter(selected_rows[0])
221
revision = self.model.get_value(iter, treemodel.REVISION)
222
parents = self.model.get_value(iter, treemodel.PARENTS)
223
children = self.model.get_value(iter, treemodel.CHILDREN)
225
self.back_button.set_sensitive(len(parents) > 0)
226
self.fwd_button.set_sensitive(len(children) > 0)
228
if self.branch.supports_tags():
229
tagdict = self.branch.tags.get_reverse_tag_dict()
230
if tagdict.has_key(revision.revision_id):
231
tags = tagdict[revision.revision_id]
232
self.logview.set_revision(revision, tags, children)
204
def _treeview_cursor_cb(self, *args):
205
"""Callback for when the treeview cursor changes."""
206
(path, col) = self.treeview.get_cursor()
207
revision = self.model[path][0]
209
self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
210
self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
212
if self.branch.supports_tags():
213
tagdict = self.branch.tags.get_reverse_tag_dict()
214
if tagdict.has_key(revision.revision_id):
215
tags = tagdict[revision.revision_id]
216
self.logview.set_revision(revision, tags)
234
218
def _back_clicked_cb(self, *args):
235
219
"""Callback for when the back button is clicked."""
236
220
(path, col) = self.treeview.get_cursor()
237
221
revision = self.model[path][0]
238
parents = self.model[path][4]
222
if not len(self.parent_ids[revision]):
242
for parent_id in parents:
243
parent = self.revisions[self.index[parent_id]]
225
for parent_id in self.parent_ids[revision]:
226
parent = self.revisions[parent_id]
244
227
if same_branch(revision, parent):
245
self.treeview.set_cursor(self.index[parent_id])
228
self.treeview.set_cursor(self.index[parent])
248
self.treeview.set_cursor(self.index[parents[0]])
231
next = self.revisions[self.parent_ids[revision][0]]
232
self.treeview.set_cursor(self.index[next])
249
233
self.treeview.grab_focus()
251
235
def _fwd_clicked_cb(self, *args):
252
236
"""Callback for when the forward button is clicked."""
253
237
(path, col) = self.treeview.get_cursor()
254
238
revision = self.model[path][0]
255
children = self.model[path][5]
256
if not len(children):
239
if not len(self.children[revision]):
259
for child_id in children:
260
child = self.revisions[self.index[child_id]]
242
for child in self.children[revision]:
261
243
if same_branch(child, revision):
262
self.treeview.set_cursor(self.index[child_id])
244
self.treeview.set_cursor(self.index[child])
265
self.treeview.set_cursor(self.index[children[0]])
247
prev = list(self.children[revision])[0]
248
self.treeview.set_cursor(self.index[prev])
266
249
self.treeview.grab_focus()
268
251
def _go_clicked_cb(self, revid):
269
252
"""Callback for when the go button for a parent is clicked."""
270
self.treeview.set_cursor(self.index[revid])
253
self.treeview.set_cursor(self.index[self.revisions[revid]])
271
254
self.treeview.grab_focus()
273
256
def show_diff(self, branch, revid, parentid):
274
257
"""Open a new window to show a diff between the given revisions."""
275
258
from bzrlib.plugins.gtk.diff import DiffWindow
276
window = DiffWindow(parent=self)
259
window = DiffWindow()
277
260
(parent_tree, rev_tree) = branch.repository.revision_trees([parentid,
279
262
description = revid + " - " + branch.nick