/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
# -*- coding: UTF-8 -*-
2
"""Branch window.
3
4
This module contains the code to manage the branch information window,
5
which contains both the revision graph and details panes.
6
"""
7
8
__copyright__ = "Copyright © 2005 Canonical Ltd."
9
__author__    = "Scott James Remnant <scott@ubuntu.com>"
10
11
12
import gtk
13
import gobject
14
import pango
15
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
16
from bzrlib.plugins.gtk import icon_path
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
17
from bzrlib.plugins.gtk.branchview import TreeView, treemodel
365 by Daniel Schierbeck
Fixed locks and made tagging work.
18
from bzrlib.plugins.gtk.tags import AddTagDialog
338 by Daniel Schierbeck
Added Preferences menu item.
19
from bzrlib.plugins.gtk.preferences import PreferencesWindow
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
20
from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
21
from bzrlib.plugins.gtk.window import Window
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
22
23
from bzrlib.config import BranchConfig, GlobalConfig
443 by Szilveszter Farkas (Phanatic)
Trivial fix for #149061 (be able to show the diff for revision 1).
24
from bzrlib.revision import Revision, NULL_REVISION
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
25
from bzrlib.trace import mutter
1 by Scott James Remnant
Commit the first version of bzrk.
26
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
27
class BranchWindow(Window):
1 by Scott James Remnant
Commit the first version of bzrk.
28
    """Branch window.
29
30
    This object represents and manages a single window containing information
31
    for a particular branch.
32
    """
33
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
34
    def __init__(self, branch, start_revs, maxnum, parent=None):
322 by Jelmer Vernooij
Add docstrings.
35
        """Create a new BranchWindow.
36
37
        :param branch: Branch object for branch to show.
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
38
        :param start_revs: Revision ids of top revisions.
322 by Jelmer Vernooij
Add docstrings.
39
        :param maxnum: Maximum number of revisions to display, 
40
                       None for no limit.
41
        """
42
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
43
        Window.__init__(self, parent=parent)
1 by Scott James Remnant
Commit the first version of bzrk.
44
        self.set_border_width(0)
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
45
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
46
        self.branch      = branch
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
47
        self.start_revs  = start_revs
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
48
        self.maxnum      = maxnum
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
49
        self.config      = GlobalConfig()
50
51
        if self.config.get_user_option('viz-compact-view') == 'yes':
52
            self.compact_view = True
53
        else:
54
            self.compact_view = False
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
55
56
        self.set_title(branch.nick + " - revision history")
1 by Scott James Remnant
Commit the first version of bzrk.
57
58
        # Use three-quarters of the screen by default
59
        screen = self.get_screen()
4 by Scott James Remnant
Use the size of the first monitor rather than the entire screen
60
        monitor = screen.get_monitor_geometry(0)
61
        width = int(monitor.width * 0.75)
62
        height = int(monitor.height * 0.75)
1 by Scott James Remnant
Commit the first version of bzrk.
63
        self.set_default_size(width, height)
64
65
        # FIXME AndyFitz!
66
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
67
        self.set_icon(icon)
68
384 by Daniel Schierbeck
Added accelerator for Next Revision action.
69
        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.
70
        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
71
        gtk.accel_map_add_entry("<viz>/View/Refresh", gtk.keysyms.F5, 0)
382 by Daniel Schierbeck
Made accelerator for Previous Revision work.
72
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
73
        self.accel_group = gtk.AccelGroup()
74
        self.add_accel_group(self.accel_group)
75
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
76
        gtk.Action.set_tool_item_type(gtk.MenuToolButton)
77
385 by Daniel Schierbeck
Created a single action for Previous Revision.
78
        self.prev_rev_action = gtk.Action("prev-rev", "_Previous Revision", "Go to the previous revision", gtk.STOCK_GO_DOWN)
79
        self.prev_rev_action.set_accel_path("<viz>/Go/Previous Revision")
80
        self.prev_rev_action.set_accel_group(self.accel_group)
81
        self.prev_rev_action.connect("activate", self._back_clicked_cb)
82
        self.prev_rev_action.connect_accelerator()
83
386 by Daniel Schierbeck
Created a single action for Next Revision.
84
        self.next_rev_action = gtk.Action("next-rev", "_Next Revision", "Go to the next revision", gtk.STOCK_GO_UP)
85
        self.next_rev_action.set_accel_path("<viz>/Go/Next Revision")
86
        self.next_rev_action.set_accel_group(self.accel_group)
87
        self.next_rev_action.connect("activate", self._fwd_clicked_cb)
88
        self.next_rev_action.connect_accelerator()
89
499.1.1 by Russ Brown
Added Refresh menu option with keyboard shortcut to viz
90
        self.refresh_action = gtk.Action("refresh", "_Refresh", "Refresh view", gtk.STOCK_REFRESH)
91
        self.refresh_action.set_accel_path("<viz>/View/Refresh")
92
        self.refresh_action.set_accel_group(self.accel_group)
93
        self.refresh_action.connect("activate", self._refresh_clicked)
94
        self.refresh_action.connect_accelerator()
95
1 by Scott James Remnant
Commit the first version of bzrk.
96
        self.construct()
97
369 by Daniel Schierbeck
Fixed bug with compact view toggling.
98
    def set_revision(self, revid):
99
        self.treeview.set_revision_id(revid)
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
100
1 by Scott James Remnant
Commit the first version of bzrk.
101
    def construct(self):
102
        """Construct the window contents."""
331 by Daniel Schierbeck
Added basic menu bar.
103
        vbox = gtk.VBox(spacing=0)
44 by David Allouche
reorganise branch window
104
        self.add(vbox)
105
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
106
        self.paned = gtk.VPaned()
107
        self.paned.pack1(self.construct_top(), resize=True, shrink=False)
108
        self.paned.pack2(self.construct_bottom(), resize=False, shrink=True)
109
        self.paned.show()
358 by Daniel Schierbeck
Generalized the hiding/showing code.
110
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
111
        nav = self.construct_navigation()
112
        menubar = self.construct_menubar()
113
        vbox.pack_start(menubar, expand=False, fill=True)
114
        vbox.pack_start(nav, expand=False, fill=True)
115
369 by Daniel Schierbeck
Fixed bug with compact view toggling.
116
        vbox.pack_start(self.paned, expand=True, fill=True)
117
        vbox.set_focus_child(self.paned)
44 by David Allouche
reorganise branch window
118
119
        vbox.show()
331 by Daniel Schierbeck
Added basic menu bar.
120
121
    def construct_menubar(self):
122
        menubar = gtk.MenuBar()
123
124
        file_menu = gtk.Menu()
334 by Daniel Schierbeck
Added icons to menus.
125
        file_menuitem = gtk.MenuItem("_File")
331 by Daniel Schierbeck
Added basic menu bar.
126
        file_menuitem.set_submenu(file_menu)
127
362 by Daniel Schierbeck
Added accel group to File -> Close menu item.
128
        file_menu_close = gtk.ImageMenuItem(gtk.STOCK_CLOSE, self.accel_group)
331 by Daniel Schierbeck
Added basic menu bar.
129
        file_menu_close.connect('activate', lambda x: self.destroy())
130
        
363 by Daniel Schierbeck
Added File -> Quit menu item.
131
        file_menu_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT, self.accel_group)
132
        file_menu_quit.connect('activate', lambda x: gtk.main_quit())
133
        
408 by Daniel Schierbeck
Made the close menu item actually appear when the viz is opened from another window.
134
        if self._parent is not None:
406 by Daniel Schierbeck
Made the viz show the close menu item only if opened from another window.
135
            file_menu.add(file_menu_close)
363 by Daniel Schierbeck
Added File -> Quit menu item.
136
        file_menu.add(file_menu_quit)
331 by Daniel Schierbeck
Added basic menu bar.
137
338 by Daniel Schierbeck
Added Preferences menu item.
138
        edit_menu = gtk.Menu()
139
        edit_menuitem = gtk.MenuItem("_Edit")
140
        edit_menuitem.set_submenu(edit_menu)
141
340 by Daniel Schierbeck
Added edit->find menu item stub.
142
        edit_menu_find = gtk.ImageMenuItem(gtk.STOCK_FIND)
143
361 by Daniel Schierbeck
Added branch settings menu item.
144
        edit_menu_branchopts = gtk.MenuItem("Branch Settings")
145
        edit_menu_branchopts.connect('activate', lambda x: PreferencesWindow(self.branch.get_config()).show())
146
407 by Daniel Schierbeck
Renamed Preferences menu item into Global Settings.
147
        edit_menu_globopts = gtk.MenuItem("Global Settings")
148
        edit_menu_globopts.connect('activate', lambda x: PreferencesWindow().show())
338 by Daniel Schierbeck
Added Preferences menu item.
149
340 by Daniel Schierbeck
Added edit->find menu item stub.
150
        edit_menu.add(edit_menu_find)
361 by Daniel Schierbeck
Added branch settings menu item.
151
        edit_menu.add(edit_menu_branchopts)
407 by Daniel Schierbeck
Renamed Preferences menu item into Global Settings.
152
        edit_menu.add(edit_menu_globopts)
338 by Daniel Schierbeck
Added Preferences menu item.
153
348 by Daniel Schierbeck
Added toggle item for revision number column.
154
        view_menu = gtk.Menu()
155
        view_menuitem = gtk.MenuItem("_View")
156
        view_menuitem.set_submenu(view_menu)
157
499.1.1 by Russ Brown
Added Refresh menu option with keyboard shortcut to viz
158
        view_menu_refresh = self.refresh_action.create_menu_item()
159
        view_menu_refresh.connect('activate', self._refresh_clicked)
160
161
        view_menu.add(view_menu_refresh)
162
        view_menu.add(gtk.SeparatorMenuItem())
163
351 by Daniel Schierbeck
Added option to hide the toolbar.
164
        view_menu_toolbar = gtk.CheckMenuItem("Show Toolbar")
165
        view_menu_toolbar.set_active(True)
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
166
        if self.config.get_user_option('viz-toolbar-visible') == 'False':
167
            view_menu_toolbar.set_active(False)
168
            self.toolbar.hide()
351 by Daniel Schierbeck
Added option to hide the toolbar.
169
        view_menu_toolbar.connect('toggled', self._toolbar_visibility_changed)
170
370 by Daniel Schierbeck
Moved compact graph toggle to the menubar.
171
        view_menu_compact = gtk.CheckMenuItem("Show Compact Graph")
172
        view_menu_compact.set_active(self.compact_view)
173
        view_menu_compact.connect('activate', self._brokenlines_toggled_cb)
174
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
175
        view_menu_diffs = gtk.CheckMenuItem("Show Diffs")
176
        view_menu_diffs.set_active(True)
177
        if self.config.get_user_option('viz-show-diffs') == 'False':
178
            view_menu_diffs.set_active(False)
179
        view_menu_diffs.connect('toggled', self._diff_visibility_changed)
180
351 by Daniel Schierbeck
Added option to hide the toolbar.
181
        view_menu.add(view_menu_toolbar)
370 by Daniel Schierbeck
Moved compact graph toggle to the menubar.
182
        view_menu.add(view_menu_compact)
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
183
        view_menu.add(view_menu_diffs)
351 by Daniel Schierbeck
Added option to hide the toolbar.
184
        view_menu.add(gtk.SeparatorMenuItem())
358 by Daniel Schierbeck
Generalized the hiding/showing code.
185
452.4.2 by Jelmer Vernooij
Hide revision number column if more than one branch was specified.
186
        self.mnu_show_revno_column = gtk.CheckMenuItem("Show Revision _Number Column")
187
        self.mnu_show_date_column = gtk.CheckMenuItem("Show _Date Column")
188
189
        # Revision numbers are pointless if there are multiple branches
190
        if len(self.start_revs) > 1:
191
            self.mnu_show_revno_column.set_sensitive(False)
192
            self.treeview.set_property('revno-column-visible', False)
193
194
        for (col, name) in [(self.mnu_show_revno_column, "revno"), 
195
                            (self.mnu_show_date_column, "date")]:
358 by Daniel Schierbeck
Generalized the hiding/showing code.
196
            col.set_active(self.treeview.get_property(name + "-column-visible"))
197
            col.connect('toggled', self._col_visibility_changed, name)
198
            view_menu.add(col)
348 by Daniel Schierbeck
Added toggle item for revision number column.
199
331 by Daniel Schierbeck
Added basic menu bar.
200
        go_menu = gtk.Menu()
382 by Daniel Schierbeck
Made accelerator for Previous Revision work.
201
        go_menu.set_accel_group(self.accel_group)
334 by Daniel Schierbeck
Added icons to menus.
202
        go_menuitem = gtk.MenuItem("_Go")
331 by Daniel Schierbeck
Added basic menu bar.
203
        go_menuitem.set_submenu(go_menu)
204
        
390 by Daniel Schierbeck
Made the Previous/Next Revision menu items local variables.
205
        go_menu_next = self.next_rev_action.create_menu_item()
206
        go_menu_prev = self.prev_rev_action.create_menu_item()
334 by Daniel Schierbeck
Added icons to menus.
207
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
208
        tag_image = gtk.Image()
209
        tag_image.set_from_file(icon_path("tag-16.png"))
210
        self.go_menu_tags = gtk.ImageMenuItem("_Tags")
211
        self.go_menu_tags.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.
212
        self._update_tags()
399 by Daniel Schierbeck
Made tags menu insensitive when there are no tags to display.
213
390 by Daniel Schierbeck
Made the Previous/Next Revision menu items local variables.
214
        go_menu.add(go_menu_next)
215
        go_menu.add(go_menu_prev)
334 by Daniel Schierbeck
Added icons to menus.
216
        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.
217
        go_menu.add(self.go_menu_tags)
334 by Daniel Schierbeck
Added icons to menus.
218
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
219
        self.revision_menu = RevisionMenu(self.branch.repository, [], self.branch, parent=self)
335 by Daniel Schierbeck
Added Revision menu.
220
        revision_menuitem = gtk.MenuItem("_Revision")
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
221
        revision_menuitem.set_submenu(self.revision_menu)
335 by Daniel Schierbeck
Added Revision menu.
222
334 by Daniel Schierbeck
Added icons to menus.
223
        branch_menu = gtk.Menu()
224
        branch_menuitem = gtk.MenuItem("_Branch")
225
        branch_menuitem.set_submenu(branch_menu)
226
336 by Daniel Schierbeck
Changed wording to comply with HIG guidelines.
227
        branch_menu.add(gtk.MenuItem("Pu_ll Revisions"))
228
        branch_menu.add(gtk.MenuItem("Pu_sh Revisions"))
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
229
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
230
        try:
231
            from bzrlib.plugins import search
232
        except ImportError:
233
            mutter("Didn't find search plugin")
234
        else:
526 by Jelmer Vernooij
Switch to found revision when clicking ok in search window.
235
            branch_menu.add(gtk.SeparatorMenuItem())
236
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
237
            branch_index_menuitem = gtk.MenuItem("_Index")
238
            branch_index_menuitem.connect('activate', self._branch_index_cb)
239
            branch_menu.add(branch_index_menuitem)
240
524 by Jelmer Vernooij
Add search dialog.
241
            branch_search_menuitem = gtk.MenuItem("_Search")
242
            branch_search_menuitem.connect('activate', self._branch_search_cb)
243
            branch_menu.add(branch_search_menuitem)
244
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
245
        help_menu = gtk.Menu()
246
        help_menuitem = gtk.MenuItem("_Help")
247
        help_menuitem.set_submenu(help_menu)
248
249
        help_about_menuitem = gtk.ImageMenuItem(gtk.STOCK_ABOUT, self.accel_group)
250
        help_about_menuitem.connect('activate', self._about_dialog_cb)
251
252
        help_menu.add(help_about_menuitem)
253
331 by Daniel Schierbeck
Added basic menu bar.
254
        menubar.add(file_menuitem)
338 by Daniel Schierbeck
Added Preferences menu item.
255
        menubar.add(edit_menuitem)
348 by Daniel Schierbeck
Added toggle item for revision number column.
256
        menubar.add(view_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
257
        menubar.add(go_menuitem)
335 by Daniel Schierbeck
Added Revision menu.
258
        menubar.add(revision_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
259
        menubar.add(branch_menuitem)
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
260
        menubar.add(help_menuitem)
331 by Daniel Schierbeck
Added basic menu bar.
261
        menubar.show_all()
262
263
        return menubar
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
264
265
    def construct_top(self):
266
        """Construct the top-half of the window."""
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
267
        # FIXME: Make broken_line_length configurable
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
268
452.4.1 by Jelmer Vernooij
Support displaying multiple tips in viz.
269
        self.treeview = TreeView(self.branch, self.start_revs, self.maxnum, self.compact_view)
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
270
373 by Daniel Schierbeck
Made column display options persisted.
271
        self.treeview.connect('revision-selected',
303 by Daniel Schierbeck
Made basic signaling work.
272
                self._treeselection_changed_cb)
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
273
        self.treeview.connect('revision-activated',
274
                self._tree_revision_activated)
303 by Daniel Schierbeck
Made basic signaling work.
275
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
276
        self.treeview.connect('tag-added', lambda w, t, r: self._update_tags())
277
373 by Daniel Schierbeck
Made column display options persisted.
278
        for col in ["revno", "date"]:
279
            option = self.config.get_user_option(col + '-column-visible')
280
            if option is not None:
281
                self.treeview.set_property(col + '-column-visible', option == 'True')
464.1.1 by Adrian Wilkins
Fixed column visibility properties not loading
282
            else:
283
                self.treeview.set_property(col + '-column-visible', False)
373 by Daniel Schierbeck
Made column display options persisted.
284
1 by Scott James Remnant
Commit the first version of bzrk.
285
        self.treeview.show()
286
375 by Daniel Schierbeck
Fixed crash when toggling compact view.
287
        align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
288
        align.set_padding(5, 0, 0, 0)
289
        align.add(self.treeview)
290
        align.show()
291
292
        return align
44 by David Allouche
reorganise branch window
293
294
    def construct_navigation(self):
295
        """Construct the navigation buttons."""
325 by Daniel Schierbeck
Switched to using a real toolbar for the viz navigation.
296
        self.toolbar = gtk.Toolbar()
297
        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
298
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
299
        self.prev_button = self.prev_rev_action.create_tool_item()
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
300
        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
301
388 by Daniel Schierbeck
Switched to using the Previous/Next Revision actions to create tool buttons.
302
        self.next_button = self.next_rev_action.create_tool_item()
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
303
        self.toolbar.insert(self.next_button, -1)
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
304
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
305
        self.toolbar.insert(gtk.SeparatorToolItem(), -1)
306
307
        refresh_button = gtk.ToolButton(gtk.STOCK_REFRESH)
404 by Daniel Schierbeck
Made the refresh use proper locking.
308
        refresh_button.connect('clicked', self._refresh_clicked)
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
309
        self.toolbar.insert(refresh_button, -1)
310
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
311
        self.toolbar.show_all()
325 by Daniel Schierbeck
Switched to using a real toolbar for the viz navigation.
312
313
        return self.toolbar
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
314
315
    def construct_bottom(self):
316
        """Construct the bottom half of the window."""
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
317
        self.bottom_hpaned = gtk.HPaned()
318
        (width, height) = self.get_size()
319
        self.bottom_hpaned.set_size_request(width, int(height / 2.5))
320
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
321
        from bzrlib.plugins.gtk.revisionview import RevisionView
412.1.2 by Daniel Schierbeck
Moved retrieval of tags into the revisionview itself.
322
        self.revisionview = RevisionView(branch=self.branch)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
323
        self.revisionview.set_size_request(width/3, int(height / 2.5))
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
324
        self.revisionview.show()
325
        self.revisionview.set_show_callback(self._show_clicked_cb)
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
326
        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.
327
        self.treeview.connect('tag-added', lambda w, t, r: self.revisionview.update_tags())
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
328
        self.bottom_hpaned.pack1(self.revisionview)
329
330
        from bzrlib.plugins.gtk.diff import DiffWidget
331
        self.diff = DiffWidget()
332
        self.bottom_hpaned.pack2(self.diff)
333
334
        self.bottom_hpaned.show_all()
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
335
        if self.config.get_user_option('viz-show-diffs') == 'False':
336
            self.diff.hide()
337
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
338
        return self.bottom_hpaned
332 by Daniel Schierbeck
Made tag selection work.
339
340
    def _tag_selected_cb(self, menuitem, revid):
356 by Daniel Schierbeck
Made revision a property on TreeView.
341
        self.treeview.set_revision_id(revid)
341 by Daniel Schierbeck
Merged with trunk.
342
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)
343
    def _treeselection_changed_cb(self, selection, *args):
303 by Daniel Schierbeck
Made basic signaling work.
344
        """callback for when the treeview changes."""
345
        revision = self.treeview.get_revision()
346
        parents  = self.treeview.get_parents()
347
        children = self.treeview.get_children()
348
523.3.2 by Jelmer Vernooij
Share same menu for context menu and main menu.
349
        self.revision_menu.set_revision_ids([revision.revision_id])
350
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
351
        if revision and revision != NULL_REVISION:
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
352
            prev_menu = gtk.Menu()
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
353
            if len(parents) > 0:
385 by Daniel Schierbeck
Created a single action for Previous Revision.
354
                self.prev_rev_action.set_sensitive(True)
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
355
                for parent_id in parents:
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
356
                    if parent_id and parent_id != NULL_REVISION:
357
                        parent = self.branch.repository.get_revision(parent_id)
358
                        try:
359
                            str = ' (' + parent.properties['branch-nick'] + ')'
360
                        except KeyError:
361
                            str = ""
355 by Daniel Schierbeck
Appended branch nick to parent and child popup menus.
362
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
363
                        item = gtk.MenuItem(parent.message.split("\n")[0] + str)
364
                        item.connect('activate', self._set_revision_cb, parent_id)
365
                        prev_menu.add(item)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
366
                prev_menu.show_all()
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
367
            else:
385 by Daniel Schierbeck
Created a single action for Previous Revision.
368
                self.prev_rev_action.set_sensitive(False)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
369
                prev_menu.hide()
370
371
            self.prev_button.set_menu(prev_menu)
372
373
            next_menu = gtk.Menu()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
374
            if len(children) > 0:
386 by Daniel Schierbeck
Created a single action for Next Revision.
375
                self.next_rev_action.set_sensitive(True)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
376
                for child_id in children:
377
                    child = self.branch.repository.get_revision(child_id)
355 by Daniel Schierbeck
Appended branch nick to parent and child popup menus.
378
                    try:
379
                        str = ' (' + child.properties['branch-nick'] + ')'
380
                    except KeyError:
381
                        str = ""
382
383
                    item = gtk.MenuItem(child.message.split("\n")[0] + str)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
384
                    item.connect('activate', self._set_revision_cb, child_id)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
385
                    next_menu.add(item)
386
                next_menu.show_all()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
387
            else:
386 by Daniel Schierbeck
Created a single action for Next Revision.
388
                self.next_rev_action.set_sensitive(False)
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
389
                next_menu.hide()
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
390
376 by Daniel Schierbeck
Changed 'back' into 'prev' and 'fwd' into 'next'.
391
            self.next_button.set_menu(next_menu)
352.1.2 by Daniel Schierbeck
Added dropdown menu to Forward button.
392
412.1.13 by Daniel Schierbeck
Re-added support for displaying the children of a revision.
393
            self.revisionview.set_revision(revision)
394
            self.revisionview.set_children(children)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
395
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
396
            self.update_diff_panel(revision, parents)
531.7.1 by Scott Scriven
Added a diff panel to otherwise-blank area in 'bzr vis'.
397
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
398
    def _tree_revision_activated(self, widget, path, col):
399
        # TODO: more than one parent
400
        """Callback for when a treeview row gets activated."""
401
        revision = self.treeview.get_revision()
402
        parents  = self.treeview.get_parents()
403
404
        if len(parents) == 0:
405
            parent_id = None
406
        else:
407
            parent_id = parents[0]
408
409
        self.show_diff(revision.revision_id, parent_id)
410
        self.treeview.grab_focus()
463.3.1 by Javier Derderian
Fixed menu entry 'View Changes'. Bug #215350
411
        
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
412
    def _back_clicked_cb(self, *args):
413
        """Callback for when the back button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
414
        self.treeview.back()
415
        
5 by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually
416
    def _fwd_clicked_cb(self, *args):
417
        """Callback for when the forward button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
418
        self.treeview.forward()
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
419
412.1.9 by Daniel Schierbeck
Removed the use of RevisionView.set_go_callback().
420
    def _go_clicked_cb(self, w, p):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
421
        """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().
422
        if self.revisionview.get_revision() is not None:
423
            self.treeview.set_revision(self.revisionview.get_revision())
152 by Jelmer Vernooij
Cleanup some more code.
424
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
425
    def _show_clicked_cb(self, revid, parentid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
426
        """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.
427
        self.show_diff(revid, parentid)
13 by Scott James Remnant
Keep the focus on the treeview
428
        self.treeview.grab_focus()
46 by Wouter van Heyst
show diff on row activation, LP# 44591
429
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
430
    def _set_revision_cb(self, w, revision_id):
356 by Daniel Schierbeck
Made revision a property on TreeView.
431
        self.treeview.set_revision_id(revision_id)
352.1.1 by Daniel Schierbeck
Added dropdown menu to Back button.
432
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
433
    def _brokenlines_toggled_cb(self, button):
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
434
        self.compact_view = button.get_active()
435
436
        if self.compact_view:
437
            option = 'yes'
330.2.4 by Daniel Schierbeck
Made use of compact view optional.
438
        else:
330.2.5 by Daniel Schierbeck
Support persistence of compact view option.
439
            option = 'no'
440
441
        self.config.set_user_option('viz-compact-view', option)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
442
        self.treeview.set_property('compact', self.compact_view)
443
        self.treeview.refresh()
368 by Daniel Schierbeck
Merged with mainline.
444
511.6.1 by Jelmer Vernooij
Add Branch/Index option if bzr-search is available.
445
    def _branch_index_cb(self, w):
446
        from bzrlib.plugins.search import index as _mod_index
447
        _mod_index.index_url(self.branch.base)
448
524 by Jelmer Vernooij
Add search dialog.
449
    def _branch_search_cb(self, w):
450
        from bzrlib.plugins.gtk.search import SearchDialog
526 by Jelmer Vernooij
Switch to found revision when clicking ok in search window.
451
        dialog = SearchDialog(self.branch)
452
        
453
        if dialog.run() == gtk.RESPONSE_OK:
454
            self.set_revision(dialog.get_revision())
455
456
        dialog.destroy()
524 by Jelmer Vernooij
Add search dialog.
457
423.9.1 by Daniel Schierbeck
Added Help->About menu item to the viz.
458
    def _about_dialog_cb(self, w):
459
        from bzrlib.plugins.gtk.about import AboutDialog
460
461
        AboutDialog().run()
462
348 by Daniel Schierbeck
Added toggle item for revision number column.
463
    def _col_visibility_changed(self, col, property):
373 by Daniel Schierbeck
Made column display options persisted.
464
        self.config.set_user_option(property + '-column-visible', col.get_active())
348 by Daniel Schierbeck
Added toggle item for revision number column.
465
        self.treeview.set_property(property + '-column-visible', col.get_active())
351 by Daniel Schierbeck
Added option to hide the toolbar.
466
467
    def _toolbar_visibility_changed(self, col):
468
        if col.get_active():
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
469
            self.toolbar.show()
351 by Daniel Schierbeck
Added option to hide the toolbar.
470
        else:
471
            self.toolbar.hide()
531.7.2 by Scott Scriven
Made 'vis' save/load visibility of its toolbar.
472
        self.config.set_user_option('viz-toolbar-visible', col.get_active())
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
473
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
474
    def _diff_visibility_changed(self, col):
475
        if col.get_active():
476
            self.diff.show()
477
        else:
478
            self.diff.hide()
479
        self.config.set_user_option('viz-show-diffs', str(col.get_active()))
480
        self.update_diff_panel()
481
371.1.1 by Daniel Schierbeck
Added About dialog to the viz.
482
    def _show_about_cb(self, w):
483
        dialog = AboutDialog()
484
        dialog.connect('response', lambda d,r: d.destroy())
485
        dialog.run()
404 by Daniel Schierbeck
Made the refresh use proper locking.
486
487
    def _refresh_clicked(self, w):
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
488
        self.treeview.refresh()
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
489
490
    def _update_tags(self):
491
        menu = gtk.Menu()
492
493
        if self.branch.supports_tags():
494
            tags = self.branch.tags.get_tag_dict().items()
495
            tags.sort()
496
            tags.reverse()
497
            for tag, revid in tags:
450.4.1 by Daniel Schierbeck
Added tag icon to branch history window.
498
                tag_image = gtk.Image()
499
                tag_image.set_from_file(icon_path('tag-16.png'))
500
                tag_item = gtk.ImageMenuItem(tag.replace('_', '__'))
501
                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.
502
                tag_item.connect('activate', self._tag_selected_cb, revid)
503
                menu.add(tag_item)
504
            self.go_menu_tags.set_submenu(menu)
505
506
            self.go_menu_tags.set_sensitive(len(tags) != 0)
507
        else:
508
            self.go_menu_tags.set_sensitive(False)
509
510
        self.go_menu_tags.show_all()
511
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
512
    def show_diff(self, revid=None, parentid=None):
513
        """Open a new window to show a diff between the given revisions."""
514
        from bzrlib.plugins.gtk.diff import DiffWindow
515
        window = DiffWindow(parent=self)
516
517
        if parentid is None:
518
            parentid = NULL_REVISION
519
520
        rev_tree    = self.branch.repository.revision_tree(revid)
521
        parent_tree = self.branch.repository.revision_tree(parentid)
522
523
        description = revid + " - " + self.branch.nick
524
        window.set_diff(description, rev_tree, parent_tree)
525
        window.show()
526
423.7.5 by Daniel Schierbeck
Made the revision history window update the Go->Tags menu when a tag is added.
527
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
528
    def update_diff_panel(self, revision=None, parents=None):
529
        """Show the current revision in the diff panel."""
530
        if self.config.get_user_option('viz-show-diffs') == 'False':
531
            return
532
533
        if not revision: # default to selected row
534
            revision = self.treeview.get_revision()
535
        if (not revision) or (revision == NULL_REVISION):
536
            return
537
538
        if not parents: # default to selected row's parents
539
            parents  = self.treeview.get_parents()
540
        if len(parents) == 0:
541
            parent_id = None
542
        else:
543
            parent_id = parents[0]
544
545
        rev_tree    = self.branch.repository.revision_tree(revision.revision_id)
546
        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.
547
531.7.3 by Scott Scriven
Added an option to show/hide the diff panel.
548
        self.diff.set_diff(rev_tree, parent_tree)
549
        self.diff.show_all()