Rev 549: Merge diff widget in viz. in file:///data/jelmer/bzr-gtk/trunk/

Jelmer Vernooij jelmer at samba.org
Fri Jul 18 13:30:04 BST 2008


At file:///data/jelmer/bzr-gtk/trunk/

------------------------------------------------------------
revno: 549
revision-id: jelmer at samba.org-20080718122956-27468cxu2b613ib8
parent: jelmer at samba.org-20080718110607-v8800mc2q0w7ilj0
parent: ubuntu at toykeeper.net-20080717120633-dmhbbdgdj4lt9k4z
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2008-07-18 14:29:56 +0200
message:
  Merge diff widget in viz.
modified:
  NEWS                           news-20070325173539-3va57o99cz3o57xe-1
  branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
  diff.py                        diffwin.py-20051017070234-cb5c6dc4960142f5
  revisionview.py                logview.py-20051024072750-4d5c28cb73611027
  viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.14
    revision-id: ubuntu at toykeeper.net-20080717120633-dmhbbdgdj4lt9k4z
    parent: ubuntu at toykeeper.net-20080717112426-mqjnn717ja3bqqjt
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-17 06:06:33 -0600
    message:
      Made diff placement configurable (bottom-right, or bottom full-width).
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.13
    revision-id: ubuntu at toykeeper.net-20080717112426-mqjnn717ja3bqqjt
    parent: ubuntu at toykeeper.net-20080717111745-totzk0c0u7xlr1zm
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-17 05:24:26 -0600
    message:
      Removed exception-swallowing hasattr()s.
    modified:
      diff.py                        diffwin.py-20051017070234-cb5c6dc4960142f5
    ------------------------------------------------------------
    revno: 531.7.12
    revision-id: ubuntu at toykeeper.net-20080717111745-totzk0c0u7xlr1zm
    parent: ubuntu at toykeeper.net-20080711173656-vw6n6l9mre3caa18
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-17 05:17:45 -0600
    message:
      Made diff panel default to off.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.11
    revision-id: ubuntu at toykeeper.net-20080711173656-vw6n6l9mre3caa18
    parent: ubuntu at toykeeper.net-20080711172546-vvrbsrf6kiuu1nkv
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Fri 2008-07-11 11:36:56 -0600
    message:
      Added features and fixes to NEWS.
    modified:
      NEWS                           news-20070325173539-3va57o99cz3o57xe-1
    ------------------------------------------------------------
    revno: 531.7.10
    revision-id: ubuntu at toykeeper.net-20080711172546-vvrbsrf6kiuu1nkv
    parent: ubuntu at toykeeper.net-20080711171247-mfacpnxhqiqz0wa7
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Fri 2008-07-11 11:25:46 -0600
    message:
      Simplified size-loading code.  No longer saves identical config every time vis runs.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.9
    revision-id: ubuntu at toykeeper.net-20080711171247-mfacpnxhqiqz0wa7
    parent: ubuntu at toykeeper.net-20080711155007-5f3chr0j0iih9vob
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Fri 2008-07-11 11:12:47 -0600
    message:
      Made vis remember window and panel sizes.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.8
    revision-id: ubuntu at toykeeper.net-20080711155007-5f3chr0j0iih9vob
    parent: ubuntu at toykeeper.net-20080711154632-6pzm4gp06vaudjg4
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Fri 2008-07-11 09:50:07 -0600
    message:
      Made viz window shrinkable.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.7
    revision-id: ubuntu at toykeeper.net-20080711154632-6pzm4gp06vaudjg4
    parent: ubuntu at toykeeper.net-20080710075840-rq7uoardk9ou3bx3
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Fri 2008-07-11 09:46:32 -0600
    message:
      Fixed labels/buttons overflowing their parent widgets.
    modified:
      revisionview.py                logview.py-20051024072750-4d5c28cb73611027
    ------------------------------------------------------------
    revno: 531.7.6
    revision-id: ubuntu at toykeeper.net-20080710075840-rq7uoardk9ou3bx3
    parent: ubuntu at toykeeper.net-20080710073313-cmgny6sfojwby970
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-10 01:58:40 -0600
    message:
      Summarized diff features in NEWS.
    modified:
      NEWS                           news-20070325173539-3va57o99cz3o57xe-1
    ------------------------------------------------------------
    revno: 531.7.5
    revision-id: ubuntu at toykeeper.net-20080710073313-cmgny6sfojwby970
    parent: ubuntu at toykeeper.net-20080710062354-tfrqs1jflq2alkv1
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-10 01:33:13 -0600
    message:
      Fixed DiffWidget so more than one call to set_diff() will work.
      Removed workaround from vis's diff panel.
    modified:
      diff.py                        diffwin.py-20051017070234-cb5c6dc4960142f5
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.4
    revision-id: ubuntu at toykeeper.net-20080710062354-tfrqs1jflq2alkv1
    parent: ubuntu at toykeeper.net-20080710061043-k6ppl18xe81uajq4
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-10 00:23:54 -0600
    message:
      The 'vis' treeview was updating twice per cursor motion.  Fixed.
      (this makes the diff panel less slow)
      The root cause might be a bug in pygtk.  The TreeView widget was 
      emitting 'cursor-changed' twice instead of once, so this patch works 
      around the issue by using only the first event per cursor position.
    modified:
      branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
    ------------------------------------------------------------
    revno: 531.7.3
    revision-id: ubuntu at toykeeper.net-20080710061043-k6ppl18xe81uajq4
    parent: ubuntu at toykeeper.net-20080710054126-710099ffvmhf5ud2
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Thu 2008-07-10 00:10:43 -0600
    message:
      Added an option to show/hide the diff panel.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.2
    revision-id: ubuntu at toykeeper.net-20080710054126-710099ffvmhf5ud2
    parent: ubuntu at toykeeper.net-20080617074536-cor6uh03liyhi6cm
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: vis-enhancements
    timestamp: Wed 2008-07-09 23:41:26 -0600
    message:
      Made 'vis' save/load visibility of its toolbar.
      (the menu had a working checkbox to hide the toolbar,
       but the value was never saved)
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
    ------------------------------------------------------------
    revno: 531.7.1
    revision-id: ubuntu at toykeeper.net-20080617074536-cor6uh03liyhi6cm
    parent: jelmer at samba.org-20080701215625-udvespwg6srjo252
    committer: Scott Scriven <ubuntu at toykeeper.net>
    branch nick: bzrk-with-diffs
    timestamp: Tue 2008-06-17 01:45:36 -0600
    message:
      Added a diff panel to otherwise-blank area in 'bzr vis'.
      It's just like the diff window, but more convenient.
    modified:
      viz/branchwin.py               branchwin.py-20051016222514-15fd120652fcf25c
=== modified file 'NEWS'
--- a/NEWS	2008-07-18 10:39:25 +0000
+++ b/NEWS	2008-07-18 12:29:56 +0000
@@ -13,6 +13,12 @@
 
   * Remove dummy "Edit->Find" option. (Jelmer Vernooij)
 
+  * Added an optional diff panel to bzr vis.  (Scott Scriven)
+
+  * Made bzr vis remember whether the toolbar is visible.  (Scott Scriven)
+
+  * Made bzr vis remember window and panel sizes.  (Scott Scriven)
+
  BUG FIXES
 
   * Replace _() calls by _i18n() calls. (Vincent Ladeuil, #187283)
@@ -38,6 +44,10 @@
 
   * Fix import in Olive rename dialog. (Kevin Light)
 
+  * Removed some redundant screen redrawing in bzr vis.  (Scott Scriven)
+
+  * Fixed overflowing labels in bzr vis.  (Scott Scriven)
+
  CHANGES
 
   * Moved notify icon code to separate script. (Jelmer Vernooij)

=== modified file 'branchview/treeview.py'
--- a/branchview/treeview.py	2008-06-30 20:11:24 +0000
+++ b/branchview/treeview.py	2008-07-10 06:23:54 +0000
@@ -325,6 +325,7 @@
         if set_tooltip is not None:
             set_tooltip(treemodel.MESSAGE)
 
+        self._prev_cursor_path = None
         self.treeview.connect("cursor-changed",
                 self._on_selection_changed)
 
@@ -400,7 +401,8 @@
     def _on_selection_changed(self, treeview):
         """callback for when the treeview changes."""
         (path, focus) = treeview.get_cursor()
-        if path is not None:
+        if (path is not None) and (path != self._prev_cursor_path):
+            self._prev_cursor_path = path # avoid emitting twice per click
             self.iter = self.model.get_iter(path)
             self.emit('revision-selected')
 

=== modified file 'diff.py'
--- a/diff.py	2008-05-22 02:33:40 +0000
+++ b/diff.py	2008-07-17 11:24:26 +0000
@@ -330,9 +330,10 @@
         # text view
 
     def set_diff_text_sections(self, sections):
-        self.diff_view = DiffFileView()
+        if getattr(self, 'diff_view', None) is None:
+            self.diff_view = DiffFileView()
+            self.pack2(self.diff_view)
         self.diff_view.show()
-        self.pack2(self.diff_view)
         for oldname, newname, patch in sections:
             self.diff_view._diffs[newname] = str(patch)
             if newname is None:
@@ -346,8 +347,9 @@
         Compares the two trees and populates the window with the
         differences.
         """
-        self.diff_view = DiffView()
-        self.pack2(self.diff_view)
+        if getattr(self, 'diff_view', None) is None:
+            self.diff_view = DiffView()
+            self.pack2(self.diff_view)
         self.diff_view.show()
         self.diff_view.set_trees(rev_tree, parent_tree)
         self.rev_tree = rev_tree
@@ -380,6 +382,7 @@
                 self.model.append(titer, [ path, path ])
 
         self.treeview.expand_all()
+        self.diff_view.show_diff(None)
 
     def set_file(self, file_path):
         """Select the current file to display"""

=== modified file 'revisionview.py'
--- a/revisionview.py	2008-06-29 19:18:34 +0000
+++ b/revisionview.py	2008-07-11 15:46:32 +0000
@@ -509,7 +509,7 @@
         table.resize(max(len(revids), 1), 2)
 
         for idx, revid in enumerate(revids):
-            align = gtk.Alignment(0.0, 0.0)
+            align = gtk.Alignment(0.0, 0.0, 1, 1)
             widgets.append(align)
             table.attach(align, 1, 2, idx, idx + 1,
                                       gtk.EXPAND | gtk.FILL, gtk.FILL)
@@ -532,12 +532,16 @@
                 hbox.pack_start(button, expand=False, fill=True)
                 button.show()
 
-            button = gtk.Button(revid)
+            button = gtk.Button()
+            revid_label = gtk.Label(str(revid))
+            revid_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+            revid_label.set_alignment(0.0, 0.5)
+            button.add(revid_label)
             button.connect("clicked",
                     lambda w, r: self.set_revision(self._repository.get_revision(r)), revid)
             button.set_use_underline(False)
-            hbox.pack_start(button, expand=False, fill=True)
-            button.show()
+            hbox.pack_start(button, expand=True, fill=True)
+            button.show_all()
 
     def _create_general(self):
         vbox = gtk.VBox(False, 6)
@@ -566,102 +570,91 @@
         self.table.set_col_spacings(6)
         self.table.show()
 
-        align = gtk.Alignment(1.0, 0.5)
+        row = 0
+
         label = gtk.Label()
+        label.set_alignment(1.0, 0.5)
         label.set_markup("<b>Revision Id:</b>")
-        align.add(label)
-        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         label.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         revision_id = gtk.Label()
+        revision_id.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+        revision_id.set_alignment(0.0, 0.5)
         revision_id.set_selectable(True)
         self.connect('notify::revision', 
                 lambda w, p: revision_id.set_text(self._revision.revision_id))
-        align.add(revision_id)
-        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(revision_id, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         revision_id.show()
 
-        align = gtk.Alignment(1.0, 0.5)
+        row += 1
         self.author_label = gtk.Label()
+        self.author_label.set_alignment(1.0, 0.5)
         self.author_label.set_markup("<b>Author:</b>")
-        align.add(self.author_label)
-        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(self.author_label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         self.author_label.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         self.author = gtk.Label()
+        self.author.set_ellipsize(pango.ELLIPSIZE_END)
+        self.author.set_alignment(0.0, 0.5)
         self.author.set_selectable(True)
-        align.add(self.author)
-        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(self.author, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         self.author.show()
         self.author.hide()
 
-        align = gtk.Alignment(1.0, 0.5)
+        row += 1
         label = gtk.Label()
+        label.set_alignment(1.0, 0.5)
         label.set_markup("<b>Committer:</b>")
-        align.add(label)
-        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         label.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         self.committer = gtk.Label()
+        self.committer.set_ellipsize(pango.ELLIPSIZE_END)
+        self.committer.set_alignment(0.0, 0.5)
         self.committer.set_selectable(True)
-        align.add(self.committer)
-        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(self.committer, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         self.committer.show()
 
-        align = gtk.Alignment(0.0, 0.5)
+        row += 1
         label = gtk.Label()
+        label.set_alignment(1.0, 0.5)
         label.set_markup("<b>Branch nick:</b>")
-        align.add(label)
-        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
+        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         label.show()
-        align.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         self.branchnick_label = gtk.Label()
+        self.branchnick_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+        self.branchnick_label.set_alignment(0.0, 0.5)
         self.branchnick_label.set_selectable(True)
-        align.add(self.branchnick_label)
-        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
+        self.table.attach(self.branchnick_label, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         self.branchnick_label.show()
-        align.show()
 
-        align = gtk.Alignment(1.0, 0.5)
+        row += 1
         label = gtk.Label()
+        label.set_alignment(1.0, 0.5)
         label.set_markup("<b>Timestamp:</b>")
-        align.add(label)
-        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         label.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         self.timestamp = gtk.Label()
+        self.timestamp.set_ellipsize(pango.ELLIPSIZE_END)
+        self.timestamp.set_alignment(0.0, 0.5)
         self.timestamp.set_selectable(True)
-        align.add(self.timestamp)
-        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
-        align.show()
+        self.table.attach(self.timestamp, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         self.timestamp.show()
 
-        align = gtk.Alignment(1.0, 0.5)
+        row += 1
         self.tags_label = gtk.Label()
+        self.tags_label.set_alignment(1.0, 0.5)
         self.tags_label.set_markup("<b>Tags:</b>")
-        align.add(self.tags_label)
-        align.show()
-        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
+        self.table.attach(self.tags_label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
         self.tags_label.show()
 
-        align = gtk.Alignment(0.0, 0.5)
         self.tags_list = gtk.Label()
-        align.add(self.tags_list)
-        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
-        align.show()
+        self.tags_list.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+        self.tags_list.set_alignment(0.0, 0.5)
+        self.table.attach(self.tags_list, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
         self.tags_list.show()
 
         self.connect('notify::revision', self._add_tags)

=== modified file 'viz/branchwin.py'
--- a/viz/branchwin.py	2008-07-01 21:54:21 +0000
+++ b/viz/branchwin.py	2008-07-17 12:06:33 +0000
@@ -48,6 +48,8 @@
         self.maxnum      = maxnum
         self.config      = GlobalConfig()
 
+        self._sizes      = {} # window and widget sizes
+
         if self.config.get_user_option('viz-compact-view') == 'yes':
             self.compact_view = True
         else:
@@ -60,7 +62,13 @@
         monitor = screen.get_monitor_geometry(0)
         width = int(monitor.width * 0.75)
         height = int(monitor.height * 0.75)
+        # user-configured window size
+        size = self._load_size('viz-window-size')
+        if size:
+            width, height = size
         self.set_default_size(width, height)
+        self.set_size_request(width/3, height/3)
+        self.connect("size-allocate", self._on_size_allocate, 'viz-window-size')
 
         # FIXME AndyFitz!
         icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
@@ -104,13 +112,15 @@
         self.add(vbox)
 
         self.paned = gtk.VPaned()
-        self.paned.pack1(self.construct_top(), resize=True, shrink=False)
-        self.paned.pack2(self.construct_bottom(), resize=False, shrink=True)
+        self.paned.pack1(self.construct_top(), resize=False, shrink=True)
+        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
         self.paned.show()
 
-        vbox.pack_start(self.construct_menubar(), expand=False, fill=True)
-        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
-        
+        nav = self.construct_navigation()
+        menubar = self.construct_menubar()
+        vbox.pack_start(menubar, expand=False, fill=True)
+        vbox.pack_start(nav, expand=False, fill=True)
+
         vbox.pack_start(self.paned, expand=True, fill=True)
         vbox.set_focus_child(self.paned)
 
@@ -161,14 +171,31 @@
 
         view_menu_toolbar = gtk.CheckMenuItem("Show Toolbar")
         view_menu_toolbar.set_active(True)
+        if self.config.get_user_option('viz-toolbar-visible') == 'False':
+            view_menu_toolbar.set_active(False)
+            self.toolbar.hide()
         view_menu_toolbar.connect('toggled', self._toolbar_visibility_changed)
 
         view_menu_compact = gtk.CheckMenuItem("Show Compact Graph")
         view_menu_compact.set_active(self.compact_view)
         view_menu_compact.connect('activate', self._brokenlines_toggled_cb)
 
+        view_menu_diffs = gtk.CheckMenuItem("Show Diffs")
+        view_menu_diffs.set_active(False)
+        if self.config.get_user_option('viz-show-diffs') == 'True':
+            view_menu_diffs.set_active(True)
+        view_menu_diffs.connect('toggled', self._diff_visibility_changed)
+
+        view_menu_wide_diffs = gtk.CheckMenuItem("Wide Diffs")
+        view_menu_wide_diffs.set_active(False)
+        if self.config.get_user_option('viz-wide-diffs') == 'True':
+            view_menu_wide_diffs.set_active(True)
+        view_menu_wide_diffs.connect('toggled', self._diff_placement_changed)
+
         view_menu.add(view_menu_toolbar)
         view_menu.add(view_menu_compact)
+        view_menu.add(view_menu_diffs)
+        view_menu.add(view_menu_wide_diffs)
         view_menu.add(gtk.SeparatorMenuItem())
 
         self.mnu_show_revno_column = gtk.CheckMenuItem("Show Revision _Number Column")
@@ -275,6 +302,15 @@
         align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
         align.set_padding(5, 0, 0, 0)
         align.add(self.treeview)
+        # user-configured size
+        size = self._load_size('viz-graph-size')
+        if size:
+            width, height = size
+            align.set_size_request(width, height)
+        else:
+            (width, height) = self.get_size()
+            align.set_size_request(width, int(height / 2.5))
+        align.connect('size-allocate', self._on_size_allocate, 'viz-graph-size')
         align.show()
 
         return align
@@ -302,15 +338,37 @@
 
     def construct_bottom(self):
         """Construct the bottom half of the window."""
+        if self.config.get_user_option('viz-wide-diffs') == 'True':
+            self.diff_paned = gtk.VPaned()
+        else:
+            self.diff_paned = gtk.HPaned()
+        (width, height) = self.get_size()
+        self.diff_paned.set_size_request(20, 20) # shrinkable
+
         from bzrlib.plugins.gtk.revisionview import RevisionView
         self.revisionview = RevisionView(branch=self.branch)
-        (width, height) = self.get_size()
-        self.revisionview.set_size_request(width, int(height / 2.5))
+        self.revisionview.set_size_request(width/3, int(height / 2.5))
+        # user-configured size
+        size = self._load_size('viz-revisionview-size')
+        if size:
+            width, height = size
+            self.revisionview.set_size_request(width, height)
+        self.revisionview.connect('size-allocate', self._on_size_allocate, 'viz-revisionview-size')
         self.revisionview.show()
         self.revisionview.set_show_callback(self._show_clicked_cb)
         self.revisionview.connect('notify::revision', self._go_clicked_cb)
         self.treeview.connect('tag-added', lambda w, t, r: self.revisionview.update_tags())
-        return self.revisionview
+        self.diff_paned.pack1(self.revisionview)
+
+        from bzrlib.plugins.gtk.diff import DiffWidget
+        self.diff = DiffWidget()
+        self.diff_paned.pack2(self.diff)
+
+        self.diff_paned.show_all()
+        if self.config.get_user_option('viz-show-diffs') != 'True':
+            self.diff.hide()
+
+        return self.diff_paned
 
     def _tag_selected_cb(self, menuitem, revid):
         self.treeview.set_revision_id(revid)
@@ -367,7 +425,9 @@
 
             self.revisionview.set_revision(revision)
             self.revisionview.set_children(children)
-    
+
+            self.update_diff_panel(revision, parents)
+
     def _tree_revision_activated(self, widget, path, col):
         # TODO: more than one parent
         """Callback for when a treeview row gets activated."""
@@ -439,9 +499,38 @@
 
     def _toolbar_visibility_changed(self, col):
         if col.get_active():
-            self.toolbar.show() 
+            self.toolbar.show()
         else:
             self.toolbar.hide()
+        self.config.set_user_option('viz-toolbar-visible', col.get_active())
+
+    def _make_diff_nonzero_size(self):
+        """make sure the diff isn't zero-width or zero-height"""
+        alloc = self.diff.get_allocation()
+        if (alloc.width < 10) or (alloc.height < 10):
+            width, height = self.get_size()
+            self.revisionview.set_size_request(width/3, int(height / 2.5))
+
+    def _diff_visibility_changed(self, col):
+        """Hide or show the diff panel."""
+        if col.get_active():
+            self.diff.show()
+            self._make_diff_nonzero_size()
+        else:
+            self.diff.hide()
+        self.config.set_user_option('viz-show-diffs', str(col.get_active()))
+        self.update_diff_panel()
+
+    def _diff_placement_changed(self, col):
+        """Toggle the diff panel's position."""
+        self.config.set_user_option('viz-wide-diffs', str(col.get_active()))
+
+        old = self.paned.get_child2()
+        self.paned.remove(old)
+        self.paned.pack2(self.construct_bottom(), resize=True, shrink=False)
+        self._make_diff_nonzero_size()
+
+        self.treeview.emit('revision-selected')
 
     def _show_about_cb(self, w):
         dialog = AboutDialog()
@@ -473,6 +562,34 @@
 
         self.go_menu_tags.show_all()
 
+    def _load_size(self, name):
+        """Read and parse 'name' from self.config.
+        The value is a string, formatted as WIDTHxHEIGHT
+        Returns None, or (width, height)
+        """
+        size = self.config.get_user_option(name)
+        if size:
+            width, height = [int(num) for num in size.split('x')]
+            # avoid writing config every time we start
+            self._sizes[name] = (width, height)
+            return width, height
+        return None
+
+    def _on_size_allocate(self, widget, allocation, name):
+        """When window has been resized, save the new size."""
+        width, height = 0, 0
+        if name in self._sizes:
+            width, height = self._sizes[name]
+
+        size_changed = (width != allocation.width) or \
+                (height != allocation.height)
+
+        if size_changed:
+            width, height = allocation.width, allocation.height
+            self._sizes[name] = (width, height)
+            value = '%sx%s' % (width, height)
+            self.config.set_user_option(name, value)
+
     def show_diff(self, revid=None, parentid=None):
         """Open a new window to show a diff between the given revisions."""
         from bzrlib.plugins.gtk.diff import DiffWindow
@@ -488,4 +605,25 @@
         window.set_diff(description, rev_tree, parent_tree)
         window.show()
 
-
+    def update_diff_panel(self, revision=None, parents=None):
+        """Show the current revision in the diff panel."""
+        if self.config.get_user_option('viz-show-diffs') != 'True':
+            return
+
+        if not revision: # default to selected row
+            revision = self.treeview.get_revision()
+        if (not revision) or (revision == NULL_REVISION):
+            return
+
+        if not parents: # default to selected row's parents
+            parents  = self.treeview.get_parents()
+        if len(parents) == 0:
+            parent_id = None
+        else:
+            parent_id = parents[0]
+
+        rev_tree    = self.branch.repository.revision_tree(revision.revision_id)
+        parent_tree = self.branch.repository.revision_tree(parent_id)
+
+        self.diff.set_diff(rev_tree, parent_tree)
+        self.diff.show_all()




More information about the bazaar-commits mailing list