/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
1
# -*- coding: UTF-8 -*-
2
"""Revision history view.
3
4
"""
5
486.1.1 by matkor at laptop-hp
Fix for presenting log in olive-gtk.
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
314 by Daniel Schierbeck
Moved branch locking into treeview.
9
import sys
10
import string
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
11
import gtk
12
import gobject
13
import pango
14
import re
303 by Daniel Schierbeck
Made basic signaling work.
15
import treemodel
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
16
from bzrlib import ui
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
17
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
18
from bzrlib.plugins.gtk import _i18n
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
19
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
20
from linegraph import linegraph, same_branch
21
from graphcell import CellRendererGraph
22
from treemodel import TreeModel
330.4.3 by Daniel Schierbeck
Switched to using NULL_REVISION instead of None.
23
from bzrlib.revision import NULL_REVISION
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
24
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
25
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
26
class TreeView(gtk.VBox):
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
27
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
28
    __gproperties__ = {
352 by Daniel Schierbeck
Added branch property to treeview.
29
        'branch': (gobject.TYPE_PYOBJECT,
30
                   'Branch',
31
                   'The Bazaar branch being visualized',
32
                   gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
33
356 by Daniel Schierbeck
Made revision a property on TreeView.
34
        'revision': (gobject.TYPE_PYOBJECT,
35
                     'Revision',
36
                     'The currently selected revision',
37
                     gobject.PARAM_READWRITE),
38
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
39
        'revision-number': (gobject.TYPE_STRING,
40
                            'Revision number',
41
                            'The number of the selected revision',
42
                            '',
43
                            gobject.PARAM_READABLE),
44
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
45
        'children': (gobject.TYPE_PYOBJECT,
46
                     'Child revisions',
47
                     'Children of the currently selected revision',
48
                     gobject.PARAM_READABLE),
49
50
        'parents': (gobject.TYPE_PYOBJECT,
51
                    'Parent revisions',
52
                    'Parents to the currently selected revision',
53
                    gobject.PARAM_READABLE),
54
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
55
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
56
                                 'Revision number column',
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
57
                                 'Show revision number column',
58
                                 True,
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
59
                                 gobject.PARAM_READWRITE),
60
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
61
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
62
                                 'Graph column',
63
                                 'Show graph column',
64
                                 True,
65
                                 gobject.PARAM_READWRITE),
66
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
67
        'date-column-visible': (gobject.TYPE_BOOLEAN,
360 by Daniel Schierbeck
Fixed wrong text in date property.
68
                                 'Date',
69
                                 'Show date column',
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
70
                                 False,
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
71
                                 gobject.PARAM_READWRITE),
72
73
        'compact': (gobject.TYPE_BOOLEAN,
74
                    'Compact view',
75
                    'Break ancestry lines to save space',
76
                    True,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
77
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
78
79
        'mainline-only': (gobject.TYPE_BOOLEAN,
80
                    'Mainline only',
81
                    'Only show the mainline history.',
82
                    False,
83
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
84
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
85
    }
86
307 by Daniel Schierbeck
Made load notification work again.
87
    __gsignals__ = {
345 by Daniel Schierbeck
Made treeview columns instance variables.
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
89
                              gobject.TYPE_NONE,
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
90
                              ()),
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
91
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
92
                              gobject.TYPE_NONE,
93
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
94
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
                              gobject.TYPE_NONE,
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
96
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
97
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
98
                              ())
307 by Daniel Schierbeck
Made load notification work again.
99
    }
100
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
101
    def __init__(self, branch, start, maxnum, compact=True):
322 by Jelmer Vernooij
Add docstrings.
102
        """Create a new TreeView.
103
104
        :param branch: Branch object for branch to show.
105
        :param start: Revision id of top revision.
106
        :param maxnum: Maximum number of revisions to display, 
107
                       None for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
108
        :param broken_line_length: After how much lines to break 
109
                                   branches.
322 by Jelmer Vernooij
Add docstrings.
110
        """
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
111
        gtk.VBox.__init__(self, spacing=0)
112
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
113
        self.progress_widget = ProgressPanel()
114
        self.pack_start(self.progress_widget, expand=False, fill=True)
645.1.5 by Vincent Ladeuil
Integrater Jelmer patch and implement a more robust solution.
115
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
116
            # We'are using our own ui, let's tell it to use our widget.
117
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
118
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
119
        self.scrolled_window = gtk.ScrolledWindow()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
120
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
121
                                        gtk.POLICY_AUTOMATIC)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
122
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
123
        self.scrolled_window.show()
124
        self.pack_start(self.scrolled_window, expand=True, fill=True)
125
126
        self.scrolled_window.add(self.construct_treeview())
303 by Daniel Schierbeck
Made basic signaling work.
127
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
128
        self.path = None
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
129
        self.branch = branch
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
130
        self.revision = None
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
131
        self.index = {}
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
132
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
133
        self.start = start
134
        self.maxnum = maxnum
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
135
        self.compact = compact
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
136
137
        gobject.idle_add(self.populate)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
138
645.1.5 by Vincent Ladeuil
Integrater Jelmer patch and implement a more robust solution.
139
        self.connect("destroy", self._on_destroy)
140
141
    def _on_destroy(self, *ignored):
142
        self.branch.unlock()
143
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
144
            # We'are using our own ui, let's tell it to stop using our widget.
145
            ui.ui_factory.set_progress_bar_widget(None)
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
146
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
147
    def do_get_property(self, property):
148
        if property.name == 'revno-column-visible':
352 by Daniel Schierbeck
Added branch property to treeview.
149
            return self.revno_column.get_visible()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
150
        elif property.name == 'graph-column-visible':
151
            return self.graph_column.get_visible()
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
152
        elif property.name == 'date-column-visible':
153
            return self.date_column.get_visible()
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
154
        elif property.name == 'compact':
155
            return self.compact
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
156
        elif property.name == 'mainline-only':
157
            return self.mainline_only
352 by Daniel Schierbeck
Added branch property to treeview.
158
        elif property.name == 'branch':
159
            return self.branch
356 by Daniel Schierbeck
Made revision a property on TreeView.
160
        elif property.name == 'revision':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
161
            return self.model.get_value(self.model.get_iter(self.path),
162
                                        treemodel.REVISION)
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
163
        elif property.name == 'revision-number':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
164
            return self.model.get_value(self.model.get_iter(self.path),
165
                                        treemodel.REVNO)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
166
        elif property.name == 'children':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
167
            return self.model.get_value(self.model.get_iter(self.path),
168
                                        treemodel.CHILDREN)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
169
        elif property.name == 'parents':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
170
            return self.model.get_value(self.model.get_iter(self.path),
171
                                        treemodel.PARENTS)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
172
        else:
173
            raise AttributeError, 'unknown property %s' % property.name
174
175
    def do_set_property(self, property, value):
176
        if property.name == 'revno-column-visible':
177
            self.revno_column.set_visible(value)
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
178
        elif property.name == 'graph-column-visible':
179
            self.graph_column.set_visible(value)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
180
        elif property.name == 'date-column-visible':
181
            self.date_column.set_visible(value)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
182
        elif property.name == 'compact':
183
            self.compact = value
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
184
        elif property.name == 'mainline-only':
185
            self.mainline_only = value
352 by Daniel Schierbeck
Added branch property to treeview.
186
        elif property.name == 'branch':
187
            self.branch = value
356 by Daniel Schierbeck
Made revision a property on TreeView.
188
        elif property.name == 'revision':
189
            self.set_revision_id(value.revision_id)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
190
        else:
191
            raise AttributeError, 'unknown property %s' % property.name
192
303 by Daniel Schierbeck
Made basic signaling work.
193
    def get_revision(self):
322 by Jelmer Vernooij
Add docstrings.
194
        """Return revision id of currently selected revision, or None."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
195
        return self.get_property('revision')
196
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
197
    def has_revision_id(self, revision_id):
198
        return (revision_id in self.index)
199
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
200
    def set_revision(self, revision):
201
        self.set_property('revision', revision)
303 by Daniel Schierbeck
Made basic signaling work.
202
356 by Daniel Schierbeck
Made revision a property on TreeView.
203
    def set_revision_id(self, revid):
322 by Jelmer Vernooij
Add docstrings.
204
        """Change the currently selected revision.
205
206
        :param revid: Revision id of revision to display.
207
        """
305 by Daniel Schierbeck
Moved revision selection to the new view.
208
        self.treeview.set_cursor(self.index[revid])
209
        self.treeview.grab_focus()
210
303 by Daniel Schierbeck
Made basic signaling work.
211
    def get_children(self):
322 by Jelmer Vernooij
Add docstrings.
212
        """Return the children of the currently selected revision.
213
214
        :return: list of revision ids.
215
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
216
        return self.get_property('children')
303 by Daniel Schierbeck
Made basic signaling work.
217
218
    def get_parents(self):
322 by Jelmer Vernooij
Add docstrings.
219
        """Return the parents of the currently selected revision.
220
221
        :return: list of revision ids.
222
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
223
        return self.get_property('parents')
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
224
225
    def add_tag(self, tag, revid=None):
226
        if revid is None: revid = self.revision.revision_id
227
228
        try:
229
            self.branch.unlock()
230
231
            try:
232
                self.branch.lock_write()
233
                self.model.add_tag(tag, revid)
234
            finally:
235
                self.branch.unlock()
236
237
        finally:
238
            self.branch.lock_read()
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
239
240
        self.emit('tag-added', tag, revid)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
241
        
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
242
    def refresh(self):
243
        gobject.idle_add(self.populate, self.get_revision())
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
244
404 by Daniel Schierbeck
Made the refresh use proper locking.
245
    def update(self):
246
        try:
247
            self.branch.unlock()
248
            try:
249
                self.branch.lock_write()
250
                self.branch.update()
251
            finally:
252
                self.branch.unlock()
253
        finally:
254
            self.branch.lock_read()
255
304 by Daniel Schierbeck
Made forward/back buttons work again.
256
    def back(self):
322 by Jelmer Vernooij
Add docstrings.
257
        """Signal handler for the Back button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
258
        parents = self.get_parents()
304 by Daniel Schierbeck
Made forward/back buttons work again.
259
        if not len(parents):
260
            return
261
262
        for parent_id in parents:
263
            parent_index = self.index[parent_id]
264
            parent = self.model[parent_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
265
            if same_branch(self.get_revision(), parent):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
266
                self.set_revision(parent)
304 by Daniel Schierbeck
Made forward/back buttons work again.
267
                break
268
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
269
            self.set_revision_id(parents[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
270
271
    def forward(self):
322 by Jelmer Vernooij
Add docstrings.
272
        """Signal handler for the Forward button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
273
        children = self.get_children()
304 by Daniel Schierbeck
Made forward/back buttons work again.
274
        if not len(children):
275
            return
276
277
        for child_id in children:
278
            child_index = self.index[child_id]
279
            child = self.model[child_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
280
            if same_branch(child, self.get_revision()):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
281
                self.set_revision(child)
304 by Daniel Schierbeck
Made forward/back buttons work again.
282
                break
283
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
284
            self.set_revision_id(children[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
285
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
286
    def populate(self, revision=None):
322 by Jelmer Vernooij
Add docstrings.
287
        """Fill the treeview with contents.
288
289
        :param start: Revision id of revision to start with.
290
        :param maxnum: Maximum number of revisions to display, or None 
291
                       for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
292
        :param broken_line_length: After how much lines branches \
293
                       should be broken.
322 by Jelmer Vernooij
Add docstrings.
294
        """
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
295
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
296
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
297
            # We'are using our own ui, let's tell it to use our widget.
298
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
299
        self.progress_bar = ui.ui_factory.nested_progress_bar()
576.4.1 by Jelmer Vernooij
Avoid using explicit names for progress bar function arguments since they differ.
300
        self.progress_bar.update("Loading ancestry graph", 0, 5)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
301
302
        try:
303
            if self.compact:
304
                broken_line_length = 32
305
            else:
306
                broken_line_length = None
307
            
308
            show_graph = self.graph_column.get_visible()
309
310
            self.branch.lock_read()
511.5.3 by Jelmer Vernooij
Merge Chad's progress bar in viz patch.
311
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
312
                                                            self.start,
313
                                                            self.maxnum, 
314
                                                            broken_line_length,
315
                                                            show_graph,
475.2.2 by Chad MILLER
Big diff, few changes. :(
316
                                                            self.mainline_only,
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
317
                                                            self.progress_bar)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
318
319
            self.model = TreeModel(self.branch, linegraphdata)
320
            self.graph_cell.columns_len = columns_len
321
            width = self.graph_cell.get_size(self.treeview)[2]
322
            if width > 500:
323
                width = 500
324
            self.graph_column.set_fixed_width(width)
325
            self.graph_column.set_max_width(width)
326
            self.index = index
327
            self.treeview.set_model(self.model)
328
329
            if not revision or revision == NULL_REVISION:
330
                self.treeview.set_cursor(0)
331
            else:
332
                self.set_revision(revision)
333
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
334
            self.emit('refreshed')
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
335
            return False
336
        finally:
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
337
            self.progress_bar.finished()
304 by Daniel Schierbeck
Made forward/back buttons work again.
338
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
339
    def construct_treeview(self):
340
        self.treeview = gtk.TreeView()
341
342
        self.treeview.set_rules_hint(True)
330.1.2 by Daniel Schierbeck
Replaced literal column index with equivalent symbol.
343
        self.treeview.set_search_column(treemodel.REVNO)
330.5.2 by Szilveszter Farkas (Phanatic)
Fixed set_tooltip_column() related issue.
344
        
330.5.5 by Szilveszter Farkas (Phanatic)
Use better fix by John.
345
        # Fix old PyGTK bug - by JAM
346
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
347
        if set_tooltip is not None:
423.4.3 by Daniel Schierbeck
Made the MESSAGE column be the tooltip column.
348
            set_tooltip(treemodel.MESSAGE)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
349
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
350
        self._prev_cursor_path = None
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
351
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
352
                self._on_selection_changed)
353
354
        self.treeview.connect("row-activated", 
355
                self._on_revision_activated)
356
357
        self.treeview.connect("button-release-event", 
358
                self._on_revision_selected)
359
360
        self.treeview.set_property('fixed-height-mode', True)
361
362
        self.treeview.show()
363
364
        cell = gtk.CellRendererText()
365
        cell.set_property("width-chars", 15)
366
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
345 by Daniel Schierbeck
Made treeview columns instance variables.
367
        self.revno_column = gtk.TreeViewColumn("Revision No")
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
368
        self.revno_column.set_resizable(False)
345 by Daniel Schierbeck
Made treeview columns instance variables.
369
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
370
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
371
        self.revno_column.pack_start(cell, expand=True)
372
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
373
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
374
375
        self.graph_cell = CellRendererGraph()
376
        self.graph_column = gtk.TreeViewColumn()
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
377
        self.graph_column.set_resizable(False)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
378
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
379
        self.graph_column.pack_start(self.graph_cell, expand=True)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
380
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
423.5.1 by Ali Sabil
Added tags visualization in the graph
381
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
382
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
383
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
384
        self.treeview.append_column(self.graph_column)
385
386
        cell = gtk.CellRendererText()
387
        cell.set_property("width-chars", 65)
388
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
389
        self.summary_column = gtk.TreeViewColumn("Summary")
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
390
        self.summary_column.set_resizable(False)
391
        self.summary_column.set_expand(True)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
392
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
393
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
394
        self.summary_column.pack_start(cell, expand=True)
395
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
396
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
397
398
        cell = gtk.CellRendererText()
399
        cell.set_property("width-chars", 15)
400
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
345 by Daniel Schierbeck
Made treeview columns instance variables.
401
        self.committer_column = gtk.TreeViewColumn("Committer")
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
402
        self.committer_column.set_resizable(False)
345 by Daniel Schierbeck
Made treeview columns instance variables.
403
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
404
        self.committer_column.set_fixed_width(200)
345 by Daniel Schierbeck
Made treeview columns instance variables.
405
        self.committer_column.pack_start(cell, expand=True)
423.4.4 by Daniel Schierbeck
Renamed COMMITER column into the correct COMMITTER.
406
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
345 by Daniel Schierbeck
Made treeview columns instance variables.
407
        self.treeview.append_column(self.committer_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
408
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
409
        cell = gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
410
        cell.set_property("width-chars", 20)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
411
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
412
        self.date_column = gtk.TreeViewColumn("Date")
413
        self.date_column.set_visible(False)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
414
        self.date_column.set_resizable(False)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
415
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
416
        self.date_column.set_fixed_width(130)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
417
        self.date_column.pack_start(cell, expand=True)
418
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
419
        self.treeview.append_column(self.date_column)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
420
        
421
        return self.treeview
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
422
    
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
423
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
424
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
425
        (path, focus) = treeview.get_cursor()
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
426
        if (path is not None) and (path != self._prev_cursor_path):
427
            self._prev_cursor_path = path # avoid emitting twice per click
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
428
            self.path = path
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
429
            self.emit('revision-selected')
430
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
431
    def _on_revision_selected(self, widget, event):
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
432
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
433
        if event.button == 3:
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
434
            menu = RevisionMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
435
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
436
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
437
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
438
            menu.popup(None, None, None, event.button, event.get_time())
439
440
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
441
        self.emit('revision-activated', path, col)