Re: [PATCH] Multi-VC chooser preferences



Hello,
here is a first step in the hopefully right direction.

A combobox is added at the left side of the location
text entry & button.

But I have a hard time giving that combobox the same
size as the text entry and the button...

The problem is far more visible on my gentoo desktop
than on the ubuntu notebook, but could be better.

Tell me what you think of this one.

-- 
Vincent Legoll
Index: vcview.py
===================================================================
--- vcview.py	(révision 1217)
+++ vcview.py	(copie de travail)
@@ -191,35 +191,39 @@
         self.button_jump.hide()
         if not self.prefs.vc_console_visible:
             self.on_console_view_toggle(self.console_hide_box)
+        self.combobox_vcs = None
+        self.vc = None
 
     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()]]
+        """Callback from vc.Vc() to allow choosing between multiple plugins able to handle one location"""
+        if self.combobox_vcs:
+            self.hbox2.remove(self.combobox_vcs)
+        self.combobox_vcs = gtk.combo_box_new_text()
+        self.hbox2.pack_start(self.combobox_vcs, False, False)
+        for avc in vcs:
+            self.combobox_vcs.append_text(avc.NAME)
+        self.combobox_vcs.set_active(0)
+        self.combobox_vcs.connect("changed", self.on_vc_change)
+        self.combobox_vcs.show()
+        return vc.choose_vc_by_name(vcs, self.combobox_vcs.get_active_text())
   
+    def on_vc_change(self, cb):
+        location = self.fileentry.gtk_entry.get_text()
+        self.vc = vc.get_vc_by_name(location, cb.get_active_text())
+        self._set_location(location)
+
     def set_location(self, location):
+        # Hide the combobox since we're going to a potentially single
+        # VC directory and then won't go through self.choose_vc()
+        if self.combobox_vcs:
+            self.combobox_vcs.hide()
+        self.vc = vc.Vc(location, self.choose_vc)
+        self._set_location(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: vc/__init__.py
===================================================================
--- vc/__init__.py	(révision 1218)
+++ vc/__init__.py	(copie de travail)
@@ -33,7 +33,16 @@
         ret.append( __import__(modname, globals(), locals(), "*") )
     return ret
 _plugins = load_plugins()
+_plugins_map = dict([(pl.Vc.NAME.upper(), pl) for pl in _plugins])
 
+def get_vc_by_name(location, name):
+    return _plugins_map[name.upper()].Vc(location)
+
+def choose_vc_by_name(vcs, name):
+    for avc in vcs:
+        if isinstance(avc, _plugins_map[name.upper()].Vc):
+            return avc
+
 def default_plugin_order(vcs):
     # Pick the Vc with the longest repo root
     return max(vcs, key=lambda repo: len(repo.root))


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