6
__copyright__ = "Copyright � 2005 Canonical Ltd."
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
7
__author__ = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
9
from gi.repository import Gtk
10
from gi.repository import GObject
11
from gi.repository import Pango
17
from linegraph import linegraph, same_branch
18
from graphcell import CellRendererGraph
19
from treemodel import TreeModel
20
14
from bzrlib.revision import NULL_REVISION
22
class TreeView(gtk.VBox):
16
from bzrlib.plugins.gtk import lock
17
from bzrlib.plugins.gtk.ui import ProgressPanel
18
from bzrlib.plugins.gtk.branchview import treemodel
19
from bzrlib.plugins.gtk.branchview.linegraph import linegraph, same_branch
20
from bzrlib.plugins.gtk.branchview.graphcell import CellRendererGraph
23
class TreeView(Gtk.VBox):
24
25
__gproperties__ = {
25
'branch': (gobject.TYPE_PYOBJECT,
26
'branch': (GObject.TYPE_PYOBJECT,
27
28
'The Bazaar branch being visualized',
28
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
29
GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE),
30
'revision': (gobject.TYPE_PYOBJECT,
31
'revision': (GObject.TYPE_PYOBJECT,
32
33
'The currently selected revision',
33
gobject.PARAM_READWRITE),
34
GObject.PARAM_READWRITE),
35
'revision-number': (gobject.TYPE_STRING,
36
'revision-number': (GObject.TYPE_STRING,
37
38
'The number of the selected revision',
39
gobject.PARAM_READABLE),
40
GObject.PARAM_READABLE),
41
'children': (gobject.TYPE_PYOBJECT,
42
'children': (GObject.TYPE_PYOBJECT,
43
44
'Children of the currently selected revision',
44
gobject.PARAM_READABLE),
45
GObject.PARAM_READABLE),
46
'parents': (gobject.TYPE_PYOBJECT,
47
'parents': (GObject.TYPE_PYOBJECT,
47
48
'Parent revisions',
48
49
'Parents to the currently selected revision',
49
gobject.PARAM_READABLE),
50
GObject.PARAM_READABLE),
51
'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
'revno-column-visible': (GObject.TYPE_BOOLEAN,
52
53
'Revision number column',
53
54
'Show revision number column',
55
gobject.PARAM_READWRITE),
56
GObject.PARAM_READWRITE),
57
'graph-column-visible': (gobject.TYPE_BOOLEAN,
58
'graph-column-visible': (GObject.TYPE_BOOLEAN,
59
60
'Show graph column',
61
gobject.PARAM_READWRITE),
62
GObject.PARAM_READWRITE),
63
'date-column-visible': (gobject.TYPE_BOOLEAN,
64
'date-column-visible': (GObject.TYPE_BOOLEAN,
65
66
'Show date column',
67
gobject.PARAM_READWRITE),
68
GObject.PARAM_READWRITE),
69
'compact': (gobject.TYPE_BOOLEAN,
70
'compact': (GObject.TYPE_BOOLEAN,
71
72
'Break ancestry lines to save space',
73
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
74
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
75
'mainline-only': (gobject.TYPE_BOOLEAN,
76
'mainline-only': (GObject.TYPE_BOOLEAN,
77
78
'Only show the mainline history.',
79
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
80
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
84
'revisions-loaded': (gobject.SIGNAL_RUN_FIRST,
87
'revision-selected': (gobject.SIGNAL_RUN_FIRST,
85
'revision-selected': (GObject.SignalFlags.RUN_FIRST,
90
'revision-activated': (gobject.SIGNAL_RUN_FIRST,
92
(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
93
'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
(gobject.TYPE_STRING, gobject.TYPE_STRING))
88
'revision-activated': (GObject.SignalFlags.RUN_FIRST,
90
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)),
91
'tag-added': (GObject.SignalFlags.RUN_FIRST,
93
(GObject.TYPE_STRING, GObject.TYPE_STRING)),
94
'refreshed': (GObject.SignalFlags.RUN_FIRST, None,
98
98
def __init__(self, branch, start, maxnum, compact=True):
105
105
:param broken_line_length: After how much lines to break
108
gtk.VBox.__init__(self, spacing=0)
110
self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
111
self.connect('revisions-loaded',
112
lambda x: self.loading_msg_box.hide())
114
self.scrolled_window = gtk.ScrolledWindow()
115
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
116
gtk.POLICY_AUTOMATIC)
117
self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
108
super(TreeView, self).__init__(homogeneous=False, spacing=0)
110
self.progress_widget = ProgressPanel()
111
self.pack_start(self.progress_widget, False, True, 0)
112
if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
113
# We'are using our own ui, let's tell it to use our widget.
114
ui.ui_factory.set_progress_bar_widget(self.progress_widget)
116
self.scrolled_window = Gtk.ScrolledWindow()
117
self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
118
Gtk.PolicyType.AUTOMATIC)
119
self.scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
118
120
self.scrolled_window.show()
119
self.pack_start(self.scrolled_window, expand=True, fill=True)
121
self.pack_start(self.scrolled_window, True, True, 0)
121
123
self.scrolled_window.add(self.construct_treeview())
125
126
self.branch = branch
126
127
self.revision = None
128
130
self.start = start
129
131
self.maxnum = maxnum
130
132
self.compact = compact
132
gobject.idle_add(self.populate)
134
self.connect("destroy", lambda x: self.branch.unlock())
134
self.model = treemodel.BranchTreeModel(self.branch, [])
135
GObject.idle_add(self.populate)
137
self.connect("destroy", self._on_destroy)
139
def _on_destroy(self, *ignored):
141
if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
142
# We'are using our own ui, let's tell it to stop using our widget.
143
ui.ui_factory.set_progress_bar_widget(None)
136
145
def do_get_property(self, property):
137
146
if property.name == 'revno-column-visible':
276
297
should be broken.
280
broken_line_length = 32
282
broken_line_length = None
284
show_graph = self.graph_column.get_visible()
286
self.branch.lock_read()
287
(linegraphdata, index, columns_len) = linegraph(self.branch.repository,
294
self.model = TreeModel(self.branch, linegraphdata)
295
self.graph_cell.columns_len = columns_len
296
width = self.graph_cell.get_size(self.treeview)[2]
299
self.graph_column.set_fixed_width(width)
300
self.graph_column.set_max_width(width)
302
self.treeview.set_model(self.model)
305
self.treeview.set_cursor(0)
307
self.set_revision(revision)
309
self.emit('revisions-loaded')
300
if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
301
# We'are using our own ui, let's tell it to use our widget.
302
ui.ui_factory.set_progress_bar_widget(self.progress_widget)
303
self.progress_bar = ui.ui_factory.nested_progress_bar()
304
self.progress_bar.update("Loading ancestry graph", 0, 5)
308
broken_line_length = 32
310
broken_line_length = None
312
show_graph = self.graph_column.get_visible()
314
self.branch.lock_read()
315
(linegraphdata, index, columns_len) = linegraph(
316
self.branch.repository.get_graph(),
324
self.model.set_line_graph_data(linegraphdata)
325
self.graph_cell.columns_len = columns_len
326
width = self.graph_cell.get_preferred_width(self.treeview)[1]
330
# The get_preferred_width() call got an insane value.
332
self.graph_column.set_fixed_width(width)
333
self.graph_column.set_max_width(width)
335
self.treeview.set_model(self.model)
337
if not revision or revision == NULL_REVISION:
338
self.treeview.set_cursor(Gtk.TreePath(path=0), None, False)
340
self.set_revision(revision)
342
self.emit('refreshed')
345
self.progress_bar.finished()
313
347
def construct_treeview(self):
314
self.treeview = gtk.TreeView()
348
self.treeview = Gtk.TreeView()
316
350
self.treeview.set_rules_hint(True)
317
self.treeview.set_search_column(treemodel.REVNO)
319
# Fix old PyGTK bug - by JAM
320
set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
321
if set_tooltip is not None:
322
set_tooltip(treemodel.MESSAGE)
351
# combined revno/summary interactive search
353
# the row in a treemodel is considered "matched" if a REVNO *starts*
354
# from the key (that is the key is found in a REVNO at the offset 0)
355
# or if a MESSAGE *contains* the key anywhere (that is, the key is
356
# found case insensitively in a MESSAGE at any offset)
357
def search_equal_func(model, column, key, iter, ignored):
358
return (model.get_value(iter, treemodel.REVNO).find(key) != 0
359
and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
361
self.treeview.set_search_equal_func(search_equal_func, None)
362
self.treeview.set_enable_search(True)
364
self.treeview.set_tooltip_column(treemodel.MESSAGE)
365
self.treeview.set_headers_visible(True)
367
self._prev_cursor_path = None
324
368
self.treeview.connect("cursor-changed",
325
369
self._on_selection_changed)
335
379
self.treeview.show()
337
cell = gtk.CellRendererText()
381
cell = Gtk.CellRendererText()
338
382
cell.set_property("width-chars", 15)
339
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
340
self.revno_column = gtk.TreeViewColumn("Revision No")
383
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
384
self.revno_column = Gtk.TreeViewColumn("Revision No")
341
385
self.revno_column.set_resizable(True)
342
self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
343
self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
344
self.revno_column.pack_start(cell, expand=True)
386
self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
387
self.revno_column.set_fixed_width(
388
cell.get_preferred_width(self.treeview)[1])
389
self.revno_column.pack_start(cell, True)
345
390
self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
346
391
self.treeview.append_column(self.revno_column)
348
393
self.graph_cell = CellRendererGraph()
349
self.graph_column = gtk.TreeViewColumn()
394
self.graph_column = Gtk.TreeViewColumn()
350
395
self.graph_column.set_resizable(True)
351
self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
352
self.graph_column.pack_start(self.graph_cell, expand=False)
353
self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
354
self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
355
self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
356
self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
396
self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
397
self.graph_column.pack_start(self.graph_cell, True)
398
self.graph_column.add_attribute(
399
self.graph_cell, "node", treemodel.NODE)
400
self.graph_column.add_attribute(
401
self.graph_cell, "tags", treemodel.TAGS)
402
self.graph_column.add_attribute(
403
self.graph_cell, "in-lines", treemodel.LAST_LINES)
404
self.graph_column.add_attribute(
405
self.graph_cell, "out-lines", treemodel.LINES)
357
406
self.treeview.append_column(self.graph_column)
359
cell = gtk.CellRendererText()
408
cell = Gtk.CellRendererText()
360
409
cell.set_property("width-chars", 65)
361
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
362
self.summary_column = gtk.TreeViewColumn("Summary")
410
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
411
self.summary_column = Gtk.TreeViewColumn("Summary")
363
412
self.summary_column.set_resizable(True)
364
self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
365
self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
366
self.summary_column.pack_start(cell, expand=True)
413
self.summary_column.set_expand(True)
414
self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
415
self.summary_column.set_fixed_width(
416
cell.get_preferred_width(self.treeview)[1])
417
self.summary_column.pack_start(cell, True)
367
418
self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
368
419
self.treeview.append_column(self.summary_column)
370
cell = gtk.CellRendererText()
421
cell = Gtk.CellRendererText()
371
422
cell.set_property("width-chars", 15)
372
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
373
self.committer_column = gtk.TreeViewColumn("Committer")
374
self.committer_column.set_resizable(True)
375
self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
376
self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
377
self.committer_column.pack_start(cell, expand=True)
378
self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
379
self.treeview.append_column(self.committer_column)
423
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
424
self.authors_column = Gtk.TreeViewColumn("Author(s)")
425
self.authors_column.set_resizable(False)
426
self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
427
self.authors_column.set_fixed_width(200)
428
self.authors_column.pack_start(cell, True)
429
self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
430
self.treeview.append_column(self.authors_column)
381
cell = gtk.CellRendererText()
432
cell = Gtk.CellRendererText()
382
433
cell.set_property("width-chars", 20)
383
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
384
self.date_column = gtk.TreeViewColumn("Date")
434
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
435
self.date_column = Gtk.TreeViewColumn("Date")
385
436
self.date_column.set_visible(False)
386
437
self.date_column.set_resizable(True)
387
self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
388
self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
389
self.date_column.pack_start(cell, expand=True)
438
self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
439
self.date_column.set_fixed_width(130)
440
self.date_column.pack_start(cell, True)
390
441
self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
391
442
self.treeview.append_column(self.date_column)
393
444
return self.treeview
395
def construct_loading_msg(self):
396
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
397
gtk.ICON_SIZE_BUTTON)
400
label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
401
label_loading.set_alignment(0.0, 0.5)
404
self.loading_msg_box = gtk.HBox()
405
self.loading_msg_box.set_spacing(5)
406
self.loading_msg_box.set_border_width(5)
407
self.loading_msg_box.pack_start(image_loading, False, False)
408
self.loading_msg_box.pack_start(label_loading, True, True)
409
self.loading_msg_box.show()
411
return self.loading_msg_box
413
446
def _on_selection_changed(self, treeview):
414
447
"""callback for when the treeview changes."""
415
448
(path, focus) = treeview.get_cursor()
417
self.iter = self.model.get_iter(path)
449
if (path is not None) and (path != self._prev_cursor_path):
450
self._prev_cursor_path = path # avoid emitting twice per click
418
452
self.emit('revision-selected')
420
454
def _on_revision_selected(self, widget, event):
421
from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
455
from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
422
456
if event.button == 3:
423
menu = RevisionPopupMenu(self.branch.repository,
424
[self.get_revision().revision_id],
458
rev = self.get_revision()
460
revs.append(rev.revision_id)
461
menu = RevisionMenu(self.branch.repository, revs, self.branch)
426
462
menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
427
menu.popup(None, None, None, event.button, event.get_time())
463
menu.popup(None, None, None, None, event.button, event.get_time())
429
465
def _on_revision_activated(self, widget, path, col):
430
466
self.emit('revision-activated', path, col)