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