[dconf-editor] Remove some sorting options.



commit 29af14a6c608d32ff00644d4b0c2056fd6495967
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Jan 22 02:59:36 2018 +0100

    Remove some sorting options.

 editor/browser-view.vala                 |  105 +++++++++--------------------
 editor/ca.desrt.dconf-editor.gschema.xml |   10 ---
 editor/key-list-box-row.vala             |    2 +-
 editor/registry-view.vala                |   10 +++-
 4 files changed, 43 insertions(+), 84 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index e7c496c..937eb9d 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -336,48 +336,23 @@ public interface BrowsableView
 * * Sorting
 \*/
 
-public enum MergeType {
-    MIXED,
-    FIRST,
-    LAST
-}
-
 public class SortingOptions : Object
 {
     private GLib.Settings settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
 
     public bool case_sensitive { get; set; default = false; }
-    public MergeType sort_folders { get; set; default = MergeType.MIXED; }
 
     construct
     {
         settings.bind ("sort-case-sensitive", this, "case-sensitive", GLib.SettingsBindFlags.GET);
-        settings.bind ("sort-folders", this, "sort-folders", GLib.SettingsBindFlags.GET);
     }
 
     public SettingComparator get_comparator ()
     {
-        if (sort_folders == MergeType.FIRST)
-        {
-            if (case_sensitive)
-                return new FoldersFirstCaseSensitive ();
-            else
-                return new FoldersFirstCaseInsensitive ();
-        }
-        else if (sort_folders == MergeType.LAST)
-        {
-            if (case_sensitive)
-                return new FoldersLastCaseSensitive ();
-            else
-                return new FoldersLastCaseInsensitive ();
-        }
-        else // if (sort_folders == MergeType.MIXED)
-        {
-            if (case_sensitive)
-                return new FoldersMixedCaseSensitive ();
-            else
-                return new FoldersMixedCaseInsensitive ();
-        }
+        if (case_sensitive)
+            return new BySchemaCaseSensitive ();
+        else
+            return new BySchemaCaseInsensitive ();
     }
 
     public void sort_key_model (GLib.ListStore model)
@@ -408,68 +383,54 @@ public class SortingOptions : Object
 public interface SettingComparator : Object
 {
     public abstract int compare (SettingObject a, SettingObject b);
-}
-
-class FoldersMixedCaseInsensitive : Object, SettingComparator
-{
-    public int compare (SettingObject a, SettingObject b)
-    {
-        return a.casefolded_name.collate (b.casefolded_name);
-    }
-}
-
-class FoldersMixedCaseSensitive : Object, SettingComparator
-{
-    public int compare (SettingObject a, SettingObject b)
-    {
-        return strcmp (a.name, b.name);
-    }
-}
 
-class FoldersFirstCaseInsensitive : Object, SettingComparator
-{
-    public int compare (SettingObject a, SettingObject b)
+    protected virtual bool sort_directories_first (SettingObject a, SettingObject b, ref int return_value)
     {
         if (a is Directory && !(b is Directory))
-            return -1;
-        if (!(a is Directory) && b is Directory)
-            return 1;
-        return a.casefolded_name.collate (b.casefolded_name);
+            return_value = -1;
+        else if (!(a is Directory) && b is Directory)
+            return_value = 1;
+        else
+            return false;
+        return true;
     }
-}
 
-class FoldersFirstCaseSensitive : Object, SettingComparator
-{
-    public int compare (SettingObject a, SettingObject b)
+    protected virtual bool sort_dconf_keys_second (SettingObject a, SettingObject b, ref int return_value)
     {
-        if (a is Directory && !(b is Directory))
-            return -1;
-        if (!(a is Directory) && b is Directory)
-            return 1;
-        return strcmp (a.name, b.name);
+        if (a is DConfKey && !(b is DConfKey))
+            return_value = -1;
+        else if (!(a is DConfKey) && b is DConfKey)
+            return_value = 1;
+        else
+            return false;
+        return true;
     }
 }
 
-class FoldersLastCaseInsensitive : Object, SettingComparator
+class BySchemaCaseInsensitive : Object, SettingComparator
 {
     public int compare (SettingObject a, SettingObject b)
     {
-        if (a is Directory && !(b is Directory))
-            return 1;
-        if (!(a is Directory) && b is Directory)
-            return -1;
+        int return_value = 0;
+        if (sort_directories_first (a, b, ref return_value))
+            return return_value;
+        if (sort_dconf_keys_second (a, b, ref return_value))
+            return return_value;
+
         return a.casefolded_name.collate (b.casefolded_name);
     }
 }
 
-class FoldersLastCaseSensitive : Object, SettingComparator
+class BySchemaCaseSensitive : Object, SettingComparator
 {
     public int compare (SettingObject a, SettingObject b)
     {
-        if (a is Directory && !(b is Directory))
-            return 1;
-        if (!(a is Directory) && b is Directory)
-            return -1;
+        int return_value = 0;
+        if (sort_directories_first (a, b, ref return_value))
+            return return_value;
+        if (sort_dconf_keys_second (a, b, ref return_value))
+            return return_value;
+
         return strcmp (a.name, b.name);
     }
 }
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
index cee383f..657f3af 100644
--- a/editor/ca.desrt.dconf-editor.gschema.xml
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -88,11 +88,6 @@
     <value value="3" nick="always-confirm-explicit"/>
     <value value="4" nick="always-delay"/>
   </enum>
-  <enum id="ca.desrt.dconf-editor.MergeType">
-    <value value="0" nick="mixed"/>
-    <value value="1" nick="first"/>
-    <value value="2" nick="last"/>
-  </enum>
   <flags id="ca.desrt.dconf-editor.RelocatableSchemasEnabledMappings">
     <value value="1" nick="User"/>
     <value value="2" nick="Built-in"/>
@@ -156,11 +151,6 @@
       <summary>A flag to sort keys list case-sensitively</summary>
       <description>GSettings doesn’t allow keys to use upper-case in their names, but installation paths of 
schemas can. If “true”, the keys list is sorted case-sensitively, with in usual order upper-case folders 
first.</description>
     </key>
-    <key name="sort-folders" enum="ca.desrt.dconf-editor.MergeType">
-      <default>'mixed'</default>
-      <summary>A flag to sort folders before, after or mixed with keys</summary>
-      <description>If “mixed”, folders are sorted together with keys; if “first”, all folders are sorted 
before keys; if “last”, all folders are sorted after keys.</description>
-    </key>
     <key type="b" name="mouse-use-extra-buttons">
       <default>true</default>
       <summary>Use “Back” and “Forward” mouse button events</summary>
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index d69a715..147af4c 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -45,7 +45,7 @@ private class ListBoxRowHeader : Grid
         natural_width = MAX_ROW_WIDTH;
     }
 
-    public ListBoxRowHeader (bool is_first_row, string? header_text = null)
+    public ListBoxRowHeader (bool is_first_row, string? header_text)
     {
         if (header_text == null)
         {
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 611e675..97048cc 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -151,7 +151,15 @@ class RegistryView : Grid, BrowsableView
 
     private void update_row_header (ListBoxRow row, ListBoxRow? before)
     {
-        ListBoxRowHeader header = new ListBoxRowHeader (before == null);
+        string? label_text = null;
+        if      ((row.get_child () is KeyListBoxRowEditable)
+              && (before == null || !(((!) before).get_child () is KeyListBoxRowEditable)))
+            label_text = _("Keys defined by a schema");
+        else if ((row.get_child () is KeyListBoxRowEditableNoSchema)
+              && (before == null || !(((!) before).get_child () is KeyListBoxRowEditableNoSchema)))
+            label_text = _("Keys not defined by a schema");
+
+        ListBoxRowHeader header = new ListBoxRowHeader (before == null, label_text);
         row.set_header (header);
     }
 


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