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