[Pkg-bazaar-commits] ./bzr-gtk/unstable r226: Add context menu in bzrk.

Jelmer Vernooij jelmer at samba.org
Fri Apr 10 07:49:45 UTC 2009


------------------------------------------------------------
revno: 226
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sun 2007-07-15 18:02:01 +0200
message:
  Add context menu in bzrk.
added:
  revisionmenu.py
modified:
  NEWS
  viz/branchwin.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2007-07-15 15:02:33 +0000
+++ b/NEWS	2007-07-15 16:02:01 +0000
@@ -10,6 +10,8 @@
 
   * Add simple About dialog. (Jelmer)
 
+  * Add context menu in bzrk. (Jelmer)
+
  BUG FIXES
 
   * Fix option help strings to comply with the style guide. (Vincent)

=== added file 'revisionmenu.py'
--- a/revisionmenu.py	1970-01-01 00:00:00 +0000
+++ b/revisionmenu.py	2007-07-15 16:02:01 +0000
@@ -0,0 +1,47 @@
+# Copyright (C) 2007 by Jelmer Vernooij <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""Simple popup menu for revisions."""
+
+try:
+    import pygtk
+    pygtk.require("2.0")
+except:
+    pass
+
+import bzrlib
+import gtk
+
+class RevisionPopupMenu(gtk.Menu):
+    def __init__(self, repository, revid):
+        super(RevisionPopupMenu, self).__init__()
+        self.create_items()
+        self.repository = repository
+        self.revid = revid
+
+    def create_items(self):
+        item = gtk.MenuItem("View _Diff")
+        item.connect('activate', self.show_diff)
+        self.append(item)
+        self.show_all()
+
+    def show_diff(self, item):
+        from bzrlib.plugins.gtk.diff import DiffWindow
+        window = DiffWindow()
+        parentid = self.repository.revision_parents(self.revid)[0]
+        (parent_tree, rev_tree) = self.repository.revision_trees([parentid, 
+                                                                   self.revid])
+        window.set_diff(self.revid, rev_tree, parent_tree)
+        window.show()

=== modified file 'viz/branchwin.py'
--- a/viz/branchwin.py	2007-03-20 21:09:30 +0000
+++ b/viz/branchwin.py	2007-07-15 16:02:01 +0000
@@ -75,6 +75,8 @@
         self.treeview.set_search_column(4)
         self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
         self.treeview.connect("row-activated", self._treeview_row_activated_cb)
+        self.treeview.connect("button-release-event", 
+                self._treeview_row_mouseclick)
         scrollwin.add(self.treeview)
         self.treeview.show()
 
@@ -174,7 +176,7 @@
 
         last_lines = []
         (self.revisions, colours, self.children, self.parent_ids,
-         merge_sorted) = distances(branch, start)
+            merge_sorted) = distances(branch, start)
         for (index, (revision, node, lines)) in enumerate(graph(
                 self.revisions, colours, merge_sorted)):
             # FIXME: at this point we should be able to show the graph order
@@ -246,8 +248,8 @@
         """Open a new window to show a diff between the given revisions."""
         from bzrlib.plugins.gtk.diff import DiffWindow
         window = DiffWindow()
-        rev_tree = branch.repository.revision_tree(revid)
-        parent_tree = branch.repository.revision_tree(parentid)
+        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
+                                                                   revid])
         description = revid + " - " + branch.nick
         window.set_diff(description, rev_tree, parent_tree)
         window.show()
@@ -257,10 +259,24 @@
         self.show_diff(self.branch, revid, parentid)
         self.treeview.grab_focus()
 
+    def _treeview_row_mouseclick(self, widget, event):
+        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
+        # FIXME: Support multiple revisions
+        menu = RevisionPopupMenu(self.branch.repository, 
+                                 self.selected_revisions()[0].revision_id)
+        menu.popup(None, None, None, event.button, event.get_time())
+
+    def selected_revision(self, path):
+        return self.model[path][0]
+
+    def selected_revisions(self):
+        return [self.selected_revision(path) for path in \
+                self.treeview.get_selection().get_selected_rows()[1]]
+
     def _treeview_row_activated_cb(self, widget, path, col):
         # TODO: more than one parent
         """Callback for when a treeview row gets activated."""
-        revision = self.model[path][0]
+        revision = self.selected_revision()
         if len(self.parent_ids[revision]) == 0:
             # Ignore revisions without parent
             return



More information about the Pkg-bazaar-commits mailing list