Re: [PATCH] Multi-VC chooser preferences



Hello,

On Tue, Mar 10, 2009 at 12:57 AM, Kai Willadsen <kai willadsen gmail com> wrote:
> HIG-wise, spacings are supposed to be multiples of 6, so I originally
> set the hbox2 spacing (i.e., what ends up being the space between the
> browse and the combo) to 12, but reset it to 6 later because it looked
> a little odd. Setting it to 12 would give some nice visual separation.
> Alternatively, maybe set HistoryFileEntry's hbox spacing to 3 and
> leave hbox2 at 6? Not HIG-y, but at least visually consistent.

I think this series of patches adress all concerns (except for the
"GtkWarning" which seems innocuous enough).

The real meat is in the first patch, which gained an additional
feature since last time: the tooltip on the combobox is
dynamically changed, to help the user understand what this
thing is about when there is only one VC in a directory and
the control is greyed (I expect the vast majority of users to
be in this category). We don't want bugs logged because they
think something is not working when in fact it is.

I fixed another couple of back-traces by using the dreaded
"lock" during initialization, I didn't think another way of doing
that locking was useful, this is simple and does the trick.
Those were the: AttributeError: 'gtk.ComboBox' object has
no attribute 'lock' Backtraces Kai reported, and that I
managed to reproduce.

remove-historyentry-vbox.patch is Stephen's patch to remove
the embedded vbox in HistoryFileEntry

set-vcview-fileentry-hbox2-spacing-to-hig-stds.patch is the HIG
compliance patch from Kai. (hope this is all of it, and didn't miss
anything)

remove-button-jump.patch is not really needed for the functionality,
but it's touching same parts of the glade file, so I included it here.

This series is probably not applicable as-is, because each patch
is generated against current trunk (r1255)

Please review & comment, I intend to push this version, if no one
is against.

-- 
Vincent Legoll
Index: vcview.py
===================================================================
--- vcview.py	(revision 1255)
+++ vcview.py	(working copy)
@@ -191,35 +191,40 @@
         self.button_jump.hide()
         if not self.prefs.vc_console_visible:
             self.on_console_view_toggle(self.console_hide_box)
+        self.vc = None
+        # VC ComboBox
+        self.combobox_vcs.lock = True
+        self.combobox_vcs.set_model(gtk.ListStore(str, object))
+        cell = gtk.CellRendererText()
+        self.combobox_vcs.pack_start(cell, False)
+        self.combobox_vcs.add_attribute(cell, 'text', 0)
+        self.combobox_vcs.lock = False
 
     def choose_vc(self, vcs):
-        """Callback from vc.Vc to choose when there are multiple plugins able to handle one location"""
-        d = gtk.Dialog(_('VC chooser'),
-            None,
-            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
-            (gtk.STOCK_OK, gtk.RESPONSE_OK))
-        
-        indexMap = {}
-        cb = gtk.combo_box_new_text()
-        for i, avc in enumerate(vcs):
-            cb.append_text(avc.NAME)
-            indexMap[avc.NAME] = i
-        cb.set_active(0)
-        lb = gtk.Label(_('Pick one source control plugin'))
-        d.vbox.set_spacing(12)
-        d.vbox.pack_start(lb, True, True, 12)
-        d.vbox.pack_start(cb, False, False)
-        cb.show()
-        lb.show()
-        d.run()
-        d.destroy()
-        return vcs[indexMap[cb.get_active_text()]]
+        """Display VC plugin(s) that can handle the location"""
+        self.combobox_vcs.lock = True
+        self.combobox_vcs.get_model().clear()
+        tooltip_texts = [_("Choose one Version Control"),
+                         _("Only one Version Control in this directory")]
+        for avc in vcs:
+            self.combobox_vcs.get_model().append([avc.NAME, avc])
+        self.combobox_vcs.set_tooltip_text(tooltip_texts[len(vcs) == 1])
+        self.combobox_vcs.set_sensitive(len(vcs) > 1)
+        self.combobox_vcs.lock = False
+        self.combobox_vcs.set_active(0)
   
+    def on_vc_change(self, cb):
+        if not cb.lock:
+            self.vc = cb.get_model()[cb.get_active_iter()][1]
+            self._set_location(self.vc.root)
+
     def set_location(self, location):
+        self.location = location = os.path.abspath(location or ".")
+        self.choose_vc(vc.get_vcs(location))
+
+    def _set_location(self, location):
         self.model.clear()
-        self.location = location = os.path.abspath(location or ".")
         self.fileentry.gtk_entry.set_text(location)
-        self.vc = vc.Vc(location, self.choose_vc)
         it = self.model.add_entries( None, [location] )
         self.treeview.grab_focus()
         self.treeview.get_selection().select_iter(it)
Index: glade2/vcview.glade
===================================================================
--- glade2/vcview.glade	(revision 1255)
+++ glade2/vcview.glade	(working copy)
@@ -71,6 +71,21 @@
 	      <property name="fill">False</property>
 	    </packing>
 	  </child>
+
+            <child>
+              <widget class="GtkComboBox" id="combobox_vcs">
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="active">0</property>
+                <property name="tooltip" translatable="no">Version Control</property>
+                <signal name="changed" handler="on_vc_change"/>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+              </packing>
+            </child>
+
 	</widget>
 	<packing>
 	  <property name="padding">0</property>
Index: vc/__init__.py
===================================================================
--- vc/__init__.py	(revision 1255)
+++ vc/__init__.py	(working copy)
@@ -34,11 +34,7 @@
     return ret
 _plugins = load_plugins()
 
-def default_plugin_order(vcs):
-    # Pick the Vc with the longest repo root
-    return max(vcs, key=lambda repo: len(repo.root))
-
-def Vc(location, ordering_func = default_plugin_order):
+def get_vcs(location):
     vcs = []
     for plugin in _plugins:
         try:
@@ -48,12 +44,6 @@
 
     if not vcs:
         # No plugin recognized that location, fallback to _null
-        vc = _null.Vc(location)
-    elif len(vcs) == 1:
-        # No need to launch a potentially GUI/interactive chooser
-        vc = vcs[0]
-    else:
-        # User gets to pick one, eventually
-        vc = ordering_func(vcs)
+        vcs.append(_null.Vc(location))
 
-    return vc
+    return vcs
Index: historyentry.py
===================================================================
--- historyentry.py	(revision 1218)
+++ historyentry.py	(working copy)
@@ -219,7 +219,7 @@
         return os.path.join(os.getcwd(), filename)
 
 
-class HistoryFileEntry(gtk.VBox, gtk.Editable):
+class HistoryFileEntry(gtk.HBox, gtk.Editable):
     __gsignals__ = {
         "browse_clicked" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
         "activate" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
@@ -239,22 +239,17 @@
 
         self.set_spacing(4)
 
-        # Allow for a preview thingie to be smacked on top of the file entry
-        hbox = gtk.HBox(False, 4)
-        hbox.show()
-        self.pack_end(hbox, False, False, 0)
-
         self.gtk_entry.connect("changed", self.__entry_changed_signal)
         self.gtk_entry.connect("activate", self.__entry_activate_signal)
 
         self._setup_dnd()
 
-        hbox.pack_start(self.__gentry, True, True, 0)
+        self.pack_start(self.__gentry, True, True, 0)
         self.__gentry.show()
 
         button = gtk.Button(_("_Browse..."))
         button.connect("clicked", self.__browse_clicked)
-        hbox.pack_start(button, False, False, 0)
+        self.pack_start(button, False, False, 0)
         button.show()
 
         access_entry = self.__gentry.get_accessible()
Index: glade2/vcview.glade
===================================================================
--- glade2/vcview.glade	(revision 1255)
+++ glade2/vcview.glade	(working copy)
@@ -28,7 +28,7 @@
 	<widget class="GtkHBox" id="hbox2">
 	  <property name="visible">True</property>
 	  <property name="homogeneous">False</property>
-	  <property name="spacing">0</property>
+	  <property name="spacing">6</property>
 
 	  <child>
 	    <widget class="Custom" id="fileentry">
Index: historyentry.py
===================================================================
--- historyentry.py	(revision 1255)
+++ historyentry.py	(working copy)
@@ -237,7 +237,7 @@
         self.__is_modal = False
         self.directory_entry = False
 
-        self.set_spacing(4)
+        self.set_spacing(6)
 
         # Allow for a preview thingie to be smacked on top of the file entry
         hbox = gtk.HBox(False, 4)
Index: glade2/vcview.glade
===================================================================
--- glade2/vcview.glade	(revision 1249)
+++ glade2/vcview.glade	(working copy)
@@ -45,32 +45,6 @@
 	    </packing>
 	  </child>
 
-	  <child>
-	    <widget class="GtkButton" id="button_jump">
-	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <signal name="button_press_event" handler="on_button_jump_press_event" last_modification_time="Thu, 22 May 2003 18:32:48 GMT"/>
-
-	      <child>
-		<widget class="GtkImage" id="image1">
-		  <property name="visible">True</property>
-		  <property name="stock">gtk-jump-to</property>
-		  <property name="icon_size">4</property>
-		  <property name="xalign">0.5</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		</widget>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">False</property>
-	      <property name="fill">False</property>
-	    </packing>
-	  </child>
 	</widget>
 	<packing>
 	  <property name="padding">0</property>
Index: vcview.py
===================================================================
--- vcview.py	(revision 1249)
+++ vcview.py	(working copy)
@@ -187,8 +187,6 @@
         self.treeview_column_location.set_visible(self.actiongroup.get_action("VcFlatten").get_active())
         self.fileentry.show() #TODO: remove once bug 97503 is fixed
         size = self.fileentry.size_request()[1]
-        self.button_jump.set_size_request(size, size)
-        self.button_jump.hide()
         if not self.prefs.vc_console_visible:
             self.on_console_view_toggle(self.console_hide_box)
 
@@ -503,36 +501,6 @@
         else: # XXX fixme
             self.refresh()
 
-    def on_button_jump_press_event(self, button, event):
-        class MyMenu(gtk.Menu):
-            def __init__(self, parent, where, showup=1):
-                gtk.Menu.__init__(self)
-                self.vcview = parent
-                self.map_id = self.connect("map", lambda item: self.on_map(item,where,showup) )
-            def add_item(self, name, submenu, showup):
-                item = gtk.MenuItem(name)
-                if submenu:
-                    item.set_submenu( MyMenu(self.vcview, submenu, showup ) )
-                self.append( item )
-            def on_map(self, item, where, showup):
-                if showup:
-                    self.add_item("..", os.path.dirname(where), 1 )
-                self.populate( where, self.listdir(where) )
-                self.show_all()
-                self.disconnect(self.map_id)
-                del self.map_id
-            def listdir(self, d):
-                try:
-                    return [p for p in os.listdir(d) if os.path.isdir( os.path.join(d,p))]
-                except OSError:
-                    return []
-            def populate(self, where, children):
-                for child in children:
-                    cc = self.listdir( os.path.join(where, child) )
-                    self.add_item( child, len(cc) and os.path.join(where,child), 0 )
-        menu = MyMenu( self, os.path.abspath(self.location) )
-        menu.popup(None, None, None, event.button, event.time)
-
     def _update_item_state(self, it, vcentry, location):
         e = vcentry
         self.model.set_state( it, 0, e.state, e.isdir )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]