[dconf-editor] Use a template for the window.



commit de80a3ba3cd89b4ea0803c2c517de9b9045ee907
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Apr 20 14:34:11 2015 +0200

    Use a template for the window.

 configure.ac             |   18 ++-
 editor/Makefile.am       |   20 +--
 editor/dconf-editor.ui   |   17 +-
 editor/dconf-editor.vala |  373 +++++-----------------------------------------
 editor/dconf-window.vala |  340 ++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in           |    1 +
 po/POTFILES.skip         |    1 +
 7 files changed, 412 insertions(+), 358 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 452371c..bf1ccf3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,11 +27,19 @@ AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
 GLIB_GSETTINGS
 
 # Dependencies
-PKG_CHECK_MODULES(dconf, dconf >= 0.23.2)
-PKG_CHECK_MODULES(glib, glib-2.0 >= 2.39.3)
-PKG_CHECK_MODULES(gmodule, gmodule-2.0)
-PKG_CHECK_MODULES(gtk, gtk+-3.0 >= 3.14)
-PKG_CHECK_MODULES(libxml, libxml-2.0)
+DCONF_REQUIRED=0.23.2
+GLIB_REQUIRED=2.39.3
+GTK_REQUIRED=3.14.0
+
+PKG_CHECK_MODULES(DCONF_EDITOR, [
+  glib-2.0 >= $GLIB_REQUIRED
+  gtk+-3.0 >= $GTK_REQUIRED
+  dconf >= $DCONF_REQUIRED
+  gmodule-2.0
+  libxml-2.0
+])
+
+AC_SUBST([GLIB_REQUIRED])
 
 dnl Gettext support
 GETTEXT_PACKAGE=dconf
diff --git a/editor/Makefile.am b/editor/Makefile.am
index 20b020c..ee3d495 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -2,28 +2,23 @@ bin_PROGRAMS = dconf-editor
 
 dconf_editor_VALAFLAGS = \
        --pkg posix \
+       --pkg gio-2.0 \
        --pkg gtk+-3.0 \
        --pkg gmodule-2.0 \
        --pkg libxml-2.0 \
-       --pkg dconf
+       --pkg dconf \
+       --gresources $(builddir)/dconf-editor.gresource.xml \
+       --target-glib $(GLIB_REQUIRED)
 
-dconf_editor_LDADD = \
-       $(dconf_LIBS) \
-       $(gtk_LIBS) \
-       $(gee_LIBS) \
-       $(gmodule_LIBS) \
-       $(libxml_LIBS)
+dconf_editor_LDADD = $(DCONF_EDITOR_LIBS)
 
 dconf_editor_CFLAGS = \
-       $(dconf_CFLAGS) \
-       $(gtk_CFLAGS) \
-       $(gee_CFLAGS) \
-       $(libxml_CFLAGS) \
        -DPKGDATADIR=\"$(pkgdatadir)\" \
        -DVERSION=\"$(VERSION)\" \
        -DLOCALEDIR=\"$(localedir)\" \
        -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
-       -w
+       -w \
+       $(DCONF_EDITOR_CFLAGS)
 
 resource_data = \
        dconf-editor.gresource.xml \
@@ -38,6 +33,7 @@ nodist_dconf_editor_SOURCES = resources.c
 dconf_editor_SOURCES = \
        config.vapi \
        dconf-editor.vala \
+       dconf-window.vala \
        dconf-model.vala \
        dconf-schema.vala \
        dconf-view.vala
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index e6a72a3..5e5c90a 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -1,11 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkAction" id="set_default_action">
-    <property name="label" translatable="yes">Set to Default</property>
-    <property name="sensitive">False</property>
-  </object>
-  <object class="GtkApplicationWindow" id="window">
+  <template class="DConfWindow" parent="GtkApplicationWindow">
     <property name="visible">False</property>
     <property name="title" translatable="yes">dconf Editor</property>
     <child>
@@ -227,10 +223,11 @@
                         <child>
                           <object class="GtkButton">
                             <property name="visible">True</property>
+                            <property name="label" translatable="yes">Set to Default</property>
                             <property name="can_focus">True</property>
                             <property name="valign">end</property>
                             <property name="receives_default">True</property>
-                            <property name="related_action">set_default_action</property>
+                            <property name="action_name">win.set-default</property>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -297,13 +294,15 @@
             <property name="can_focus">False</property>
             <property name="border_width">6</property>
             <property name="spacing">6</property>
+            <signal name="key_press_event" handler="on_key_press_event"/>
             <child>
-              <object class="GtkButton" id="search_box_close_button">
+              <object class="GtkButton">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_action_appearance">False</property>
                 <property name="relief">none</property>
+                <signal name="clicked" handler="on_close_button_clicked"/>
                 <child>
                   <object class="GtkImage">
                     <property name="visible">True</property>
@@ -323,6 +322,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">•</property>
+                <signal name="activate" handler="find_next_cb"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -338,6 +338,7 @@
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_action_appearance">False</property>
+                <signal name="clicked" handler="find_next_cb"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -366,5 +367,5 @@
         </child>
       </object>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index c9fa6be..ad10e50 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -1,27 +1,11 @@
 class ConfigurationEditor : Gtk.Application
 {
-    private SettingsModel model;
-
     private Settings settings;
-    private Gtk.ApplicationWindow window;
+    private DConfWindow window;
     private int window_width = 0;
     private int window_height = 0;
     private bool window_is_maximized = false;
     private bool window_is_fullscreen = false;
-    private Gtk.TreeView dir_tree_view;
-    private Gtk.TreeView key_tree_view;
-    private Gtk.Grid key_info_grid;
-    private Gtk.Label schema_label;
-    private Gtk.Label summary_label;
-    private Gtk.Label description_label;
-    private Gtk.Label type_label;
-    private Gtk.Label default_label;
-    private Gtk.Action set_default_action;
-    private Gtk.Box search_box;
-    private Gtk.Entry search_entry;
-    private Gtk.Label search_label;
-
-    private Key? selected_key;
 
     private const OptionEntry[] option_entries =
     {
@@ -31,18 +15,33 @@ class ConfigurationEditor : Gtk.Application
 
     private const GLib.ActionEntry[] action_entries =
     {
-        { "find",  find_cb  },
+        { "find", find_cb },
         { "about", about_cb },
-        { "quit",  quit  }
+        { "quit", quit }
     };
 
-    public ConfigurationEditor()
+    /*\
+    * * Application init
+    \*/
+
+    public ConfigurationEditor ()
     {
-        Object(application_id: "ca.desrt.dconf-editor", flags: ApplicationFlags.FLAGS_NONE);
+        Object (application_id: "ca.desrt.dconf-editor", flags: ApplicationFlags.FLAGS_NONE);
 
         add_main_option_entries (option_entries);
     }
 
+    public static int main (string[] args)
+    {
+        Intl.setlocale (LocaleCategory.ALL, "");
+        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+        Intl.textdomain (Config.GETTEXT_PACKAGE);
+
+        var app = new ConfigurationEditor ();
+        return app.run (args);
+    }
+
     protected override int handle_local_options (GLib.VariantDict options)
     {
         if (options.contains ("version"))
@@ -56,21 +55,18 @@ class ConfigurationEditor : Gtk.Application
         return -1;
     }
 
-    protected override void startup()
+    protected override void startup ()
     {
-        base.startup();
+        base.startup ();
 
         Environment.set_application_name (_("dconf Editor"));
 
         add_action_entries (action_entries, this);
 
-        settings = new Settings ("ca.desrt.dconf-editor.Settings");
-
-        Gtk.Builder ui = new Gtk.Builder.from_resource ("/ca/desrt/dconf-editor/ui/dconf-editor.ui");
-
         /* window */
-        window = (Gtk.ApplicationWindow) ui.get_object ("window");
+        window = new DConfWindow ();
 
+        settings = new Settings ("ca.desrt.dconf-editor.Settings");
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-fullscreen"))
             window.fullscreen ();
@@ -81,209 +77,25 @@ class ConfigurationEditor : Gtk.Application
         window.size_allocate.connect (size_allocate_cb);
 
         add_window (window);
-
-        /* named objects apart search box */
-        key_info_grid = (Gtk.Grid) ui.get_object("key_info_grid");
-        schema_label = (Gtk.Label) ui.get_object("schema_label");
-        summary_label = (Gtk.Label) ui.get_object("summary_label");
-        description_label = (Gtk.Label) ui.get_object("description_label");
-        type_label = (Gtk.Label) ui.get_object("type_label");
-        default_label = (Gtk.Label) ui.get_object("default_label");
-
-        set_default_action = (Gtk.Action) ui.get_object("set_default_action");
-        set_default_action.activate.connect(set_default_cb);
-
-        dir_tree_view = (Gtk.TreeView) ui.get_object("dir_tree_view");
-
-        /* trees */
-        key_tree_view = new DConfKeyView ();
-        key_tree_view.show ();
-        key_tree_view.get_selection ().changed.connect (key_selected_cb);
-        var scroll = (Gtk.ScrolledWindow) ui.get_object("key_scrolledwindow");
-        scroll.add (key_tree_view);
-
-        model = new SettingsModel ();
-        dir_tree_view.set_model (model);
-
-        Gtk.TreeSelection selection = dir_tree_view.get_selection ();
-        selection.changed.connect (dir_selected_cb);
-
-        Gtk.TreeIter iter;
-        if (model.get_iter_first (out iter))
-            selection.select_iter (iter);
-
-        /* search box */
-        search_box = (Gtk.Box) ui.get_object("search_box");
-        search_box.key_press_event.connect ((event) =>
-        {
-            if (event.keyval == Gdk.Key.Escape)
-            {
-                search_box.hide();
-                return true;
-            }
-            return false;
-        });
-        search_entry = (Gtk.Entry) ui.get_object("search_entry");
-        search_label = (Gtk.Label) ui.get_object("search_label");
-        search_entry.activate.connect(find_next_cb);
-        var search_box_close_button = (Gtk.Button) ui.get_object("search_box_close_button");
-        search_box_close_button.clicked.connect(() =>
-        {
-            search_box.hide();
-        });
-
-        var search_next_button = (Gtk.Button) ui.get_object("search_next_button");
-        search_next_button.clicked.connect(find_next_cb);
     }
 
-    protected override void activate()
+    protected override void activate ()
     {
-        window.present();
+        window.present ();
     }
 
     protected override void shutdown ()
     {
-        base.shutdown();
+        base.shutdown ();
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
         settings.set_boolean ("window-is-maximized", window_is_maximized);
         settings.set_boolean ("window-is-fullscreen", window_is_fullscreen);
     }
 
-    private void dir_selected_cb()
-    {
-        KeyModel? key_model = null;
-
-        Gtk.TreeIter iter;
-        if (dir_tree_view.get_selection().get_selected(null, out iter))
-            key_model = model.get_directory(iter).key_model;
-
-        key_tree_view.set_model(key_model);
-
-        /* Always select something */
-        if (key_model != null && key_model.get_iter_first(out iter))
-            key_tree_view.get_selection().select_iter(iter);
-    }
-
-    private string key_to_description(Key key)
-    {
-        switch(key.schema.type)
-        {
-        case "y":
-        case "n":
-        case "q":
-        case "i":
-        case "u":
-        case "x":
-        case "t":
-            Variant min, max;
-            if (key.schema.range != null)
-            {
-                min = key.schema.range.min;
-                max = key.schema.range.max;
-            }
-            else
-            {
-                min = key.get_min();
-                max = key.get_max();
-            }
-            return _("Integer [%s..%s]").printf(min.print(false), max.print(false));
-        case "d":
-            Variant min, max;
-            if (key.schema.range != null)
-            {
-                min = key.schema.range.min;
-                max = key.schema.range.max;
-            }
-            else
-            {
-                min = key.get_min();
-                max = key.get_max();
-            }
-            return _("Double [%s..%s]").printf(min.print(false), max.print(false));
-        case "b":
-            return _("Boolean");
-        case "s":
-            return _("String");
-        case "<enum>":
-            return _("Enumeration");
-        default:
-            return key.schema.type;
-        }
-    }
-
-    private void key_selected_cb()
-    {
-        if(selected_key != null)
-            selected_key.value_changed.disconnect(key_changed_cb);
-
-        Gtk.TreeIter iter;
-        Gtk.TreeModel model;
-        if (key_tree_view.get_selection().get_selected(out model, out iter))
-        {
-            var key_model = (KeyModel) model;
-            selected_key = key_model.get_key(iter);
-        }
-        else
-            selected_key = null;
-
-        if(selected_key != null)
-            selected_key.value_changed.connect(key_changed_cb);
-
-        key_info_grid.sensitive = selected_key != null;
-        set_default_action.sensitive = selected_key != null && !selected_key.is_default;
-
-        string schema_name = "", summary = "", description = "", type = "", default_value = "";
-
-        if (selected_key != null)
-        {
-            if (selected_key.schema != null)
-            {
-                var gettext_domain = selected_key.schema.gettext_domain;
-                schema_name = selected_key.schema.schema.id;
-                if (selected_key.schema.summary != null)
-                    summary = selected_key.schema.summary;
-                if (gettext_domain != null && summary != "")
-                    summary = dgettext(gettext_domain, summary);
-                if (selected_key.schema.description != null)
-                    description = selected_key.schema.description;
-                if (gettext_domain != null && description != "")
-                    description = dgettext(gettext_domain, description);
-                type = key_to_description(selected_key);
-                default_value = selected_key.schema.default_value.print(false);
-            }
-            else
-            {
-                schema_name = _("No schema");
-            }
-        }
-
-        schema_label.set_text(schema_name);
-        summary_label.set_text(summary.strip());
-        description_label.set_text(description.strip());
-        type_label.set_text(type);
-        default_label.set_text(default_value);
-    }
-
-    private void key_changed_cb(Key key)
-    {
-        set_default_action.sensitive = selected_key != null && !selected_key.is_default;
-    }
-
-    private void set_default_cb (Gtk.Action action)
-    {
-        if (selected_key == null)
-            return;
-        selected_key.set_to_default();
-    }
-
-    private void size_allocate_cb (Gtk.Allocation allocation)
-    {
-        if (window_is_maximized || window_is_fullscreen)
-            return;
-        window_width = allocation.width;
-        window_height = allocation.height;
-    }
+    /*\
+    * * Window callbacks
+    \*/
 
     private bool window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
     {
@@ -295,118 +107,24 @@ class ConfigurationEditor : Gtk.Application
         return false;
     }
 
-    private void find_cb()
-    {
-        search_box.show();
-        search_entry.grab_focus();
-    }
-
-    private void find_next_cb()
+    private void size_allocate_cb (Gtk.Allocation allocation)
     {
-        search_label.set_text("");
-
-        /* Get the current position in the tree */
-        Gtk.TreeIter iter;
-        var key_iter = Gtk.TreeIter();
-        var have_key_iter = false;
-        if (dir_tree_view.get_selection().get_selected(null, out iter))
-        {
-            if (key_tree_view.get_selection().get_selected(null, out key_iter))
-            {
-                var dir = model.get_directory(iter);
-                if (dir.key_model.iter_next(ref key_iter))
-                    have_key_iter = true;
-                else
-                    get_next_iter(ref iter);
-            }
-        }
-        else if (!model.get_iter_first(out iter))
+        if (window_is_maximized || window_is_fullscreen)
             return;
-
-        var on_first_directory = true;
-        do
-        {
-            /* Select next directory that matches */
-            var dir = model.get_directory(iter);
-            if (!have_key_iter)
-            {
-                have_key_iter = dir.key_model.get_iter_first(out key_iter);
-                if (!on_first_directory && dir.name.index_of(search_entry.text) >= 0)
-                {
-                    dir_tree_view.expand_to_path(model.get_path(iter));
-                    dir_tree_view.get_selection().select_iter(iter);
-                    dir_tree_view.scroll_to_cell(model.get_path(iter), null, false, 0, 0);
-                    return;
-                }
-            }
-            on_first_directory = false;
-
-            /* Select next key that matches */
-            if (have_key_iter)
-            {
-                do
-                {
-                    var key = dir.key_model.get_key(key_iter);
-                    if (key_matches(key, search_entry.text))
-                    {
-                        dir_tree_view.expand_to_path(model.get_path(iter));
-                        dir_tree_view.get_selection().select_iter(iter);
-                        dir_tree_view.scroll_to_cell(model.get_path(iter), null, false, 0, 0);
-                        key_tree_view.get_selection().select_iter(key_iter);
-                        key_tree_view.scroll_to_cell(dir.key_model.get_path(key_iter), null, false, 0, 0);
-                        return;
-                    }
-                } while(dir.key_model.iter_next(ref key_iter));
-            }
-            have_key_iter = false;
-        } while(get_next_iter(ref iter));
-
-        search_label.set_text(_("Not found"));
+        window_width = allocation.width;
+        window_height = allocation.height;
     }
 
-    private bool key_matches (Key key, string text)
-    {
-        /* Check key name */
-        if (key.name.index_of(text) >= 0)
-            return true;
-
-        /* Check key schema (description) */
-        if (key.schema != null)
-        {
-            if (key.schema.summary != null && key.schema.summary.index_of(text) >= 0)
-                return true;
-            if (key.schema.description != null && key.schema.description.index_of(text) >= 0)
-                return true;
-        }
+    /*\
+    * * App-menu callbacks
+    \*/
 
-        /* Check key value */
-        if (key.value.is_of_type(VariantType.STRING) && key.value.get_string().index_of(text) >= 0)
-            return true;
-
-        return false;
-    }
-
-    private bool get_next_iter(ref Gtk.TreeIter iter)
+    private void find_cb ()
     {
-        /* Search children next */
-        if (model.iter_has_child(iter))
-        {
-            model.iter_nth_child(out iter, iter, 0);
-            return true;
-        }
-
-        /* Move to the next branch */
-        while (!model.iter_next(ref iter))
-        {
-            /* Otherwise move to the parent and onto the next iter */
-            if (!model.iter_parent(out iter, iter))
-                return false;
-        }
-
-        return true;
+        window.find_cb ();
     }
 
-    private void about_cb()
+    private void about_cb ()
     {
         string[] authors = { "Robert Ancell", null };
         string license = _("This program is free software; you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of 
the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will 
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy 
of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA");
@@ -423,15 +141,4 @@ class ConfigurationEditor : Gtk.Application
                                "logo-icon-name", "dconf-editor",
                                null);
     }
-
-    public static int main(string[] args)
-    {
-        Intl.setlocale (LocaleCategory.ALL, "");
-        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
-        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
-        Intl.textdomain (Config.GETTEXT_PACKAGE);
-
-        var app = new ConfigurationEditor();
-        return app.run(args);
-    }
 }
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
new file mode 100644
index 0000000..a486555
--- /dev/null
+++ b/editor/dconf-window.vala
@@ -0,0 +1,340 @@
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/dconf-editor.ui")]
+class DConfWindow : ApplicationWindow
+{
+    private SettingsModel model;
+    [GtkChild]
+    private TreeView dir_tree_view;
+
+    private TreeView key_tree_view;
+    [GtkChild]
+    private ScrolledWindow key_scrolledwindow;  // TODO used only for adding key_tree_view, a pseudo-TreeView
+
+    [GtkChild]
+    private Grid key_info_grid;
+    [GtkChild]
+    private Label schema_label;
+    [GtkChild]
+    private Label summary_label;
+    [GtkChild]
+    private Label description_label;
+    [GtkChild]
+    private Label type_label;
+    [GtkChild]
+    private Label default_label;
+
+    [GtkChild]
+    private Box search_box;
+    [GtkChild]
+    private Entry search_entry;
+    [GtkChild]
+    private Label search_label;
+
+    private Key? selected_key;
+
+    private const GLib.ActionEntry[] window_actions =
+    {
+        { "set-default", set_default_cb }
+    };
+    private SimpleAction set_default_action;
+
+    public DConfWindow ()
+    {
+        add_action_entries (window_actions, this);
+        set_default_action = (SimpleAction) lookup_action ("set-default");
+        set_default_action.set_enabled (false);
+
+        /* key tree */
+        key_tree_view = new DConfKeyView ();
+        key_tree_view.show ();
+        key_tree_view.get_selection ().changed.connect (key_selected_cb);
+        key_scrolledwindow.add (key_tree_view);
+
+        /* dir tree */
+        model = new SettingsModel ();
+        dir_tree_view.set_model (model);
+
+        TreeSelection selection = dir_tree_view.get_selection ();
+        selection.changed.connect (dir_selected_cb);
+
+        TreeIter iter;
+        if (model.get_iter_first (out iter))
+            selection.select_iter (iter);
+    }
+
+    /*\
+    * * Dir TreeView
+    \*/
+
+    private void dir_selected_cb ()
+    {
+        KeyModel? key_model = null;
+
+        TreeIter iter;
+        if (dir_tree_view.get_selection ().get_selected (null, out iter))
+            key_model = model.get_directory (iter).key_model;
+
+        key_tree_view.set_model (key_model);
+
+        /* Always select something */
+        if (key_model != null && key_model.get_iter_first (out iter))
+            key_tree_view.get_selection ().select_iter (iter);
+    }
+
+    /*\
+    * * Key TreeView & informations
+    \*/
+
+    private string key_to_description (Key key)
+    {
+        switch (key.schema.type)
+        {
+        case "y":
+        case "n":
+        case "q":
+        case "i":
+        case "u":
+        case "x":
+        case "t":
+            Variant min, max;
+            if (key.schema.range != null)
+            {
+                min = key.schema.range.min;
+                max = key.schema.range.max;
+            }
+            else
+            {
+                min = key.get_min ();
+                max = key.get_max ();
+            }
+            return _("Integer [%s..%s]").printf (min.print (false), max.print (false));
+        case "d":
+            Variant min, max;
+            if (key.schema.range != null)
+            {
+                min = key.schema.range.min;
+                max = key.schema.range.max;
+            }
+            else
+            {
+                min = key.get_min ();
+                max = key.get_max ();
+            }
+            return _("Double [%s..%s]").printf (min.print (false), max.print (false));
+        case "b":
+            return _("Boolean");
+        case "s":
+            return _("String");
+        case "<enum>":
+            return _("Enumeration");
+        default:
+            return key.schema.type;
+        }
+    }
+
+    private void key_selected_cb ()
+    {
+        if (selected_key != null)
+            selected_key.value_changed.disconnect (key_changed_cb);
+
+        TreeIter iter;
+        TreeModel model;
+        if (key_tree_view.get_selection ().get_selected (out model, out iter))
+        {
+            var key_model = (KeyModel) model;
+            selected_key = key_model.get_key (iter);
+        }
+        else
+            selected_key = null;
+
+        if (selected_key != null)
+            selected_key.value_changed.connect (key_changed_cb);
+
+        key_info_grid.sensitive = selected_key != null;
+        set_default_action.set_enabled (selected_key != null && !selected_key.is_default);
+
+        string schema_name = "", summary = "", description = "", type = "", default_value = "";
+
+        if (selected_key != null)
+        {
+            if (selected_key.schema != null)
+            {
+                var gettext_domain = selected_key.schema.gettext_domain;
+                schema_name = selected_key.schema.schema.id;
+
+                if (selected_key.schema.summary != null)
+                    summary = selected_key.schema.summary;
+                if (gettext_domain != null && summary != "")
+                    summary = dgettext (gettext_domain, summary);
+
+                if (selected_key.schema.description != null)
+                    description = selected_key.schema.description;
+                if (gettext_domain != null && description != "")
+                    description = dgettext (gettext_domain, description);
+
+                type = key_to_description (selected_key);
+                default_value = selected_key.schema.default_value.print (false);
+            }
+            else
+            {
+                schema_name = _("No schema");
+            }
+        }
+
+        schema_label.set_text (schema_name);
+        summary_label.set_text (summary.strip ());
+        description_label.set_text (description.strip ());
+        type_label.set_text (type);
+        default_label.set_text (default_value);
+    }
+
+    /*\
+    * * Set_default button
+    \*/
+
+    private void key_changed_cb (Key key)   /* TODO reuse */
+    {
+        set_default_action.set_enabled (selected_key != null && !selected_key.is_default);
+    }
+
+    private void set_default_cb ()
+    {
+        if (selected_key == null)
+            return;
+        selected_key.set_to_default ();
+    }
+
+    /*\
+    * * Search box
+    \*/
+
+    public void find_cb ()
+    {
+        search_box.show ();
+        search_entry.grab_focus ();
+    }
+
+    [GtkCallback]
+    private bool on_key_press_event (Gdk.EventKey event)
+    {
+        if (event.keyval == Gdk.Key.Escape)
+        {
+            search_box.hide ();
+            return true;
+        }
+        return false;
+    }
+
+    [GtkCallback]
+    private void on_close_button_clicked ()
+    {
+        search_box.hide ();
+    }
+
+    [GtkCallback]
+    private void find_next_cb ()
+    {
+        search_label.set_text ("");
+
+        /* Get the current position in the tree */
+        TreeIter iter;
+        TreeIter key_iter = TreeIter ();
+        var have_key_iter = false;
+        if (dir_tree_view.get_selection ().get_selected (null, out iter))
+        {
+            if (key_tree_view.get_selection ().get_selected (null, out key_iter))
+            {
+                var dir = model.get_directory (iter);
+                if (dir.key_model.iter_next (ref key_iter))
+                    have_key_iter = true;
+                else
+                    get_next_iter (ref iter);
+            }
+        }
+        else if (!model.get_iter_first (out iter))
+            return;
+
+        var on_first_directory = true;
+        do
+        {
+            /* Select next directory that matches */
+            var dir = model.get_directory (iter);
+            if (!have_key_iter)
+            {
+                have_key_iter = dir.key_model.get_iter_first (out key_iter);
+                if (!on_first_directory && dir.name.index_of (search_entry.text) >= 0)
+                {
+                    dir_tree_view.expand_to_path (model.get_path (iter));
+                    dir_tree_view.get_selection ().select_iter (iter);
+                    dir_tree_view.scroll_to_cell (model.get_path (iter), null, false, 0, 0);
+                    return;
+                }
+            }
+            on_first_directory = false;
+
+            /* Select next key that matches */
+            if (have_key_iter)
+            {
+                do
+                {
+                    var key = dir.key_model.get_key (key_iter);
+                    if (key_matches (key, search_entry.text))
+                    {
+                        dir_tree_view.expand_to_path (model.get_path (iter));
+                        dir_tree_view.get_selection ().select_iter (iter);
+                        dir_tree_view.scroll_to_cell (model.get_path (iter), null, false, 0, 0);
+                        key_tree_view.get_selection ().select_iter (key_iter);
+                        key_tree_view.scroll_to_cell (dir.key_model.get_path (key_iter), null, false, 0, 0);
+                        return;
+                    }
+                } while (dir.key_model.iter_next (ref key_iter));
+            }
+            have_key_iter = false;
+        } while (get_next_iter (ref iter));
+
+        search_label.set_text(_("Not found"));
+    }
+
+    private bool key_matches (Key key, string text)
+    {
+        /* Check key name */
+        if (key.name.index_of (text) >= 0)
+            return true;
+
+        /* Check key schema (description) */
+        if (key.schema != null)
+        {
+            if (key.schema.summary != null && key.schema.summary.index_of (text) >= 0)
+                return true;
+            if (key.schema.description != null && key.schema.description.index_of (text) >= 0)
+                return true;
+        }
+
+        /* Check key value */
+        if (key.value.is_of_type (VariantType.STRING) && key.value.get_string ().index_of (text) >= 0)
+            return true;
+
+        return false;
+    }
+
+    private bool get_next_iter (ref TreeIter iter)
+    {
+        /* Search children next */
+        if (model.iter_has_child (iter))
+        {
+            model.iter_nth_child (out iter, iter, 0);
+            return true;
+        }
+
+        /* Move to the next branch */
+        while (!model.iter_next (ref iter))
+        {
+            /* Otherwise move to the parent and onto the next iter */
+            if (!model.iter_parent (out iter, iter))
+                return false;
+        }
+
+        return true;
+    }
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4fdf726..666083b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@ editor/ca.desrt.dconf-editor.desktop.in.in
 [type: gettext/glade]editor/dconf-editor-menu.ui
 [type: gettext/glade]editor/dconf-editor.ui
 editor/dconf-editor.vala
+editor/dconf-window.vala
 editor/dconf-model.vala
 editor/dconf-schema.vala
 editor/dconf-view.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 94d4e95..29eb772 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,5 +1,6 @@
 editor/ca.desrt.dconf-editor.desktop.in
 editor/dconf-editor.c
+editor/dconf-window.c
 editor/dconf-model.c
 editor/dconf-schema.c
 editor/dconf-view.c


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