/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
1 by Scott James Remnant
Commit the first version of bzrk.
1
"""Branch window.
2
3
This module contains the code to manage the branch information window,
4
which contains both the revision graph and details panes.
5
"""
6
671.2.1 by Vincent Ladeuil
Ensure compatibility with PyGtk-2.8.
7
__copyright__ = "Copyright (c) 2005 Canonical Ltd."
1 by Scott James Remnant
Commit the first version of bzrk.
8
__author__    = "Scott James Remnant <scott@ubuntu.com>"
9
10
11
import gtk
12
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
13
from bzrlib.plugins.gtk import icon_path
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
14
from bzrlib.plugins.gtk.branchview import TreeView
338 by Daniel Schierbeck
Added Preferences menu item.
15
from bzrlib.plugins.gtk.preferences import PreferencesWindow
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
16
from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
17
from bzrlib.plugins.gtk.window import Window
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
18
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
19
from bzrlib.config import GlobalConfig
20
from bzrlib.revision import NULL_REVISION
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
21
from bzrlib.trace import mutter
1 by Scott James Remnant
Commit the first version of bzrk.
22
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
23
class BranchWindow(Window):
1 by Scott James Remnant
Commit the first version of bzrk.
24
    """Branch window.
25
26
    This object represents and manages a single window containing information
27
    for a particular branch.
28
    """
29
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
30
    def __init__(self, branch, start_revs, maxnum, parent=None):
322 by Jelmer Vernooij
Add docstrings.
31
        """Create a new BranchWindow.
32
33
        :param branch: Branch object for branch to show.
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
34
        :param start_revs: Revision ids of top revisions.
322 by Jelmer Vernooij
Add docstrings.
35
        :param maxnum: Maximum number of revisions to display, 
36
                       None for no limit.
37
        """
38
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
39
        Window.__init__(self, parent=parent)
1 by Scott James Remnant
Commit the first version of bzrk.
40
        self.set_border_width(0)
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
41
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
42
        self.branch      = branch
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
43
        self.start_revs  = start_revs
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
44
        self.maxnum      = maxnum
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
45
        self.config      = GlobalConfig()
46
47
        if self.config.get_user_option('viz-compact-view') == 'yes':
48
            self.compact_view = True
49
        else:
50
            self.compact_view = False
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
51
630 by Jelmer Vernooij
Use _get_nick(local=True) rather than .nick to get at a branches' nick, since
52
        self.set_title(branch._get_nick(local=True) + " - revision history")
1 by Scott James Remnant
Commit the first version of bzrk.
53
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
54
        # user-configured window size
531.7.10 by Scott Scriven
Simplified size-loading code. No longer saves identical config every time vis runs.
55
        size = self._load_size('viz-window-size')
56
        if size:
57
            width, height = size
555.2.1 by Jasper Groenewegen
Modify DiffWidget to include a checkbutton to wrap long lines in the diff view
58
        else:
59
            # Use three-quarters of the screen by default
60
            screen = self.get_screen()
61
            monitor = screen.get_monitor_geometry(0)
62
            width = int(monitor.width * 0.75)
63
            height = int(monitor.height * 0.75)
1 by Scott James Remnant
Commit the first version of bzrk.
64
        self.set_default_size(width, height)
531.7.8 by Scott Scriven
Made viz window shrinkable.
65
        self.set_size_request(width/3, height/3)
625.1.8 by Torsten Landschoff
Save widget sizes only when closing the BranchWindow.
66
        self._save_size_on_destroy(self, 'viz-window-size')
1 by Scott James Remnant
Commit the first version of bzrk.
67
68
        # FIXME AndyFitz!
69
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
70
        self.set_icon(icon)
71
384 by Daniel Schierbeck
Added accelerator for Next Revision action.
72
        gtk.accel_map_add_entry("<viz>/Go/Next Revision", gtk.keysyms.Up, gtk.gdk.MOD1_MASK)
383 by Daniel Schierbeck
Switched to using symbolic names for keyvals.
73
        gtk.accel_map_add_entry("<viz>/Go/Previous Revision", gtk.keysyms.Down, gtk.gdk.MOD1_MASK)
499.1.1 by Russ Brown
Added Refresh menu option with keyboard shortcut to viz
74
        gtk.accel_map_add_entry("<viz>/View/Refresh", gtk.keysyms.F5, 0)
382 by Daniel Schierbeck
Made accelerator for Previous Revision work.
75
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
76
        self.accel_group = gtk.AccelGroup()
77
        self.add_accel_group(self.accel_group)
78
671.2.1 by Vincent Ladeuil
Ensure compatibility with PyGtk-2.8.
79
        if getattr(gtk.Action, 'set_tool_item_type', None) is not None:
80
            # Not available before PyGtk-2.10
81
            gtk.Action.set_tool_item_type(gtk.MenuToolButton)
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
82
385 by Daniel Schierbeck
Created a single action for Previous Revision.
83
        self.prev_rev_action = gtk.Action("prev-rev", "_Previous Revision", "Go to the previous revision", gtk.STOCK_GO_DOWN)
84
        self.prev_rev_action.set_accel_path("<viz>/Go/Previous Revision")
85
        self.prev_rev_action.set_accel_group(self.accel_group)
86
        self.prev_rev_action.connect("activate", self._back_clicked_cb)
87
        self.prev_rev_action.connect_accelerator()
88
386 by Daniel Schierbeck
Created a single action for Next Revision.
89
        self.next_rev_action = gtk.Action("next-rev", "_Next Revision", "Go to the next revision", gtk.STOCK_GO_UP)
90
        self.next_rev_action.set_accel_path("<viz>/Go/Next Revision")
91
        self.next_rev_action.set_accel_group(self.accel_group)
92
        self.next_rev_action.connect("activate", self._fwd_clicked_cb)
93
        self.next_rev_action.connect_accelerator()
94
499.1.1 by Russ Brown
Added Refresh menu option with keyboard shortcut to viz
95
        self.refresh_action = gtk.Action("refresh", "_Refresh", "Refresh view", gtk.STOCK_REFRESH)
96
        self.refresh_action.set_accel_path("<viz>/View/Refresh")
97
        self.refresh_action.set_accel_group(self.accel_group)
98
        self.refresh_action.connect("activate", self._refresh_clicked)
99
        self.refresh_action.connect_accelerator()
100
1 by Scott James Remnant
Commit the first version of bzrk.
101
        self.construct()
102
625.1.8 by Torsten Landschoff
Save widget sizes only when closing the BranchWindow.
103
    def _save_size_on_destroy(self, widget, config_name):
104
        """Creates a hook that saves the size of widget to config option 
105
           config_name when the window is destroyed/closed."""
106
        def save_size(src):
107
            width, height = widget.allocation.width, widget.allocation.height
108
            value = '%sx%s' % (width, height)
109
            self.config.set_user_option(config_name, value)
110
        self.connect("destroy", save_size)
111
369 by Daniel Schierbeck
Fixed bug with compact view toggling.
112
    def set_revision(self, revid):
113
        self.treeview.set_revision_id(revid)
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
114
1 by Scott James Remnant
Commit the first version of bzrk.
115
    def construct(self):
116
        """Construct the window contents."""
331 by Daniel Schierbeck
Added basic menu bar.
117
        vbox = gtk.VBox(spacing=0)
44 by David Allouche
reorganise branch window
118
        self.add(vbox)
119
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
120
        self.paned = gtk.VPaned()
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
121
        self.paned.pack1(self.construct_top(), resize=False, shrink=True)
122
        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
123
        self.paned.show()
358 by Daniel Schierbeck
Generalized the hiding/showing code.
124
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
125
        nav = self.construct_navigation()
126
        menubar = self.construct_menubar()
127
        vbox.pack_start(menubar, expand=False, fill=True)
128
        vbox.pack_start(nav, expand=False, fill=True)
129
369 by Daniel Schierbeck
Fixed bug with compact view toggling.
130
        vbox.pack_start(self.paned, expand=True, fill=True)
131
        vbox.set_focus_child(self.paned)
44 by David Allouche
reorganise branch window
132
624 by Jelmer Vernooij
Delay registration of signals to prevent problems when signal handlers use not yet constructed widgets.
133
        self.treeview.connect('revision-selected',
134
                self._treeselection_changed_cb)
135
        self.treeview.connect('revision-activated',
136
                self._tree_revision_activated)
137
138
        self.treeview.connect('tag-added', lambda w, t, r: self._update_tags())
44 by David Allouche
reorganise branch window
139
        vbox.show()
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
140
331 by Daniel Schierbeck
Added basic menu bar.
141
    def construct_menubar(self):
142
        menubar = gtk.MenuBar()
143
144
        file_menu = gtk.Menu()
334 by Daniel Schierbeck
Added icons to menus.
145
        file_menuitem = gtk.MenuItem("_File")
331 by Daniel Schierbeck
Added basic menu bar.
146
        file_menuitem.set_submenu(file_menu)
147
362 by Daniel Schierbeck
Added accel group to File -> Close menu item.
148
        file_menu_close = gtk.ImageMenuItem(gtk.STOCK_CLOSE, self.accel_group)
331 by Daniel Schierbeck
Added basic menu bar.
149
        file_menu_close.connect('activate', lambda x: self.destroy())
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
150
363 by Daniel Schierbeck
Added File -> Quit menu item.
151
        file_menu_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT, self.accel_group)
152
        file_menu_quit.connect('activate', lambda x: gtk.main_quit())
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
153
408 by Daniel Schierbeck
Made the close menu item actually appear when the viz is opened from another window.
154
        if self._parent is not None:
406 by Daniel Schierbeck
Made the viz show the close menu item only if opened from another window.
155
            file_menu.add(file_menu_close)
363 by Daniel Schierbeck
Added File -> Quit menu item.
156
        file_menu.add(file_menu_quit)
331 by Daniel Schierbeck
Added basic menu bar.
157
338 by Daniel Schierbeck
Added Preferences menu item.
158
        edit_menu = gtk.Menu()
159
        edit_menuitem = gtk.MenuItem("_Edit")
160
        edit_menuitem.set_submenu(edit_menu)
161
361 by Daniel Schierbeck
Added branch settings menu item.
162
        edit_menu_branchopts = gtk.MenuItem("Branch Settings")
163
        edit_menu_branchopts.connect('activate', lambda x: PreferencesWindow(self.branch.get_config()).show())
164
407 by Daniel Schierbeck
Renamed Preferences menu item into Global Settings.
165
        edit_menu_globopts = gtk.MenuItem("Global Settings")
166
        edit_menu_globopts.connect('activate', lambda x: PreferencesWindow().show())
338 by Daniel Schierbeck
Added Preferences menu item.
167
361 by Daniel Schierbeck
Added branch settings menu item.
168
        edit_menu.add(edit_menu_branchopts)
407 by Daniel Schierbeck
Renamed Preferences menu item into Global Settings.
169
        edit_menu.add(edit_menu_globopts)
338 by Daniel Schierbeck
Added Preferences menu item.
170
348 by Daniel Schierbeck
Added toggle item for revision number column.
171
        view_menu = gtk.Menu()
172
        view_menuitem = gtk.MenuItem("_View")
173
        view_menuitem.set_submenu(view_menu)
174
499.1.1 by Russ Brown
Added Refresh menu option with keyboard shortcut to viz
175
        view_menu_refresh = self.refresh_action.create_menu_item()
176
        view_menu_refresh.connect('activate', self._refresh_clicked)
177
178
        view_menu.add(view_menu_refresh)
179
        view_menu.add(gtk.SeparatorMenuItem())
180
351 by Daniel Schierbeck
Added option to hide the toolbar.
181
        view_menu_toolbar = gtk.CheckMenuItem("Show Toolbar")
182
        view_menu_toolbar.set_active(True)
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
183
        if self.config.get_user_option('viz-toolbar-visible') == 'False':
184
            view_menu_toolbar.set_active(False)
185
            self.toolbar.hide()
351 by Daniel Schierbeck
Added option to hide the toolbar.
186
        view_menu_toolbar.connect('toggled', self._toolbar_visibility_changed)
187
370 by Daniel Schierbeck
Moved compact graph toggle to the menubar.
188
        view_menu_compact = gtk.CheckMenuItem("Show Compact Graph")
189
        view_menu_compact.set_active(self.compact_view)
190
        view_menu_compact.connect('activate', self._brokenlines_toggled_cb)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
191
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
192
        view_menu_diffs = gtk.CheckMenuItem("Show Diffs")
531.7.12 by Scott Scriven
Made diff panel default to off.
193
        view_menu_diffs.set_active(False)
194
        if self.config.get_user_option('viz-show-diffs') == 'True':
195
            view_menu_diffs.set_active(True)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
196
        view_menu_diffs.connect('toggled', self._diff_visibility_changed)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
197
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
198
        view_menu_wide_diffs = gtk.CheckMenuItem("Wide Diffs")
199
        view_menu_wide_diffs.set_active(False)
200
        if self.config.get_user_option('viz-wide-diffs') == 'True':
201
            view_menu_wide_diffs.set_active(True)
202
        view_menu_wide_diffs.connect('toggled', self._diff_placement_changed)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
203
571 by Jasper Groenewegen
Merge addition of word wrap control to gdiff and visualise windows
204
        view_menu_wrap_diffs = gtk.CheckMenuItem("Wrap _Long Lines in Diffs")
555.2.2 by Jasper Groenewegen
Change from checkbox to menu item in bzr vis, add menu bar + item in gdiff
205
        view_menu_wrap_diffs.set_active(False)
206
        if self.config.get_user_option('viz-wrap-diffs') == 'True':
207
            view_menu_wrap_diffs.set_active(True)
208
        view_menu_wrap_diffs.connect('toggled', self._diff_wrap_changed)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
209
351 by Daniel Schierbeck
Added option to hide the toolbar.
210
        view_menu.add(view_menu_toolbar)
370 by Daniel Schierbeck
Moved compact graph toggle to the menubar.
211
        view_menu.add(view_menu_compact)
555.2.2 by Jasper Groenewegen
Change from checkbox to menu item in bzr vis, add menu bar + item in gdiff
212
        view_menu.add(gtk.SeparatorMenuItem())
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
213
        view_menu.add(view_menu_diffs)
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
214
        view_menu.add(view_menu_wide_diffs)
555.2.2 by Jasper Groenewegen
Change from checkbox to menu item in bzr vis, add menu bar + item in gdiff
215
        view_menu.add(view_menu_wrap_diffs)
351 by Daniel Schierbeck
Added option to hide the toolbar.
216
        view_menu.add(gtk.SeparatorMenuItem())
358 by Daniel Schierbeck
Generalized the hiding/showing code.
217
452.4.2 by Jelmer Vernooij
Hide revision number column if more than one branch was specified.
218
        self.mnu_show_revno_column = gtk.CheckMenuItem("Show Revision _Number Column")
219
        self.mnu_show_date_column = gtk.CheckMenuItem("Show _Date Column")
220
221
        # Revision numbers are pointless if there are multiple branches
222
        if len(self.start_revs) > 1:
223
            self.mnu_show_revno_column.set_sensitive(False)
224
            self.treeview.set_property('revno-column-visible', False)
225
226
        for (col, name) in [(self.mnu_show_revno_column, "revno"), 
227
                            (self.mnu_show_date_column, "date")]:
358 by Daniel Schierbeck
Generalized the hiding/showing code.
228
            col.set_active(self.treeview.get_property(name + "-column-visible"))
229
            col.connect('toggled', self._col_visibility_changed, name)
230
            view_menu.add(col)
348 by Daniel Schierbeck
Added toggle item for revision number column.
231
331 by Daniel Schierbeck
Added basic menu bar.
232
        go_menu = gtk.Menu()
382 by Daniel Schierbeck
Made accelerator for Previous Revision work.
233
        go_menu.set_accel_group(self.accel_group)
334 by Daniel Schierbeck
Added icons to menus.
234
        go_menuitem = gtk.MenuItem("_Go")
331 by Daniel Schierbeck
Added basic menu bar.
235
        go_menuitem.set_submenu(go_menu)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
236
390 by Daniel Schierbeck
Made the Previous/Next Revision menu items local variables.
237
        go_menu_next = self.next_rev_action.create_menu_item()
238
        go_menu_prev = self.prev_rev_action.create_menu_item()
334 by Daniel Schierbeck
Added icons to menus.
239
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
240
        tag_image = gtk.Image()
241
        tag_image.set_from_file(icon_path("tag-16.png"))
242
        self.go_menu_tags = gtk.ImageMenuItem("_Tags")
243
        self.go_menu_tags.set_image(tag_image)
587 by Jelmer Vernooij
Avoid determining tags until tags widget has been added.
244
        self.treeview.connect('refreshed', lambda w: self._update_tags())
399 by Daniel Schierbeck
Made tags menu insensitive when there are no tags to display.
245
390 by Daniel Schierbeck
Made the Previous/Next Revision menu items local variables.
246
        go_menu.add(go_menu_next)
247
        go_menu.add(go_menu_prev)
334 by Daniel Schierbeck
Added icons to menus.
248
        go_menu.add(gtk.SeparatorMenuItem())
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
249
        go_menu.add(self.go_menu_tags)
334 by Daniel Schierbeck
Added icons to menus.
250
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
251
        self.revision_menu = RevisionMenu(self.branch.repository, [], self.branch, parent=self)
335 by Daniel Schierbeck
Added Revision menu.
252
        revision_menuitem = gtk.MenuItem("_Revision")
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
253
        revision_menuitem.set_submenu(self.revision_menu)
335 by Daniel Schierbeck
Added Revision menu.
254
334 by Daniel Schierbeck
Added icons to menus.
255
        branch_menu = gtk.Menu()
256
        branch_menuitem = gtk.MenuItem("_Branch")
257
        branch_menuitem.set_submenu(branch_menu)
258
336 by Daniel Schierbeck
Changed wording to comply with HIG guidelines.
259
        branch_menu.add(gtk.MenuItem("Pu_ll Revisions"))
260
        branch_menu.add(gtk.MenuItem("Pu_sh Revisions"))
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
261
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
262
        try:
263
            from bzrlib.plugins import search
264
        except ImportError:
265
            mutter("Didn't find search plugin")
266
        else:
526 by Jelmer Vernooij
Switch to found revision when clicking ok in search window.
267
            branch_menu.add(gtk.SeparatorMenuItem())
268
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
269
            branch_index_menuitem = gtk.MenuItem("_Index")
270
            branch_index_menuitem.connect('activate', self._branch_index_cb)
271
            branch_menu.add(branch_index_menuitem)
272
524 by Jelmer Vernooij
Add search dialog.
273
            branch_search_menuitem = gtk.MenuItem("_Search")
274
            branch_search_menuitem.connect('activate', self._branch_search_cb)
275
            branch_menu.add(branch_search_menuitem)
276
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
277
        help_menu = gtk.Menu()
278
        help_menuitem = gtk.MenuItem("_Help")
279
        help_menuitem.set_submenu(help_menu)
280
281
        help_about_menuitem = gtk.ImageMenuItem(gtk.STOCK_ABOUT, self.accel_group)
282
        help_about_menuitem.connect('activate', self._about_dialog_cb)
283
284
        help_menu.add(help_about_menuitem)
285
331 by Daniel Schierbeck
Added basic menu bar.
286
        menubar.add(file_menuitem)
338 by Daniel Schierbeck
Added Preferences menu item.
287
        menubar.add(edit_menuitem)
348 by Daniel Schierbeck
Added toggle item for revision number column.
288
        menubar.add(view_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
289
        menubar.add(go_menuitem)
335 by Daniel Schierbeck
Added Revision menu.
290
        menubar.add(revision_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
291
        menubar.add(branch_menuitem)
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
292
        menubar.add(help_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
293
        menubar.show_all()
294
295
        return menubar
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
296
297
    def construct_top(self):
298
        """Construct the top-half of the window."""
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
299
        # FIXME: Make broken_line_length configurable
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
300
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
301
        self.treeview = TreeView(self.branch, self.start_revs, self.maxnum, self.compact_view)
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
302
373 by Daniel Schierbeck
Made column display options persisted.
303
        for col in ["revno", "date"]:
304
            option = self.config.get_user_option(col + '-column-visible')
305
            if option is not None:
306
                self.treeview.set_property(col + '-column-visible', option == 'True')
464.1.1 by Adrian Wilkins
Fixed column visibility properties not loading
307
            else:
308
                self.treeview.set_property(col + '-column-visible', False)
373 by Daniel Schierbeck
Made column display options persisted.
309
1 by Scott James Remnant
Commit the first version of bzrk.
310
        self.treeview.show()
311
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
312
        align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
313
        align.set_padding(5, 0, 0, 0)
314
        align.add(self.treeview)
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
315
        # user-configured size
531.7.10 by Scott Scriven
Simplified size-loading code. No longer saves identical config every time vis runs.
316
        size = self._load_size('viz-graph-size')
317
        if size:
318
            width, height = size
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
319
            align.set_size_request(width, height)
320
        else:
321
            (width, height) = self.get_size()
322
            align.set_size_request(width, int(height / 2.5))
625.1.8 by Torsten Landschoff
Save widget sizes only when closing the BranchWindow.
323
        self._save_size_on_destroy(align, 'viz-graph-size')
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
324
        align.show()
325
326
        return align
44 by David Allouche
reorganise branch window
327
328
    def construct_navigation(self):
329
        """Construct the navigation buttons."""
325 by Daniel Schierbeck
Switched to using a real toolbar for the viz navigation.
330
        self.toolbar = gtk.Toolbar()
331
        self.toolbar.set_style(gtk.TOOLBAR_BOTH_HORIZ)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
332
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
333
        self.prev_button = self.prev_rev_action.create_tool_item()
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
334
        self.toolbar.insert(self.prev_button, -1)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
335
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
336
        self.next_button = self.next_rev_action.create_tool_item()
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
337
        self.toolbar.insert(self.next_button, -1)
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
338
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
339
        self.toolbar.insert(gtk.SeparatorToolItem(), -1)
340
341
        refresh_button = gtk.ToolButton(gtk.STOCK_REFRESH)
404 by Daniel Schierbeck
Made the refresh use proper locking.
342
        refresh_button.connect('clicked', self._refresh_clicked)
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
343
        self.toolbar.insert(refresh_button, -1)
344
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
345
        self.toolbar.show_all()
325 by Daniel Schierbeck
Switched to using a real toolbar for the viz navigation.
346
347
        return self.toolbar
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
348
349
    def construct_bottom(self):
350
        """Construct the bottom half of the window."""
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
351
        if self.config.get_user_option('viz-wide-diffs') == 'True':
352
            self.diff_paned = gtk.VPaned()
353
        else:
354
            self.diff_paned = gtk.HPaned()
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
355
        (width, height) = self.get_size()
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
356
        self.diff_paned.set_size_request(20, 20) # shrinkable
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
357
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
358
        from bzrlib.plugins.gtk.revisionview import RevisionView
412.1.2 by Daniel Schierbeck
Moved retrieval of tags into the revisionview itself.
359
        self.revisionview = RevisionView(branch=self.branch)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
360
        self.revisionview.set_size_request(width/3, int(height / 2.5))
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
361
        # user-configured size
531.7.10 by Scott Scriven
Simplified size-loading code. No longer saves identical config every time vis runs.
362
        size = self._load_size('viz-revisionview-size')
363
        if size:
364
            width, height = size
531.7.9 by Scott Scriven
Made vis remember window and panel sizes.
365
            self.revisionview.set_size_request(width, height)
625.1.8 by Torsten Landschoff
Save widget sizes only when closing the BranchWindow.
366
        self._save_size_on_destroy(self.revisionview, 'viz-revisionview-size')
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
367
        self.revisionview.show()
368
        self.revisionview.set_show_callback(self._show_clicked_cb)
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
369
        self.revisionview.connect('notify::revision', self._go_clicked_cb)
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
370
        self.treeview.connect('tag-added', lambda w, t, r: self.revisionview.update_tags())
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
371
        self.diff_paned.pack1(self.revisionview)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
372
373
        from bzrlib.plugins.gtk.diff import DiffWidget
374
        self.diff = DiffWidget()
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
375
        self.diff_paned.pack2(self.diff)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
376
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
377
        self.diff_paned.show_all()
531.7.12 by Scott Scriven
Made diff panel default to off.
378
        if self.config.get_user_option('viz-show-diffs') != 'True':
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
379
            self.diff.hide()
380
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
381
        return self.diff_paned
332 by Daniel Schierbeck
Made tag selection work.
382
383
    def _tag_selected_cb(self, menuitem, revid):
356 by Daniel Schierbeck
Made revision a property on TreeView.
384
        self.treeview.set_revision_id(revid)
341 by Daniel Schierbeck
Merged with trunk.
385
280.1.2 by Daniel Schierbeck
Switched to handle the 'changed' signal from the treeview's treeselection instead of the 'cursor-changed' signal from the treeview itself, allowing more flexibility (particularly the ability to handle programmatic selections)
386
    def _treeselection_changed_cb(self, selection, *args):
303 by Daniel Schierbeck
Made basic signaling work.
387
        """callback for when the treeview changes."""
388
        revision = self.treeview.get_revision()
389
        parents  = self.treeview.get_parents()
390
        children = self.treeview.get_children()
391
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
392
        self.revision_menu.set_revision_ids([revision.revision_id])
393
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
394
        if revision and revision != NULL_REVISION:
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
395
            prev_menu = gtk.Menu()
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
396
            if len(parents) > 0:
385 by Daniel Schierbeck
Created a single action for Previous Revision.
397
                self.prev_rev_action.set_sensitive(True)
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
398
                for parent_id in parents:
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
399
                    if parent_id and parent_id != NULL_REVISION:
400
                        parent = self.branch.repository.get_revision(parent_id)
401
                        try:
402
                            str = ' (' + parent.properties['branch-nick'] + ')'
403
                        except KeyError:
404
                            str = ""
355 by Daniel Schierbeck
Appended branch nick to parent and child popup menus.
405
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
406
                        item = gtk.MenuItem(parent.message.split("\n")[0] + str)
407
                        item.connect('activate', self._set_revision_cb, parent_id)
408
                        prev_menu.add(item)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
409
                prev_menu.show_all()
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
410
            else:
385 by Daniel Schierbeck
Created a single action for Previous Revision.
411
                self.prev_rev_action.set_sensitive(False)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
412
                prev_menu.hide()
413
671.1.2 by David Roberts
Further consequential changes for PyGtk-2.8
414
            if getattr(self.prev_button, 'set_menu', None) is not None:
415
		self.prev_button.set_menu(prev_menu)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
416
417
            next_menu = gtk.Menu()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
418
            if len(children) > 0:
386 by Daniel Schierbeck
Created a single action for Next Revision.
419
                self.next_rev_action.set_sensitive(True)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
420
                for child_id in children:
421
                    child = self.branch.repository.get_revision(child_id)
355 by Daniel Schierbeck
Appended branch nick to parent and child popup menus.
422
                    try:
423
                        str = ' (' + child.properties['branch-nick'] + ')'
424
                    except KeyError:
425
                        str = ""
426
427
                    item = gtk.MenuItem(child.message.split("\n")[0] + str)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
428
                    item.connect('activate', self._set_revision_cb, child_id)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
429
                    next_menu.add(item)
430
                next_menu.show_all()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
431
            else:
386 by Daniel Schierbeck
Created a single action for Next Revision.
432
                self.next_rev_action.set_sensitive(False)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
433
                next_menu.hide()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
434
671.1.2 by David Roberts
Further consequential changes for PyGtk-2.8
435
            if getattr(self.next_button, 'set_menu', None) is not None:
436
		self.next_button.set_menu(next_menu)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
437
412.1.13 by Daniel Schierbeck
Re-added support for displaying the children of a revision.
438
            self.revisionview.set_revision(revision)
439
            self.revisionview.set_children(children)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
440
            self.update_diff_panel(revision, parents)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
441
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
442
    def _tree_revision_activated(self, widget, path, col):
443
        # TODO: more than one parent
444
        """Callback for when a treeview row gets activated."""
445
        revision = self.treeview.get_revision()
446
        parents  = self.treeview.get_parents()
447
448
        if len(parents) == 0:
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
449
            parent_id = NULL_REVISION
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
450
        else:
451
            parent_id = parents[0]
452
453
        self.show_diff(revision.revision_id, parent_id)
454
        self.treeview.grab_focus()
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
455
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
456
    def _back_clicked_cb(self, *args):
457
        """Callback for when the back button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
458
        self.treeview.back()
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
459
5 by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually
460
    def _fwd_clicked_cb(self, *args):
461
        """Callback for when the forward button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
462
        self.treeview.forward()
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
463
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
464
    def _go_clicked_cb(self, w, p):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
465
        """Callback for when the go button for a parent is clicked."""
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
466
        if self.revisionview.get_revision() is not None:
467
            self.treeview.set_revision(self.revisionview.get_revision())
152 by Jelmer Vernooij
Cleanup some more code.
468
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
469
    def _show_clicked_cb(self, revid, parentid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
470
        """Callback for when the show button for a parent is clicked."""
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
471
        self.show_diff(revid, parentid)
13 by Scott James Remnant
Keep the focus on the treeview
472
        self.treeview.grab_focus()
46 by Wouter van Heyst
show diff on row activation, LP# 44591
473
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
474
    def _set_revision_cb(self, w, revision_id):
356 by Daniel Schierbeck
Made revision a property on TreeView.
475
        self.treeview.set_revision_id(revision_id)
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
476
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
477
    def _brokenlines_toggled_cb(self, button):
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
478
        self.compact_view = button.get_active()
479
480
        if self.compact_view:
481
            option = 'yes'
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
482
        else:
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
483
            option = 'no'
484
485
        self.config.set_user_option('viz-compact-view', option)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
486
        self.treeview.set_property('compact', self.compact_view)
487
        self.treeview.refresh()
368 by Daniel Schierbeck
Merged with mainline.
488
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
489
    def _branch_index_cb(self, w):
490
        from bzrlib.plugins.search import index as _mod_index
491
        _mod_index.index_url(self.branch.base)
492
524 by Jelmer Vernooij
Add search dialog.
493
    def _branch_search_cb(self, w):
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
494
        from bzrlib.plugins.search import index as _mod_index
524 by Jelmer Vernooij
Add search dialog.
495
        from bzrlib.plugins.gtk.search import SearchDialog
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
496
        from bzrlib.plugins.search import errors as search_errors
497
498
        try:
499
            index = _mod_index.open_index_url(self.branch.base)
500
        except search_errors.NoSearchIndex:
501
            dialog = gtk.MessageDialog(self, type=gtk.MESSAGE_QUESTION, 
502
                buttons=gtk.BUTTONS_OK_CANCEL, 
503
                message_format="This branch has not been indexed yet. "
504
                               "Index now?")
505
            if dialog.run() == gtk.RESPONSE_OK:
553 by Jelmer Vernooij
Merge asking the user whether to create an index.
506
                dialog.destroy()
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
507
                index = _mod_index.index_url(self.branch.base)
508
            else:
553 by Jelmer Vernooij
Merge asking the user whether to create an index.
509
                dialog.destroy()
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
510
                return
511
512
        dialog = SearchDialog(index)
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
513
526 by Jelmer Vernooij
Switch to found revision when clicking ok in search window.
514
        if dialog.run() == gtk.RESPONSE_OK:
515
            self.set_revision(dialog.get_revision())
516
517
        dialog.destroy()
524 by Jelmer Vernooij
Add search dialog.
518
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
519
    def _about_dialog_cb(self, w):
520
        from bzrlib.plugins.gtk.about import AboutDialog
521
        AboutDialog().run()
522
348 by Daniel Schierbeck
Added toggle item for revision number column.
523
    def _col_visibility_changed(self, col, property):
373 by Daniel Schierbeck
Made column display options persisted.
524
        self.config.set_user_option(property + '-column-visible', col.get_active())
348 by Daniel Schierbeck
Added toggle item for revision number column.
525
        self.treeview.set_property(property + '-column-visible', col.get_active())
351 by Daniel Schierbeck
Added option to hide the toolbar.
526
527
    def _toolbar_visibility_changed(self, col):
528
        if col.get_active():
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
529
            self.toolbar.show()
351 by Daniel Schierbeck
Added option to hide the toolbar.
530
        else:
531
            self.toolbar.hide()
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
532
        self.config.set_user_option('viz-toolbar-visible', col.get_active())
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
533
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
534
    def _make_diff_nonzero_size(self):
535
        """make sure the diff isn't zero-width or zero-height"""
536
        alloc = self.diff.get_allocation()
537
        if (alloc.width < 10) or (alloc.height < 10):
538
            width, height = self.get_size()
539
            self.revisionview.set_size_request(width/3, int(height / 2.5))
540
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
541
    def _diff_visibility_changed(self, col):
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
542
        """Hide or show the diff panel."""
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
543
        if col.get_active():
544
            self.diff.show()
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
545
            self._make_diff_nonzero_size()
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
546
        else:
547
            self.diff.hide()
548
        self.config.set_user_option('viz-show-diffs', str(col.get_active()))
549
        self.update_diff_panel()
550
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
551
    def _diff_placement_changed(self, col):
552
        """Toggle the diff panel's position."""
553
        self.config.set_user_option('viz-wide-diffs', str(col.get_active()))
554
555
        old = self.paned.get_child2()
556
        self.paned.remove(old)
557
        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
558
        self._make_diff_nonzero_size()
559
560
        self.treeview.emit('revision-selected')
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
561
555.2.2 by Jasper Groenewegen
Change from checkbox to menu item in bzr vis, add menu bar + item in gdiff
562
    def _diff_wrap_changed(self, widget):
563
        """Toggle word wrap in the diff widget."""
564
        self.config.set_user_option('viz-wrap-diffs', widget.get_active())
565
        self.diff._on_wraplines_toggled(widget)
404 by Daniel Schierbeck
Made the refresh use proper locking.
566
567
    def _refresh_clicked(self, w):
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
568
        self.treeview.refresh()
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
569
570
    def _update_tags(self):
571
        menu = gtk.Menu()
572
573
        if self.branch.supports_tags():
574
            tags = self.branch.tags.get_tag_dict().items()
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
575
            tags.sort(reverse=True)
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
576
            for tag, revid in tags:
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
577
                tag_image = gtk.Image()
578
                tag_image.set_from_file(icon_path('tag-16.png'))
579
                tag_item = gtk.ImageMenuItem(tag.replace('_', '__'))
580
                tag_item.set_image(tag_image)
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
581
                tag_item.connect('activate', self._tag_selected_cb, revid)
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
582
                tag_item.set_sensitive(self.treeview.has_revision_id(revid))
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
583
                menu.add(tag_item)
584
            self.go_menu_tags.set_submenu(menu)
585
586
            self.go_menu_tags.set_sensitive(len(tags) != 0)
587
        else:
588
            self.go_menu_tags.set_sensitive(False)
589
590
        self.go_menu_tags.show_all()
591
531.7.10 by Scott Scriven
Simplified size-loading code. No longer saves identical config every time vis runs.
592
    def _load_size(self, name):
593
        """Read and parse 'name' from self.config.
594
        The value is a string, formatted as WIDTHxHEIGHT
595
        Returns None, or (width, height)
596
        """
597
        size = self.config.get_user_option(name)
598
        if size:
599
            width, height = [int(num) for num in size.split('x')]
600
            # avoid writing config every time we start
601
            return width, height
602
        return None
603
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
604
    def show_diff(self, revid=None, parentid=NULL_REVISION):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
605
        """Open a new window to show a diff between the given revisions."""
606
        from bzrlib.plugins.gtk.diff import DiffWindow
607
        window = DiffWindow(parent=self)
608
609
        rev_tree    = self.branch.repository.revision_tree(revid)
610
        parent_tree = self.branch.repository.revision_tree(parentid)
611
630 by Jelmer Vernooij
Use _get_nick(local=True) rather than .nick to get at a branches' nick, since
612
        description = revid + " - " + self.branch._get_nick(local=True)
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
613
        window.set_diff(description, rev_tree, parent_tree)
614
        window.show()
615
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
616
    def update_diff_panel(self, revision=None, parents=None):
617
        """Show the current revision in the diff panel."""
531.7.12 by Scott Scriven
Made diff panel default to off.
618
        if self.config.get_user_option('viz-show-diffs') != 'True':
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
619
            return
620
621
        if not revision: # default to selected row
622
            revision = self.treeview.get_revision()
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
623
        if revision == NULL_REVISION:
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
624
            return
625
626
        if not parents: # default to selected row's parents
627
            parents  = self.treeview.get_parents()
628
        if len(parents) == 0:
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
629
            parent_id = NULL_REVISION
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
630
        else:
631
            parent_id = parents[0]
632
633
        rev_tree    = self.branch.repository.revision_tree(revision.revision_id)
634
        parent_tree = self.branch.repository.revision_tree(parent_id)
531.7.5 by Scott Scriven
Fixed DiffWidget so more than one call to set_diff() will work.
635
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
636
        self.diff.set_diff(rev_tree, parent_tree)
555.2.2 by Jasper Groenewegen
Change from checkbox to menu item in bzr vis, add menu bar + item in gdiff
637
        if self.config.get_user_option('viz-wrap-diffs') == 'True':
638
            self.diff._on_wraplines_toggled(wrap=True)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
639
        self.diff.show_all()