[meld/ui-next] vcview: Switch up VC selection UI to always show all options



commit 2ae54731f0c434773b78e205fcfbaf8eed0fcbaf
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 17 11:38:44 2019 +1000

    vcview: Switch up VC selection UI to always show all options
    
    The idea here is that in 99% of cases, users would only have one
    repository in a folder, but that meant that we'd show them an annoyingly
    inactive combobox with little feedback about what else we might be able
    to do, or indeed why there was only one option there.
    
    Now, we show all of our VC options in the combo with the reasons that
    they're not available indicated. We still try to maintain the same
    default selection behaviour that we had previously.

 meld/resources/ui/vcview.ui |  4 ++++
 meld/vc/__init__.py         | 20 +++-----------------
 meld/vcview.py              | 46 ++++++++++++++++++++++++++++++---------------
 3 files changed, 38 insertions(+), 32 deletions(-)
---
diff --git a/meld/resources/ui/vcview.ui b/meld/resources/ui/vcview.ui
index 0e2643c3..326fdf9d 100644
--- a/meld/resources/ui/vcview.ui
+++ b/meld/resources/ui/vcview.ui
@@ -43,9 +43,13 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="model">liststore_vcs</property>
+                <property name="popup_fixed_width">False</property>
                 <signal name="changed" handler="on_vc_change" swapped="no"/>
                 <child>
                   <object class="GtkCellRendererText">
+                    <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                    <property name="width-chars">12</property>
+                    <property name="max-width-chars">30</property>
                   </object>
                   <attributes>
                     <attribute name="text">0</attribute>
diff --git a/meld/vc/__init__.py b/meld/vc/__init__.py
index 5130cab9..07e7caab 100644
--- a/meld/vc/__init__.py
+++ b/meld/vc/__init__.py
@@ -22,7 +22,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-from . import _null, bzr, darcs, git, mercurial, svn
+from . import bzr, darcs, git, mercurial, svn
 
 # Tuple of plugins, ordered according to best-guess as to which VC a
 # user is likely to want by default in a multiple-VC situation.
@@ -42,23 +42,9 @@ def get_vcs(location):
     """
 
     vcs = []
-    max_depth = 0
     for plugin in VC_PLUGINS:
         root, location = plugin.Vc.is_in_repo(location)
-        if not root:
-            continue
-
-        # Choose the deepest root we find, unless it's from a VC that
-        # doesn't walk; these can be spurious as the real root may be
-        # much higher up in the tree.
-        depth = len(root)
-        if depth > max_depth and plugin.Vc.VC_ROOT_WALK:
-            vcs, max_depth = [], depth
-        if depth >= max_depth:
-            vcs.append(plugin.Vc)
-
-    if not vcs:
-        # No plugin recognized that location, fallback to _null
-        return [_null.Vc]
+        enabled = root is not None
+        vcs.append((plugin.Vc, enabled))
 
     return vcs
diff --git a/meld/vcview.py b/meld/vcview.py
index 6da9e08e..0363791a 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -286,6 +286,28 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         self.set_action_enabled("open-external", False)
         super().on_container_switch_out_event(window)
 
+    def get_default_vc(self, vcs):
+        target_name = self.vc.NAME if self.vc else None
+
+        for i, (name, vc, enabled) in enumerate(vcs):
+            if not enabled:
+                continue
+
+            if target_name and name == target_name:
+                return i
+
+        depths = [len(getattr(vc, 'root', [])) for name, vc, enabled in vcs]
+        target_depth = max(depths, default=0)
+
+        for i, (name, vc, enabled) in enumerate(vcs):
+            if not enabled:
+                continue
+
+            if target_depth and len(vc.root) == target_depth:
+                return i
+
+        return 0
+
     def populate_vcs_for_location(self, location):
         """Display VC plugin(s) that can handle the location"""
         vcs_model = self.combobox_vcs.get_model()
@@ -303,18 +325,22 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
             location = parent_location
         else:
             # existing parent directory was found
-            for avc in get_vcs(location):
+            for avc, enabled in get_vcs(location):
                 err_str = ''
                 vc_details = {'name': avc.NAME, 'cmd': avc.CMD}
 
-                if not avc.is_installed():
+                if not enabled:
+                    # Translators: This error message is shown when no
+                    # repository of this type is found.
+                    err_str = _("%(name)s (not found)")
+                elif not avc.is_installed():
                     # Translators: This error message is shown when a version
                     # control binary isn't installed.
                     err_str = _("%(name)s (%(cmd)s not installed)")
                 elif not avc.valid_repo(location):
                     # Translators: This error message is shown when a version
                     # controlled repository is invalid.
-                    err_str = _("%(name)s (Invalid repository)")
+                    err_str = _("%(name)s (invalid repository)")
 
                 if err_str:
                     vcs_model.append([err_str % vc_details, avc, False])
@@ -322,27 +348,17 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
 
                 vcs_model.append([avc.NAME, avc(location), True])
 
-        valid_vcs = [(i, r[1].NAME) for i, r in enumerate(vcs_model) if r[2]]
-        default_active = min(valid_vcs)[0] if valid_vcs else 0
-
-        # Keep the same VC plugin active on refresh, otherwise use the first
-        current_vc_name = self.vc.NAME if self.vc else None
-        same_vc = [i for i, name in valid_vcs if name == current_vc_name]
-        if same_vc:
-            default_active = same_vc[0]
+        default_active = self.get_default_vc(vcs_model)
 
-        if not valid_vcs:
+        if not any(enabled for _, _, enabled in vcs_model):
             # If we didn't get any valid vcs then fallback to null
             null_vcs = _null.Vc(location)
             vcs_model.insert(0, [null_vcs.NAME, null_vcs, True])
             tooltip = _("No valid version control system found in this folder")
-        elif len(vcs_model) == 1:
-            tooltip = _("Only one version control system found in this folder")
         else:
             tooltip = _("Choose which version control system to use")
 
         self.combobox_vcs.set_tooltip_text(tooltip)
-        self.combobox_vcs.set_sensitive(len(vcs_model) > 1)
         self.combobox_vcs.set_active(default_active)
 
     @Template.Callback()


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