[gnome-boxes] Move Searchbar UI setup to a .ui file



commit 17efdbbe1aa5c724223db62f8d47467636881d58
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Jan 30 21:30:48 2014 +0000

    Move Searchbar UI setup to a .ui file
    
    Not much gain at all in this case but lets do this for consistency.

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/searchbar.ui           |   18 ++++++++++++++++++
 src/searchbar.vala             |   34 ++++++++++++++--------------------
 3 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 8ba393a..a59d5db 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -8,6 +8,7 @@
     <file>icons/boxes-gray.png</file>
     <file preprocess="xml-stripblanks">ui/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/searchbar.ui</file>
     <file preprocess="xml-stripblanks">ui/selectionbar.ui</file>
     <file preprocess="xml-stripblanks">ui/sidebar.ui</file>
     <file preprocess="xml-stripblanks">ui/topbar.ui</file>
diff --git a/data/ui/searchbar.ui b/data/ui/searchbar.ui
new file mode 100644
index 0000000..03ae745
--- /dev/null
+++ b/data/ui/searchbar.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesSearchbar" parent="GtkSearchBar">
+    <property name="visible">True</property>
+    <signal name="notify::search-mode-enabled" handler="on_search_mode_notify"/>
+
+    <child>
+      <object class="GtkSearchEntry" id="entry">
+        <property name="visible">True</property>
+        <property name="width-chars">40</property>
+        <property name="hexpand">True</property>
+        <signal name="search-changed" handler="on_search_changed"/>
+        <signal name="activate" handler="on_search_activated"/>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/searchbar.vala b/src/searchbar.vala
index 7aa7dbc..0cd92ee 100644
--- a/src/searchbar.vala
+++ b/src/searchbar.vala
@@ -1,5 +1,6 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/searchbar.ui")]
 private class Boxes.Searchbar: Gtk.SearchBar {
     public bool enable_key_handler {
         set {
@@ -9,30 +10,32 @@ private class Boxes.Searchbar: Gtk.SearchBar {
                 GLib.SignalHandler.block (App.app.window, key_handler_id);
         }
     }
+    [GtkChild]
     private Gtk.SearchEntry entry;
 
     private ulong key_handler_id;
 
     public Searchbar () {
-        setup_searchbar ();
-
         key_handler_id = App.app.window.key_press_event.connect (on_app_key_pressed);
-        entry.search_changed.connect (on_search_changed);
-        entry.activate.connect ( () => {
-            App.app.view.activate ();
-        });
-
-        notify["search-mode-enabled"].connect (() => {
-            if (!search_mode_enabled)
-                text = "";
-        });
     }
 
+    [GtkCallback]
     private void on_search_changed () {
         App.app.filter.text = text;
         App.app.view.refilter ();
     }
 
+    [GtkCallback]
+    private void on_search_activated () {
+        App.app.view.activate ();
+    }
+
+    [GtkCallback]
+    private void on_search_mode_notify () {
+        if (!search_mode_enabled)
+            text = "";
+    }
+
     public string text {
         get { return entry.text; }
         set { entry.set_text (value); }
@@ -44,13 +47,4 @@ private class Boxes.Searchbar: Gtk.SearchBar {
 
         return handle_event ((Gdk.Event *) (&event));
     }
-
-    private void setup_searchbar () {
-        entry = new Gtk.SearchEntry ();
-        entry.width_chars = 40;
-        entry.hexpand = true;
-        add (entry);
-
-        show_all ();
-    }
 }


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