[Pkg-bazaar-commits] ./bzr-gtk/unstable r10: Add an extra window type, clicking the little icons next to a parent
Scott James Remnant
scott at netsplit.com
Fri Apr 10 07:15:14 UTC 2009
------------------------------------------------------------
revno: 10
committer: Scott James Remnant <scott at netsplit.com>
timestamp: Mon 2005-10-17 08:55:01 +0100
message:
Add an extra window type, clicking the little icons next to a parent
revision will open a window with the differences between the revision
and that one.
added:
diffwin.py
modified:
branchwin.py
bzrkapp.py
-------------- next part --------------
=== modified file 'branchwin.py'
--- a/branchwin.py 2005-10-17 06:51:34 +0000
+++ b/branchwin.py 2005-10-17 07:55:01 +0000
@@ -29,11 +29,13 @@
for a particular branch.
"""
- def __init__(self):
+ def __init__(self, app=None):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.set_border_width(0)
self.set_title("bzrk")
+ self.app = app
+
# Use three-quarters of the screen by default
screen = self.get_screen()
monitor = screen.get_monitor_geometry(0)
@@ -227,6 +229,8 @@
the new branch before updating the window title and model of the
treeview itself.
"""
+ self.branch = branch
+
# [ revision, node, last_lines, lines, message, committer, timestamp ]
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
gobject.TYPE_PYOBJECT,
@@ -319,8 +323,9 @@
button = gtk.Button()
button.add(image)
button.set_relief(gtk.RELIEF_NONE)
- button.set_sensitive(False)
- button.connect("clicked", self._show_clicked_cb, parent_id)
+ button.set_sensitive(self.app is not None)
+ button.connect("clicked", self._show_clicked_cb,
+ revision.revision_id, parent_id)
hbox.pack_start(button, expand=False, fill=True)
button.show()
@@ -359,6 +364,7 @@
"""Callback for when the go button for a parent is clicked."""
self.treeview.set_cursor(self.index[self.revisions[revid]])
- def _show_clicked_cb(self, widget, revid):
+ def _show_clicked_cb(self, widget, revid, parentid):
"""Callback for when the show button for a parent is clicked."""
- print "SHOW %s" % revid
+ if self.app is not None:
+ self.app.show_diff(self.branch, revid, parentid)
=== modified file 'bzrkapp.py'
--- a/bzrkapp.py 2005-10-17 01:07:49 +0000
+++ b/bzrkapp.py 2005-10-17 07:55:01 +0000
@@ -16,6 +16,7 @@
import gtk
from branchwin import BranchWindow
+from diffwin import DiffWindow
class BzrkApp(object):
@@ -31,10 +32,19 @@
def show(self, branch, start):
"""Open a new window to show the given branch."""
- self._num_windows += 1
-
- window = BranchWindow()
+ window = BranchWindow(self)
window.set_branch(branch, start)
+
+ self._num_windows += 1
+ window.connect("destroy", self._destroy_cb)
+ window.show()
+
+ def show_diff(self, branch, revid, parentid):
+ """Open a new window to show a diff between the given revisions."""
+ window = DiffWindow(self)
+ window.set_diff(branch, revid, parentid)
+
+ self._num_windows += 1
window.connect("destroy", self._destroy_cb)
window.show()
=== added file 'diffwin.py'
--- a/diffwin.py 1970-01-01 00:00:00 +0000
+++ b/diffwin.py 2005-10-17 07:55:01 +0000
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+"""Difference window.
+
+This module contains the code to manage the diff window which shows
+the changes made between two revisions on a branch.
+"""
+
+__copyright__ = "Copyright ? 2005 Canonical Ltd."
+__author__ = "Scott James Remnant <scott at ubuntu.com>"
+
+
+import os
+
+from cStringIO import StringIO
+
+import gtk
+import gobject
+import pango
+
+try:
+ import gtksourceview
+ have_gtksourceview = True
+except ImportError:
+ have_gtksourceview = False
+
+from bzrlib.delta import compare_trees
+from bzrlib.diff import show_diff_trees
+
+
+class DiffWindow(gtk.Window):
+ """Diff window.
+
+ This object represents and manages a single window containing the
+ differences between two revisions on a branch.
+ """
+
+ def __init__(self, app=None):
+ gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+ self.set_border_width(0)
+ self.set_title("bzrk diff")
+
+ self.app = app
+
+ # Use two thirds of the screen by default
+ screen = self.get_screen()
+ monitor = screen.get_monitor_geometry(0)
+ width = int(monitor.width * 0.66)
+ height = int(monitor.height * 0.66)
+ self.set_default_size(width, height)
+
+ self.construct()
+
+ def construct(self):
+ """Construct the window contents."""
+ hbox = gtk.HBox(spacing=6)
+ hbox.set_border_width(12)
+ self.add(hbox)
+ hbox.show()
+
+ scrollwin = gtk.ScrolledWindow()
+ scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrollwin.set_shadow_type(gtk.SHADOW_IN)
+ hbox.pack_start(scrollwin, expand=False, fill=True)
+ scrollwin.show()
+
+ self.model = gtk.TreeStore(str, str)
+ self.treeview = gtk.TreeView(self.model)
+ self.treeview.set_headers_visible(False)
+ self.treeview.set_search_column(1)
+ self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
+ scrollwin.add(self.treeview)
+ self.treeview.show()
+
+ cell = gtk.CellRendererText()
+ cell.set_property("width-chars", 20)
+ column = gtk.TreeViewColumn()
+ column.pack_start(cell, expand=True)
+ column.add_attribute(cell, "text", 0)
+ self.treeview.append_column(column)
+
+
+ scrollwin = gtk.ScrolledWindow()
+ scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ scrollwin.set_shadow_type(gtk.SHADOW_IN)
+ hbox.pack_start(scrollwin, expand=True, fill=True)
+ scrollwin.show()
+
+ if have_gtksourceview:
+ self.buffer = gtksourceview.SourceBuffer()
+ slm = gtksourceview.SourceLanguagesManager()
+ gsl = slm.get_language_from_mime_type("text/x-patch")
+ self.buffer.set_language(gsl)
+ self.buffer.set_highlight(True)
+
+ sourceview = gtksourceview.SourceView(self.buffer)
+ else:
+ self.buffer = gtk.TextBuffer()
+ sourceview = gtk.TextView(self.buffer)
+
+ sourceview.set_editable(False)
+ sourceview.set_wrap_mode(gtk.WRAP_CHAR)
+ sourceview.modify_font(pango.FontDescription("Monospace"))
+ scrollwin.add(sourceview)
+ sourceview.show()
+
+ def set_diff(self, branch, revid, parentid):
+ """Set the differences showed by this window.
+
+ Compares the two trees and populates the window with the
+ differences.
+ """
+ self.rev_tree = branch.revision_tree(revid)
+ self.parent_tree = branch.revision_tree(parentid)
+
+ self.model.clear()
+ delta = compare_trees(self.parent_tree, self.rev_tree)
+
+ if len(delta.added):
+ titer = self.model.append(None, [ "Added", None ])
+ for path, id, kind in delta.added:
+ self.model.append(titer, [ path, path ])
+
+ if len(delta.removed):
+ titer = self.model.append(None, [ "Removed", None ])
+ for path, id, kind in delta.removed:
+ self.model.append(titer, [ path, path ])
+
+ if len(delta.renamed):
+ titer = self.model.append(None, [ "Renamed", None ])
+ for oldpath, newpath, id, kind, text_modified, meta_modified \
+ in delta.renamed:
+ self.model.append(titer, [ oldpath, oldpath ])
+
+ if len(delta.modified):
+ titer = self.model.append(None, [ "Modified", None ])
+ for path, id, kind, text_modified, meta_modified in delta.modified:
+ self.model.append(titer, [ path, path ])
+
+ self.treeview.expand_all()
+ self.set_title(os.path.basename(branch.base) + " - bzrk diff")
+
+ def _treeview_cursor_cb(self, *args):
+ """Callback for when the treeview cursor changes."""
+ (path, col) = self.treeview.get_cursor()
+ path = self.model[path][1]
+ if path is None:
+ return
+
+ s = StringIO()
+ show_diff_trees(self.parent_tree, self.rev_tree, s, [ path ])
+ self.buffer.set_text(s.getvalue())
More information about the Pkg-bazaar-commits
mailing list