/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to viz/branchwin.py

  • Committer: Jelmer Vernooij
  • Author(s): Ximin Luo
  • Date: 2011-02-18 16:58:04 UTC
  • mto: This revision was merged to the branch mainline in revision 731.
  • Revision ID: jelmer@samba.org-20110218165804-t0uluis3kwbs8bec
Add option to use 'bzr viz' with a vertical layout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        self.refresh_action.connect("activate", self._refresh_clicked)
99
99
        self.refresh_action.connect_accelerator()
100
100
 
101
 
        self.construct()
 
101
        self.vbox = self.construct()
102
102
 
103
103
    def _save_size_on_destroy(self, widget, config_name):
104
104
        """Creates a hook that saves the size of widget to config option 
117
117
        vbox = gtk.VBox(spacing=0)
118
118
        self.add(vbox)
119
119
 
120
 
        self.paned = gtk.VPaned()
121
 
        self.paned.pack1(self.construct_top(), resize=False, shrink=True)
122
 
        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
123
 
        self.paned.show()
124
 
 
 
120
        # order is important here
 
121
        paned = self.construct_paned()
125
122
        nav = self.construct_navigation()
126
123
        menubar = self.construct_menubar()
 
124
 
127
125
        vbox.pack_start(menubar, expand=False, fill=True)
128
126
        vbox.pack_start(nav, expand=False, fill=True)
129
 
 
130
 
        vbox.pack_start(self.paned, expand=True, fill=True)
131
 
        vbox.set_focus_child(self.paned)
 
127
        vbox.pack_start(paned, expand=True, fill=True)
 
128
        vbox.set_focus_child(paned)
132
129
 
133
130
        self.treeview.connect('revision-selected',
134
131
                self._treeselection_changed_cb)
138
135
        self.treeview.connect('tag-added', lambda w, t, r: self._update_tags())
139
136
        vbox.show()
140
137
 
 
138
        return vbox
 
139
 
 
140
    def construct_paned(self):
 
141
        """Construct the main HPaned/VPaned contents."""
 
142
        if self.config.get_user_option('viz-vertical') == 'True':
 
143
            self.paned = gtk.HPaned()
 
144
        else:
 
145
            self.paned = gtk.VPaned()
 
146
 
 
147
        self.paned.pack1(self.construct_top(), resize=False, shrink=True)
 
148
        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
 
149
        self.paned.show()
 
150
 
 
151
        return self.paned
 
152
 
141
153
    def construct_menubar(self):
142
154
        menubar = gtk.MenuBar()
143
155
 
189
201
        view_menu_compact.set_active(self.compact_view)
190
202
        view_menu_compact.connect('activate', self._brokenlines_toggled_cb)
191
203
 
 
204
        view_menu_vertical = gtk.CheckMenuItem("Side-by-side Layout")
 
205
        view_menu_vertical.set_active(False)
 
206
        if self.config.get_user_option('viz-vertical') == 'True':
 
207
            view_menu_vertical.set_active(True)
 
208
        view_menu_vertical.connect('toggled', self._vertical_layout)
 
209
 
192
210
        view_menu_diffs = gtk.CheckMenuItem("Show Diffs")
193
211
        view_menu_diffs.set_active(False)
194
212
        if self.config.get_user_option('viz-show-diffs') == 'True':
209
227
 
210
228
        view_menu.add(view_menu_toolbar)
211
229
        view_menu.add(view_menu_compact)
 
230
        view_menu.add(view_menu_vertical)
212
231
        view_menu.add(gtk.SeparatorMenuItem())
213
232
        view_menu.add(view_menu_diffs)
214
233
        view_menu.add(view_menu_wide_diffs)
531
550
            self.toolbar.hide()
532
551
        self.config.set_user_option('viz-toolbar-visible', col.get_active())
533
552
 
 
553
    def _vertical_layout(self, col):
 
554
        """Toggle the layout vertical/horizontal"""
 
555
        self.config.set_user_option('viz-vertical', str(col.get_active()))
 
556
 
 
557
        old = self.paned
 
558
        self.vbox.remove(old)
 
559
        self.vbox.pack_start(self.construct_paned(), expand=True, fill=True)
 
560
        self._make_diff_paned_nonzero_size()
 
561
        self._make_diff_nonzero_size()
 
562
 
 
563
        self.treeview.emit('revision-selected')
 
564
 
 
565
    def _make_diff_paned_nonzero_size(self):
 
566
        """make sure the diff/revision pane isn't zero-width or zero-height"""
 
567
        alloc = self.diff_paned.get_allocation()
 
568
        if (alloc.width < 10) or (alloc.height < 10):
 
569
            width, height = self.get_size()
 
570
            self.diff_paned.set_size_request(width/3, int(height / 2.5))
 
571
 
534
572
    def _make_diff_nonzero_size(self):
535
573
        """make sure the diff isn't zero-width or zero-height"""
536
574
        alloc = self.diff.get_allocation()