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