[dconf-editor] Use HeaderBar and SearchBar.



commit 1507ca0faf9b169743552c98d034cd58c1d518db
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Sep 23 16:15:39 2015 +0200

    Use HeaderBar and SearchBar.

 editor/dconf-editor-menu.ui |    7 --
 editor/dconf-editor.ui      |  154 +++++++++++++++++++-----------------------
 editor/dconf-editor.vala    |    6 --
 editor/dconf-window.vala    |   36 ++++------
 4 files changed, 85 insertions(+), 118 deletions(-)
---
diff --git a/editor/dconf-editor-menu.ui b/editor/dconf-editor-menu.ui
index fbb919f..1cf0428 100644
--- a/editor/dconf-editor-menu.ui
+++ b/editor/dconf-editor-menu.ui
@@ -3,13 +3,6 @@
   <menu id="app-menu">
     <section>
       <item>
-        <attribute name="label" translatable="yes">_Find…</attribute>
-        <attribute name="action">app.find</attribute>
-        <attribute name="accel">&lt;Primary&gt;f</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
         <attribute name="label" translatable="yes">_About</attribute>
         <attribute name="action">app.about</attribute>
       </item>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 7d8d0d8..a7bc813 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -6,17 +6,84 @@
     <property name="title" translatable="yes">dconf Editor</property>
     <property name="height_request">525</property>
     <property name="width_request">700</property>
+    <signal name="key_press_event" handler="on_key_press_event"/>
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="show-close-button">True</property>
+        <property name="title" translatable="yes">dconf Editor</property>
+        <child>
+          <object class="GtkToggleButton" id="search_button">
+            <property name="visible">True</property>
+            <property name="valign">center</property>
+            <property name="sensitive">True</property>
+            <property name="active" bind-source="search_bar" bind-property="search-mode-enabled" 
bind-flags="bidirectional|sync-create"/>
+            <!-- <accelerator key="F" signal="toggled" modifiers="GDK_CONTROL_MASK"/> TODO -->
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">edit-find-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
     <child>
-      <object class="GtkBox">
+      <object class="GtkGrid">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <child>
+          <object class="GtkSearchBar" id="search_bar">
+            <property name="visible">True</property>
+            <property name="search-mode-enabled">False</property>
+            <property name="show-close-button">False</property>
+            <child>
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <style>
+                  <class name="linked"/>
+                </style>
+                <child>
+                  <object class="GtkSearchEntry" id="search_entry">
+                    <property name="visible">True</property>
+                    <property name="vexpand">False</property>
+                    <property name="width-request">350</property>
+                    <signal name="activate" handler="find_next_cb"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton" id="search_next_button">
+                    <property name="visible">True</property>
+                    <signal name="clicked" handler="find_next_cb"/>
+                    <property name="sensitive" bind-source="search_button" bind-property="active"/>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">True</property>
+                        <property name="icon_size">1</property>
+                        <property name="icon_name">go-down-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
           <object class="GtkPaned">
             <property name="orientation">horizontal</property>
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
             <property name="position">100</property>
+            <property name="expand">True</property>
             <child>
               <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
@@ -65,87 +132,6 @@
               </object>
             </child>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkBox" id="search_box">
-            <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">
-                <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>
-                    <property name="can_focus">False</property>
-                    <property name="icon-name">window-close</property>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="search_entry">
-                <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>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="search_next_button">
-                <property name="label" translatable="yes">Next</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <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>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="search_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
         </child>
       </object>
     </child>
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index f7dca23..1a090d1 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -32,7 +32,6 @@ class ConfigurationEditor : Gtk.Application
 
     private const GLib.ActionEntry[] action_entries =
     {
-        { "find", find_cb },
         { "about", about_cb },
         { "quit", quit }
     };
@@ -136,11 +135,6 @@ class ConfigurationEditor : Gtk.Application
     * * App-menu callbacks
     \*/
 
-    private void find_cb ()
-    {
-        window.find_cb ();
-    }
-
     private void about_cb ()
     {
         string[] authors = { "Robert Ancell", "Arnaud Bonatti", null };
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index b211ec5..3bdac97 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -25,12 +25,14 @@ class DConfWindow : ApplicationWindow
     [GtkChild] private TreeSelection dir_tree_selection;
     [GtkChild] private ListBox key_list_box;
 
-    [GtkChild] private Box search_box;
-    [GtkChild] private Entry search_entry;
-    [GtkChild] private Label search_label;
+    [GtkChild] private SearchBar search_bar;
+    [GtkChild] private SearchEntry search_entry;
+    [GtkChild] private Button search_next_button;
 
     public DConfWindow ()
     {
+        search_bar.connect_entry (search_entry);
+
         model = new SettingsModel ();
         dir_tree_view.set_model (model);
 
@@ -46,6 +48,8 @@ class DConfWindow : ApplicationWindow
     [GtkCallback]
     private void dir_selected_cb ()
     {
+        search_next_button.set_sensitive (true);        // TODO better, or maybe just hide search_bar 1/2
+
         GLib.ListStore? key_model = null;
 
         TreeIter iter;
@@ -75,6 +79,8 @@ class DConfWindow : ApplicationWindow
     [GtkCallback]
     private void row_activated_cb (ListBoxRow list_box_row)
     {
+        search_next_button.set_sensitive (true);        // TODO better, or maybe just hide search_bar 2/2
+
         ((KeyListBoxRow) list_box_row.get_child ()).show_dialog (this);
     }
 
@@ -82,34 +88,21 @@ class DConfWindow : ApplicationWindow
     * * Search box
     \*/
 
-    public void find_cb ()
-    {
-        search_box.show ();
-        search_entry.grab_focus ();
-    }
-
     [GtkCallback]
-    private bool on_key_press_event (Gdk.EventKey event)
+    private bool on_key_press_event (Widget widget, Gdk.EventKey event)     // TODO better?
     {
-        if (event.keyval == Gdk.Key.Escape)
+        if (Gdk.keyval_name (event.keyval) == "f" && (event.state & Gdk.ModifierType.CONTROL_MASK) != 0)    
// TODO better?
         {
-            search_box.hide ();
+            search_bar.set_search_mode (!search_bar.get_search_mode ());
             return true;
         }
-        return false;
-    }
+        return search_bar.handle_event (event);
 
-    [GtkCallback]
-    private void on_close_button_clicked ()
-    {
-        search_box.hide ();
     }
 
     [GtkCallback]
     private void find_next_cb ()
     {
-        search_label.label = "";
-
         TreeIter iter;
         int position = 0;
         if (dir_tree_selection.get_selected (null, out iter))
@@ -142,6 +135,7 @@ class DConfWindow : ApplicationWindow
                 {
                     select_dir (iter);
                     key_list_box.select_row (key_list_box.get_row_at_index (position));
+                    // TODO select key in ListBox
                     return;
                 }
                 position++;
@@ -151,7 +145,7 @@ class DConfWindow : ApplicationWindow
         }
         while (get_next_iter (ref iter));
 
-        search_label.label = _("Not found");
+        search_next_button.set_sensitive (false);
     }
 
     private void select_dir (TreeIter iter)


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