/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
671.1.2 by David Roberts
Further consequential changes for PyGtk-2.8
417
            if getattr(self.prev_button, 'set_menu', None) is not None:
418
		self.prev_button.set_menu(prev_menu)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
419
420
            next_menu = gtk.Menu()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
421
            if len(children) > 0:
386 by Daniel Schierbeck
Created a single action for Next Revision.
422
                self.next_rev_action.set_sensitive(True)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
423
                for child_id in children:
424
                    child = self.branch.repository.get_revision(child_id)
355 by Daniel Schierbeck
Appended branch nick to parent and child popup menus.
425
                    try:
426
                        str = ' (' + child.properties['branch-nick'] + ')'
427
                    except KeyError:
428
                        str = ""
429
430
                    item = gtk.MenuItem(child.message.split("\n")[0] + str)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
431
                    item.connect('activate', self._set_revision_cb, child_id)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
432
                    next_menu.add(item)
433
                next_menu.show_all()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
434
            else:
386 by Daniel Schierbeck
Created a single action for Next Revision.
435
                self.next_rev_action.set_sensitive(False)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
436
                next_menu.hide()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
437
671.1.2 by David Roberts
Further consequential changes for PyGtk-2.8
438
            if getattr(self.next_button, 'set_menu', None) is not None:
439
		self.next_button.set_menu(next_menu)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
440
412.1.13 by Daniel Schierbeck
Re-added support for displaying the children of a revision.
441
            self.revisionview.set_revision(revision)
442
            self.revisionview.set_children(children)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
443
            self.update_diff_panel(revision, parents)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
444
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
445
    def _tree_revision_activated(self, widget, path, col):
446
        # TODO: more than one parent
447
        """Callback for when a treeview row gets activated."""
448
        revision = self.treeview.get_revision()
449
        parents  = self.treeview.get_parents()
450
451
        if len(parents) == 0:
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
452
            parent_id = NULL_REVISION
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
453
        else:
454
            parent_id = parents[0]
455
456
        self.show_diff(revision.revision_id, parent_id)
457
        self.treeview.grab_focus()
463.3.1 by Javier Derderian
Fixed menu entry 'View Changes'. Bug #215350
458
        
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
459
    def _back_clicked_cb(self, *args):
460
        """Callback for when the back button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
461
        self.treeview.back()
462
        
5 by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually
463
    def _fwd_clicked_cb(self, *args):
464
        """Callback for when the forward button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
465
        self.treeview.forward()
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
466
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
467
    def _go_clicked_cb(self, w, p):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
468
        """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().
469
        if self.revisionview.get_revision() is not None:
470
            self.treeview.set_revision(self.revisionview.get_revision())
152 by Jelmer Vernooij
Cleanup some more code.
471
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
472
    def _show_clicked_cb(self, revid, parentid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
473
        """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.
474
        self.show_diff(revid, parentid)
13 by Scott James Remnant
Keep the focus on the treeview
475
        self.treeview.grab_focus()
46 by Wouter van Heyst
show diff on row activation, LP# 44591
476
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
477
    def _set_revision_cb(self, w, revision_id):
356 by Daniel Schierbeck
Made revision a property on TreeView.
478
        self.treeview.set_revision_id(revision_id)
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
479
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
480
    def _brokenlines_toggled_cb(self, button):
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
481
        self.compact_view = button.get_active()
482
483
        if self.compact_view:
484
            option = 'yes'
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
485
        else:
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
486
            option = 'no'
487
488
        self.config.set_user_option('viz-compact-view', option)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
489
        self.treeview.set_property('compact', self.compact_view)
490
        self.treeview.refresh()
368 by Daniel Schierbeck
Merged with mainline.
491
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
492
    def _branch_index_cb(self, w):
493
        from bzrlib.plugins.search import index as _mod_index
494
        _mod_index.index_url(self.branch.base)
495
524 by Jelmer Vernooij
Add search dialog.
496
    def _branch_search_cb(self, w):
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
497
        from bzrlib.plugins.search import index as _mod_index
524 by Jelmer Vernooij
Add search dialog.
498
        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.
499
        from bzrlib.plugins.search import errors as search_errors
500
501
        try:
502
            index = _mod_index.open_index_url(self.branch.base)
503
        except search_errors.NoSearchIndex:
504
            dialog = gtk.MessageDialog(self, type=gtk.MESSAGE_QUESTION, 
505
                buttons=gtk.BUTTONS_OK_CANCEL, 
506
                message_format="This branch has not been indexed yet. "
507
                               "Index now?")
508
            if dialog.run() == gtk.RESPONSE_OK:
553 by Jelmer Vernooij
Merge asking the user whether to create an index.
509
                dialog.destroy()
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
510
                index = _mod_index.index_url(self.branch.base)
511
            else:
553 by Jelmer Vernooij
Merge asking the user whether to create an index.
512
                dialog.destroy()
533.11.1 by Jelmer Vernooij
Ask user whether to index if there is no index present yet.
513
                return
514
515
        dialog = SearchDialog(index)
526 by Jelmer Vernooij
Switch to found revision when clicking ok in search window.
516
        
517
        if dialog.run() == gtk.RESPONSE_OK:
518
            self.set_revision(dialog.get_revision())
519
520
        dialog.destroy()
524 by Jelmer Vernooij
Add search dialog.
521
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
522
    def _about_dialog_cb(self, w):
523
        from bzrlib.plugins.gtk.about import AboutDialog
524
525
        AboutDialog().run()
526
348 by Daniel Schierbeck
Added toggle item for revision number column.
527
    def _col_visibility_changed(self, col, property):
373 by Daniel Schierbeck
Made column display options persisted.
528
        self.config.set_user_option(property + '-column-visible', col.get_active())
348 by Daniel Schierbeck
Added toggle item for revision number column.
529
        self.treeview.set_property(property + '-column-visible', col.get_active())
351 by Daniel Schierbeck
Added option to hide the toolbar.
530
531
    def _toolbar_visibility_changed(self, col):
532
        if col.get_active():
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
533
            self.toolbar.show()
351 by Daniel Schierbeck
Added option to hide the toolbar.
534
        else:
535
            self.toolbar.hide()
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
536
        self.config.set_user_option('viz-toolbar-visible', col.get_active())
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
537
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
538
    def _make_diff_nonzero_size(self):
539
        """make sure the diff isn't zero-width or zero-height"""
540
        alloc = self.diff.get_allocation()
541
        if (alloc.width < 10) or (alloc.height < 10):
542
            width, height = self.get_size()
543
            self.revisionview.set_size_request(width/3, int(height / 2.5))
544
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
545
    def _diff_visibility_changed(self, col):
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
546
        """Hide or show the diff panel."""
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
547
        if col.get_active():
548
            self.diff.show()
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
549
            self._make_diff_nonzero_size()
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
550
        else:
551
            self.diff.hide()
552
        self.config.set_user_option('viz-show-diffs', str(col.get_active()))
553
        self.update_diff_panel()
554
531.7.14 by Scott Scriven
Made diff placement configurable (bottom-right, or bottom full-width).
555
    def _diff_placement_changed(self, col):
556
        """Toggle the diff panel's position."""
557
        self.config.set_user_option('viz-wide-diffs', str(col.get_active()))
558
559
        old = self.paned.get_child2()
560
        self.paned.remove(old)
561
        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
562
        self._make_diff_nonzero_size()
563
564
        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
565
    
566
    def _diff_wrap_changed(self, widget):
567
        """Toggle word wrap in the diff widget."""
568
        self.config.set_user_option('viz-wrap-diffs', widget.get_active())
569
        self.diff._on_wraplines_toggled(widget)
570
    
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
571
    def _show_about_cb(self, w):
572
        dialog = AboutDialog()
573
        dialog.connect('response', lambda d,r: d.destroy())
574
        dialog.run()
404 by Daniel Schierbeck
Made the refresh use proper locking.
575
576
    def _refresh_clicked(self, w):
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
577
        self.treeview.refresh()
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
578
579
    def _update_tags(self):
580
        menu = gtk.Menu()
581
582
        if self.branch.supports_tags():
583
            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.
584
            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.
585
            for tag, revid in tags:
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
586
                tag_image = gtk.Image()
587
                tag_image.set_from_file(icon_path('tag-16.png'))
588
                tag_item = gtk.ImageMenuItem(tag.replace('_', '__'))
589
                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.
590
                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.
591
                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.
592
                menu.add(tag_item)
593
            self.go_menu_tags.set_submenu(menu)
594
595
            self.go_menu_tags.set_sensitive(len(tags) != 0)
596
        else:
597
            self.go_menu_tags.set_sensitive(False)
598
599
        self.go_menu_tags.show_all()
600
531.7.10 by Scott Scriven
Simplified size-loading code. No longer saves identical config every time vis runs.
601
    def _load_size(self, name):
602
        """Read and parse 'name' from self.config.
603
        The value is a string, formatted as WIDTHxHEIGHT
604
        Returns None, or (width, height)
605
        """
606
        size = self.config.get_user_option(name)
607
        if size:
608
            width, height = [int(num) for num in size.split('x')]
609
            # avoid writing config every time we start
610
            return width, height
611
        return None
612
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
613
    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.
614
        """Open a new window to show a diff between the given revisions."""
615
        from bzrlib.plugins.gtk.diff import DiffWindow
616
        window = DiffWindow(parent=self)
617
618
        rev_tree    = self.branch.repository.revision_tree(revid)
619
        parent_tree = self.branch.repository.revision_tree(parentid)
620
630 by Jelmer Vernooij
Use _get_nick(local=True) rather than .nick to get at a branches' nick, since
621
        description = revid + " - " + self.branch._get_nick(local=True)
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
622
        window.set_diff(description, rev_tree, parent_tree)
623
        window.show()
624
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
625
    def update_diff_panel(self, revision=None, parents=None):
626
        """Show the current revision in the diff panel."""
531.7.12 by Scott Scriven
Made diff panel default to off.
627
        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.
628
            return
629
630
        if not revision: # default to selected row
631
            revision = self.treeview.get_revision()
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
632
        if revision == NULL_REVISION:
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
633
            return
634
635
        if not parents: # default to selected row's parents
636
            parents  = self.treeview.get_parents()
637
        if len(parents) == 0:
627 by Jelmer Vernooij
Use NULL_REVISION rather than None.
638
            parent_id = NULL_REVISION
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
639
        else:
640
            parent_id = parents[0]
641
642
        rev_tree    = self.branch.repository.revision_tree(revision.revision_id)
643
        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.
644
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
645
        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
646
        if self.config.get_user_option('viz-wrap-diffs') == 'True':
647
            self.diff._on_wraplines_toggled(wrap=True)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
648
        self.diff.show_all()