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