[dconf-editor] Use in-app notifications on bad path.



commit aabb143fe8dc2085bd8018d8efa20db0a8d95d72
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jul 16 13:01:38 2016 +0200

    Use in-app notifications on bad path.

 editor/dconf-editor.ui    |   51 +++++++++++++++++++++++++++++++++++-
 editor/dconf-view.vala    |    2 +-
 editor/dconf-window.vala  |   19 +++++++++++++
 editor/registry-view.vala |   64 ++++++++++++++++++++++++---------------------
 4 files changed, 104 insertions(+), 32 deletions(-)
---
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 5e902b7..a394603 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -107,8 +107,57 @@
       </object>
     </child>
     <child>
-      <object class="RegistryView" id="registry_view">
+      <object class="GtkOverlay">
         <property name="visible">True</property>
+        <child>
+          <object class="RegistryView" id="registry_view">
+            <property name="visible">True</property>
+          </object>
+        </child>
+        <child type="overlay">
+          <object class="GtkRevealer" id="notification_revealer">
+            <property name="visible">True</property>
+            <property name="halign">center</property>
+            <property name="valign">start</property>
+            <child>
+              <object class="GtkFrame">
+                <property name="visible">True</property>
+                <style>
+                  <class name="app-notification"/>
+                </style>
+                <child>
+                  <object class="GtkGrid">
+                    <property name="visible">True</property>
+                    <property name="column-spacing">20</property>
+                    <child>
+                      <object class="GtkLabel" id="notification_label">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkButton">
+                        <property name="visible">True</property>
+                        <property name="focus-on-click">False</property>
+                        <property name="relief">none</property>
+                        <style>
+                          <class name="image-button"/>
+                        </style>
+                        <signal name="clicked" handler="hide_notification"/>
+                        <child>
+                          <object class="GtkImage">
+                            <property name="visible">True</property>
+                            <property name="icon-name">window-close-symbolic</property>
+                            <property name="icon-size">1</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 1e538b3..bc46943 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -337,7 +337,7 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
         return int64.parse (this.get_text ());
     }
 
-    public void reload (Variant gvariant)
+    public void reload (Variant gvariant)       // TODO "key_editor_child_number_int_real_reload: assertion 
'gvariant != NULL' failed" two times when ghosting a key
     {
         locked = 2;
         this.set_value (get_variant_as_double (gvariant));
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index ebd1516..6d8dfc9 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -49,6 +49,9 @@ class DConfWindow : ApplicationWindow
     [GtkChild] private PathBar pathbar;
     [GtkChild] private RegistryView registry_view;
 
+    [GtkChild] private Revealer notification_revealer;
+    [GtkChild] private Label notification_label;
+
     public DConfWindow ()
     {
         add_action_entries (action_entries, this);
@@ -326,4 +329,20 @@ class DConfWindow : ApplicationWindow
         registry_view.discard_row_popover ();
         registry_view.set_search_mode (false);
     }
+
+    /*\
+    * * Non-existant path notifications
+    \*/
+
+    public void show_notification (string notification)
+    {
+        notification_label.set_text (notification);
+        notification_revealer.set_reveal_child (true);
+    }
+
+    [GtkCallback]
+    private void hide_notification ()
+    {
+        notification_revealer.set_reveal_child (false);
+    }
 }
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 855ab10..7d19431 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -52,13 +52,13 @@ class RegistryView : Grid
         bind_property ("behaviour", revealer, "behaviour", 
BindingFlags.BIDIRECTIONAL|BindingFlags.SYNC_CREATE);
     }
 
-    public void init (string path, bool restore_view)
+    public void init (string path, bool restore_view)   // TODO check path format
     {
         dir_tree_view.set_model (model);
         dir_tree_view.expand_all ();
 
         current_path = path;
-        if (!restore_view || current_path == "" || !scroll_to_path (current_path))
+        if (!restore_view || current_path == "" || path [0] != '/' || !scroll_to_path (current_path))
         {
             current_path = "/";
             if (!scroll_to_path ("/"))
@@ -70,7 +70,7 @@ class RegistryView : Grid
     {
         revealer.path_changed ();
         current_path = path;
-        ((DConfWindow) this.get_parent ()).update_hamburger_menu ();
+        get_dconf_window ().update_hamburger_menu ();
     }
 
     public void enable_transition (bool enable)
@@ -99,10 +99,8 @@ class RegistryView : Grid
             return model.get_root_directory ();
     }
 
-    public bool scroll_to_path (string _full_name)      // TODO don't do all the selection work if the 
folder didn't change
+    public bool scroll_to_path (string _full_name)      // TODO don't do all the selection work if the 
folder didn't change; clarify what "return true" means
     {
-        invalidate_popovers ();
-
         string full_name = _full_name.dup ();
         string folder_name;
         if (full_name.has_suffix ("/"))
@@ -112,33 +110,35 @@ class RegistryView : Grid
 
         if (!select_folder (folder_name))
         {
-            empty_path_message_dialog ((Window) this.get_parent ());
+            get_dconf_window ().show_notification (_("Cannot find folder \"%s\".").printf (folder_name));
             return false;
         }
 
         if (full_name == folder_name)
         {
-            update_current_path (full_name);
-            stack.set_visible_child_name ("browse-view");
+            open_folder (full_name);
+            return true;
         }
-        else
-        {
-            string [] names = full_name.split ("/");
-            Key? key = get_key_from_name (names [names.length - 1]);
-            if (key == null)
-            {
-                update_current_path (folder_name);
-                stack.set_visible_child_name ("browse-view");
-                empty_path_message_dialog ((Window) this.get_parent ());
-                return false;
-            }
-            if (!properties_view.populate_properties_list_box (revealer, (!) key))
-                return false;
 
-            update_current_path (full_name);
-            stack.set_visible_child (properties_view);
+        string [] names = full_name.split ("/");
+        string key_name = names [names.length - 1];
+        Key? key = get_key_from_name (key_name);
+        if (key == null)
+        {
+            open_folder (folder_name);
+            get_dconf_window ().show_notification (_("Cannot find key \"%s\" here.").printf (key_name));
+            return true;
+        }
+        if (!properties_view.populate_properties_list_box (revealer, (!) key))
+        {
+            open_folder (folder_name);
+            get_dconf_window ().show_notification (_("Key \"%s\" has been removed.").printf (key_name));
+            return true;
         }
 
+        update_current_path (full_name);
+        invalidate_popovers ();
+        stack.set_visible_child (properties_view);
         return true;
     }
     private bool select_folder (string full_name)
@@ -178,12 +178,16 @@ class RegistryView : Grid
         }
         return null;
     }
+    private void open_folder (string folder_path)
+    {
+        update_current_path (folder_path);
+        invalidate_popovers ();
+        stack.set_visible_child_name ("browse-view");
+    }
 
-    private static void empty_path_message_dialog (Window window)
+    private DConfWindow get_dconf_window ()
     {
-        MessageDialog dialog = new MessageDialog (window, DialogFlags.MODAL, MessageType.ERROR, 
ButtonsType.OK, _("Oops! Cannot find something at this path."));
-        dialog.run ();
-        dialog.destroy ();
+        return (DConfWindow) this.get_parent ().get_parent ();
     }
 
     /*\
@@ -260,7 +264,7 @@ class RegistryView : Grid
             row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (position);
         }
         rows_possibly_with_popover.remove_all ();
-        ((DConfWindow) this.get_parent ()).update_hamburger_menu ();
+        get_dconf_window ().update_hamburger_menu ();
     }
 
     /*\
@@ -275,7 +279,7 @@ class RegistryView : Grid
     public void enter_delay_mode ()
     {
         revealer.enter_delay_mode ();
-        ((DConfWindow) this.get_parent ()).update_hamburger_menu ();
+        get_dconf_window ().update_hamburger_menu ();
     }
 
     private void set_key_value (Key key, Variant? new_value)


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