6
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 bzrlib.plugins.gtk import _i18n
18
from linegraph import linegraph, same_branch
19
from graphcell import CellRendererGraph
20
from treemodel import TreeModel
21
14
from bzrlib.revision import NULL_REVISION
23
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):
25
25
__gproperties__ = {
26
'branch': (gobject.TYPE_PYOBJECT,
26
'branch': (GObject.TYPE_PYOBJECT,
28
28
'The Bazaar branch being visualized',
29
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
29
GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE),
31
'revision': (gobject.TYPE_PYOBJECT,
31
'revision': (GObject.TYPE_PYOBJECT,
33
33
'The currently selected revision',
34
gobject.PARAM_READWRITE),
34
GObject.PARAM_READWRITE),
36
'revision-number': (gobject.TYPE_STRING,
36
'revision-number': (GObject.TYPE_STRING,
38
38
'The number of the selected revision',
40
gobject.PARAM_READABLE),
40
GObject.PARAM_READABLE),
42
'children': (gobject.TYPE_PYOBJECT,
42
'children': (GObject.TYPE_PYOBJECT,
44
44
'Children of the currently selected revision',
45
gobject.PARAM_READABLE),
45
GObject.PARAM_READABLE),
47
'parents': (gobject.TYPE_PYOBJECT,
47
'parents': (GObject.TYPE_PYOBJECT,
48
48
'Parent revisions',
49
49
'Parents to the currently selected revision',
50
gobject.PARAM_READABLE),
50
GObject.PARAM_READABLE),
52
'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
'revno-column-visible': (GObject.TYPE_BOOLEAN,
53
53
'Revision number column',
54
54
'Show revision number column',
56
gobject.PARAM_READWRITE),
56
GObject.PARAM_READWRITE),
58
'graph-column-visible': (gobject.TYPE_BOOLEAN,
58
'graph-column-visible': (GObject.TYPE_BOOLEAN,
60
60
'Show graph column',
62
gobject.PARAM_READWRITE),
62
GObject.PARAM_READWRITE),
64
'date-column-visible': (gobject.TYPE_BOOLEAN,
64
'date-column-visible': (GObject.TYPE_BOOLEAN,
66
66
'Show date column',
68
gobject.PARAM_READWRITE),
68
GObject.PARAM_READWRITE),
70
'compact': (gobject.TYPE_BOOLEAN,
70
'compact': (GObject.TYPE_BOOLEAN,
72
72
'Break ancestry lines to save space',
74
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
74
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
76
'mainline-only': (gobject.TYPE_BOOLEAN,
76
'mainline-only': (GObject.TYPE_BOOLEAN,
78
78
'Only show the mainline history.',
80
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
80
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
85
'revisions-loaded': (gobject.SIGNAL_RUN_FIRST,
88
'revision-selected': (gobject.SIGNAL_RUN_FIRST,
85
'revision-selected': (GObject.SignalFlags.RUN_FIRST,
91
'revision-activated': (gobject.SIGNAL_RUN_FIRST,
93
(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
'tag-added': (gobject.SIGNAL_RUN_FIRST,
96
(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,
99
98
def __init__(self, branch, start, maxnum, compact=True):
106
105
:param broken_line_length: After how much lines to break
109
gtk.VBox.__init__(self, spacing=0)
111
self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
112
self.connect('revisions-loaded',
113
lambda x: self.loading_msg_box.hide())
115
self.scrolled_window = gtk.ScrolledWindow()
116
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
117
gtk.POLICY_AUTOMATIC)
118
self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
108
GObject.GObject.__init__(self, spacing=0)
110
self.progress_widget = ProgressPanel()
111
self.pack_start(self.progress_widget, expand=False, fill=True)
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)
119
120
self.scrolled_window.show()
120
121
self.pack_start(self.scrolled_window, expand=True, fill=True)
122
123
self.scrolled_window.add(self.construct_treeview())
126
126
self.branch = branch
127
127
self.revision = None
129
130
self.start = start
130
131
self.maxnum = maxnum
131
132
self.compact = compact
133
gobject.idle_add(self.populate)
135
self.connect("destroy", lambda x: self.branch.unlock())
134
self.model = treemodel.TreeModel(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)
137
145
def do_get_property(self, property):
138
146
if property.name == 'revno-column-visible':
277
296
should be broken.
281
broken_line_length = 32
283
broken_line_length = None
285
show_graph = self.graph_column.get_visible()
287
self.branch.lock_read()
288
(linegraphdata, index, columns_len) = linegraph(self.branch.repository,
289
(self.start,) , # Sequence of start revisions
295
self.model = TreeModel(self.branch, linegraphdata)
296
self.graph_cell.columns_len = columns_len
297
width = self.graph_cell.get_size(self.treeview)[2]
300
self.graph_column.set_fixed_width(width)
301
self.graph_column.set_max_width(width)
303
self.treeview.set_model(self.model)
305
if not revision or revision == NULL_REVISION:
306
self.treeview.set_cursor(0)
308
self.set_revision(revision)
310
self.emit('revisions-loaded')
299
if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
300
# We'are using our own ui, let's tell it to use our widget.
301
ui.ui_factory.set_progress_bar_widget(self.progress_widget)
302
self.progress_bar = ui.ui_factory.nested_progress_bar()
303
self.progress_bar.update("Loading ancestry graph", 0, 5)
307
broken_line_length = 32
309
broken_line_length = None
311
show_graph = self.graph_column.get_visible()
313
self.branch.lock_read()
314
(linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
322
self.model.line_graph_data = linegraphdata
323
self.graph_cell.columns_len = columns_len
324
width = self.graph_cell.get_size(self.treeview)[2]
327
self.graph_column.set_fixed_width(width)
328
self.graph_column.set_max_width(width)
330
self.treeview.set_model(self.model)
332
if not revision or revision == NULL_REVISION:
333
self.treeview.set_cursor(0)
335
self.set_revision(revision)
337
self.emit('refreshed')
340
self.progress_bar.finished()
314
342
def construct_treeview(self):
315
self.treeview = gtk.TreeView()
343
self.treeview = Gtk.TreeView()
317
345
self.treeview.set_rules_hint(True)
318
self.treeview.set_search_column(treemodel.REVNO)
320
# Fix old PyGTK bug - by JAM
321
set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
322
if set_tooltip is not None:
323
set_tooltip(treemodel.MESSAGE)
346
# combined revno/summary interactive search
348
# the row in a treemodel is considered "matched" if a REVNO *starts*
349
# from the key (that is the key is found in a REVNO at the offset 0)
350
# or if a MESSAGE *contains* the key anywhere (that is, the key is
351
# found case insensitively in a MESSAGE at any offset)
352
def search_equal_func(model, column, key, iter):
353
return (model.get_value(iter, treemodel.REVNO).find(key) != 0
354
and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
356
self.treeview.set_search_equal_func(search_equal_func)
357
self.treeview.set_enable_search(True)
359
set_tooltip(treemodel.MESSAGE)
361
self._prev_cursor_path = None
325
362
self.treeview.connect("cursor-changed",
326
363
self._on_selection_changed)
336
373
self.treeview.show()
338
cell = gtk.CellRendererText()
375
cell = Gtk.CellRendererText()
339
376
cell.set_property("width-chars", 15)
340
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
341
self.revno_column = gtk.TreeViewColumn("Revision No")
342
self.revno_column.set_resizable(False)
343
self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
377
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
378
self.revno_column = Gtk.TreeViewColumn("Revision No")
379
self.revno_column.set_resizable(True)
380
self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
344
381
self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
345
self.revno_column.pack_start(cell, expand=True)
382
self.revno_column.pack_start(cell, True, True, 0)
346
383
self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
347
384
self.treeview.append_column(self.revno_column)
349
386
self.graph_cell = CellRendererGraph()
350
self.graph_column = gtk.TreeViewColumn()
351
self.graph_column.set_resizable(False)
352
self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
353
self.graph_column.pack_start(self.graph_cell, expand=True)
387
self.graph_column = Gtk.TreeViewColumn()
388
self.graph_column.set_resizable(True)
389
self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
390
self.graph_column.pack_start(self.graph_cell, True, True, 0)
354
391
self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
355
392
self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
356
393
self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
357
394
self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
358
395
self.treeview.append_column(self.graph_column)
360
cell = gtk.CellRendererText()
397
cell = Gtk.CellRendererText()
361
398
cell.set_property("width-chars", 65)
362
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
363
self.summary_column = gtk.TreeViewColumn("Summary")
364
self.summary_column.set_resizable(False)
399
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
400
self.summary_column = Gtk.TreeViewColumn("Summary")
401
self.summary_column.set_resizable(True)
365
402
self.summary_column.set_expand(True)
366
self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
403
self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
367
404
self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
368
self.summary_column.pack_start(cell, expand=True)
405
self.summary_column.pack_start(cell, True, True, 0)
369
406
self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
370
407
self.treeview.append_column(self.summary_column)
372
cell = gtk.CellRendererText()
409
cell = Gtk.CellRendererText()
373
410
cell.set_property("width-chars", 15)
374
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
375
self.committer_column = gtk.TreeViewColumn("Committer")
376
self.committer_column.set_resizable(False)
377
self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
378
self.committer_column.set_fixed_width(200)
379
self.committer_column.pack_start(cell, expand=True)
380
self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
381
self.treeview.append_column(self.committer_column)
411
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
412
self.authors_column = Gtk.TreeViewColumn("Author(s)")
413
self.authors_column.set_resizable(False)
414
self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
415
self.authors_column.set_fixed_width(200)
416
self.authors_column.pack_start(cell, True, True, 0)
417
self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
418
self.treeview.append_column(self.authors_column)
383
cell = gtk.CellRendererText()
420
cell = Gtk.CellRendererText()
384
421
cell.set_property("width-chars", 20)
385
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
386
self.date_column = gtk.TreeViewColumn("Date")
422
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
423
self.date_column = Gtk.TreeViewColumn("Date")
387
424
self.date_column.set_visible(False)
388
self.date_column.set_resizable(False)
389
self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
425
self.date_column.set_resizable(True)
426
self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
390
427
self.date_column.set_fixed_width(130)
391
self.date_column.pack_start(cell, expand=True)
428
self.date_column.pack_start(cell, True, True, 0)
392
429
self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
393
430
self.treeview.append_column(self.date_column)
395
432
return self.treeview
397
def construct_loading_msg(self):
398
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
399
gtk.ICON_SIZE_BUTTON)
402
label_loading = gtk.Label(
403
_i18n("Please wait, loading ancestral graph..."))
404
label_loading.set_alignment(0.0, 0.5)
407
self.loading_msg_box = gtk.HBox()
408
self.loading_msg_box.set_spacing(5)
409
self.loading_msg_box.set_border_width(5)
410
self.loading_msg_box.pack_start(image_loading, False, False)
411
self.loading_msg_box.pack_start(label_loading, True, True)
412
self.loading_msg_box.show()
414
return self.loading_msg_box
416
434
def _on_selection_changed(self, treeview):
417
435
"""callback for when the treeview changes."""
418
436
(path, focus) = treeview.get_cursor()
420
self.iter = self.model.get_iter(path)
437
if (path is not None) and (path != self._prev_cursor_path):
438
self._prev_cursor_path = path # avoid emitting twice per click
421
440
self.emit('revision-selected')
423
442
def _on_revision_selected(self, widget, event):
424
from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
443
from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
444
if event.button == 3:
426
menu = RevisionPopupMenu(self.branch.repository,
445
menu = RevisionMenu(self.branch.repository,
427
446
[self.get_revision().revision_id],
429
448
menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))