Re: [PATCH] Multi-VC chooser preferences



Here is the version that always have the combobox,
greyed when there is only one item, that shows the
list of VC plugins able to handle the location.

This is not so ugly as my first attempt at doing it
this way... The key to that was using a 2 column
ListStore, instead of just a single
gtk.combo_box_new_text() one

But, there are still 2 small things to shake out:

1) I get those gtk assertion failures

gnomeglade.py:45: GtkWarning: gtk_tree_row_reference_new:
assertion `GTK_IS_TREE_MODEL (model)' failed
  self.xml = gtk.glade.XML(filename, root, typedict=override)

gnomeglade.py:45: GtkWarning: gtk_cell_view_set_displayed_row:
assertion `GTK_IS_TREE_MODEL (cell_view->priv->model)' failed
  self.xml = gtk.glade.XML(filename, root, typedict=override)

2) When viewing a location that has a single git repository
after having been in a git+hg one, the size of the combobox
stays the same, whereas it should shrink. Refreshing or
re-entering the same location make the combobox shrink
to the right size.

Stephens patch for historyentry is included, but should be
committed separately. This is just for review.

-- 
Vincent Legoll
Index: vcview.py
===================================================================
--- vcview.py	(revision 1219)
+++ vcview.py	(working copy)
@@ -191,35 +191,35 @@
         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.set_model(gtk.ListStore(str, object))
+        cell = gtk.CellRendererText()
+        self.combobox_vcs.pack_start(cell, False)
+        self.combobox_vcs.add_attribute(cell, 'text', 0)
 
     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()
+        for avc in vcs:
+            self.combobox_vcs.get_model().append([avc.NAME, avc])
+        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 1219)
+++ 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="yes">Pick one source control plugin</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 1219)
+++ 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 1219)
+++ 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()


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