[dconf-editor] Warn if multiple schemas use the same path.



commit 8c3cf378de176c1d83e814dbe2b4edc943e32f5b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Oct 28 15:26:04 2017 +0200

    Warn if multiple schemas use the same path.

 editor/dconf-model.vala   |   14 ++++++++++++++
 editor/registry-info.ui   |   25 +++++++++++++++++++++++++
 editor/registry-info.vala |    2 ++
 editor/registry-view.ui   |   25 +++++++++++++++++++++++++
 editor/registry-view.vala |    6 ++++++
 5 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 07a97f3..f6dc0b9 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -37,6 +37,8 @@ public class Directory : SettingObject
     public HashTable<string, Directory> child_map = new HashTable<string, Directory> (str_hash, str_equal);
     public List<Directory> children = new List<Directory> ();     // TODO remove
 
+    public bool warning_multiple_schemas = false;
+
     public Directory (Directory? parent, string name, DConf.Client client)
     {
         Object (nullable_parent: parent, name: name);
@@ -584,6 +586,8 @@ public class SettingsModel : Object, Gtk.TreeModel
         string [] non_relocatable_schemas;
         string [] relocatable_schemas;
 
+        HashTable<string, Directory> path_and_schema = new HashTable<string, Directory> (str_hash, 
str_equal);
+
         settings_schema_source.list_schemas (true, out non_relocatable_schemas, out relocatable_schemas);
 
         foreach (string schema_id in non_relocatable_schemas)
@@ -593,8 +597,18 @@ public class SettingsModel : Object, Gtk.TreeModel
                 continue;       // TODO better
 
             string schema_path = ((!) settings_schema).get_path ();
+
             Directory view = create_gsettings_views (root, schema_path [1:schema_path.length]);
             view.init_gsettings_keys ((!) settings_schema);
+
+            Directory? schema_already_installed_there = path_and_schema.lookup (schema_path);
+            if (schema_already_installed_there != null)
+            {
+                ((!) schema_already_installed_there).warning_multiple_schemas = true;
+                view.warning_multiple_schemas = true;
+            }
+            else
+                path_and_schema.insert (schema_path, view);
         }
     }
 
diff --git a/editor/registry-info.ui b/editor/registry-info.ui
index 16e7245..9219c2d 100644
--- a/editor/registry-info.ui
+++ b/editor/registry-info.ui
@@ -4,6 +4,31 @@
   <template class="RegistryInfo" parent="GtkGrid">
     <property name="orientation">vertical</property>
     <child>
+      <object class="GtkRevealer" id="multiple_schemas_warning_revealer">
+        <property name="visible">True</property>
+        <property name="reveal-child">False</property>
+        <child>
+          <object class="GtkInfoBar">
+            <property name="visible">True</property>
+            <property name="message-type">warning</property>
+            <child internal-child="content_area">
+              <object class="GtkBox">
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="max-width-chars">40</property>
+                    <property name="wrap">True</property>
+                    <property name="label" translatable="yes">Multiple schemas are installed at the parent 
path. This key might be defined and used by more than one schema. This could lead to problems. Edit value at 
your own risk.</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
       <object class="GtkRevealer" id="no_schema_warning"> <!-- TODO report bug: hiding and showing infobar 
fails to draw it the 2nd time -->
         <property name="visible">True</property>
         <property name="reveal-child">False</property>
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index c5cfafe..a9b92c0 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -20,6 +20,7 @@ using Gtk;
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-info.ui")]
 class RegistryInfo : Grid
 {
+    [GtkChild] private Revealer multiple_schemas_warning_revealer;
     [GtkChild] private Revealer no_schema_warning;
     [GtkChild] private Revealer one_choice_warning_revealer;
     [GtkChild] private Label one_choice_enum_warning;
@@ -67,6 +68,7 @@ class RegistryInfo : Grid
         unowned Variant [] dict_container;
         key.properties.get ("(ba{ss})", out has_schema, out dict_container);
 
+        multiple_schemas_warning_revealer.set_reveal_child (has_schema && 
key.parent.warning_multiple_schemas);
         no_schema_warning.set_reveal_child (!has_schema);
 
         properties_list_box.@foreach ((widget) => widget.destroy ());
diff --git a/editor/registry-view.ui b/editor/registry-view.ui
index df6569e..21f8c74 100644
--- a/editor/registry-view.ui
+++ b/editor/registry-view.ui
@@ -14,6 +14,31 @@
       </object>
     </child>
     <child>
+      <object class="GtkRevealer" id="multiple_schemas_warning_revealer">
+        <property name="visible">True</property>
+        <property name="reveal-child">False</property>
+        <child>
+          <object class="GtkInfoBar">
+            <property name="visible">True</property>
+            <property name="message-type">warning</property>
+            <child internal-child="content_area">
+              <object class="GtkBox">
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="max-width-chars">40</property>
+                    <property name="wrap">True</property>
+                    <property name="label" translatable="yes">Multiple schemas are installed at this path. 
This could lead to problems if it hasn’t been done carefully. Only one schema is displayed here. Edit values 
at your own risk.</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
       <object class="GtkRevealer" id="need_reload_warning_revealer">
         <property name="visible">True</property>
         <property name="reveal-child">False</property>
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index a090449..d180cde 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -26,6 +26,8 @@ class RegistryView : Grid, PathElement
 
     private GLib.Settings application_settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
     [GtkChild] private Revealer need_reload_warning_revealer;
+    [GtkChild] private Revealer multiple_schemas_warning_revealer;
+    private bool multiple_schemas_warning_needed;
 
     private SettingsModel model = new SettingsModel ();
     [GtkChild] private TreeView dir_tree_view;
@@ -94,6 +96,7 @@ class RegistryView : Grid, PathElement
     {
         stack.set_transition_type (current_path.has_prefix (path) ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
         need_reload_warning_revealer.set_reveal_child (false);
+        multiple_schemas_warning_revealer.set_reveal_child (multiple_schemas_warning_needed);
         update_current_path (path);
         get_selected_directory ().sort_key_model (application_settings.get_boolean ("sort-case-sensitive"));
         stack.set_visible_child_name ("browse-view");
@@ -142,6 +145,7 @@ class RegistryView : Grid, PathElement
     private void show_properties_view (string path)
     {
         need_reload_warning_revealer.set_reveal_child (false);
+        multiple_schemas_warning_revealer.set_reveal_child (false);
 
         stack.set_transition_type (path.has_prefix (current_path) && current_path.length == 
path.last_index_of_char ('/') + 1 ? StackTransitionType.CROSSFADE : StackTransitionType.NONE);
         update_current_path (path);
@@ -168,6 +172,8 @@ class RegistryView : Grid, PathElement
         dir.sort_key_model (application_settings.get_boolean ("sort-case-sensitive"));
         key_model = dir.key_model;
 
+        multiple_schemas_warning_needed = dir.warning_multiple_schemas;
+
         key_list_box.bind_model (key_model, new_list_box_row);
     }
 


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