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