Movie list window: hide search bar by default, make it appear on text entry
authorPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 30 Oct 2009 19:19:56 +0000 (20:19 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 30 Oct 2009 19:21:58 +0000 (20:21 +0100)
The search bar will appear as soon as something is typed. A tool button is
added to hide the search bar.

src/movie-list-window.vala

index 2e2159b..0759ba7 100644 (file)
@@ -31,8 +31,12 @@ public class MovieListWindow : StackableWindow {
                search_field_item.set_expand (true);
                search_field_item.add (search_field);
 
+               var close_image = new Image.from_file("/usr/share/icons/hicolor/48x48/hildon/general_close.png");
+               var close_button = new ToolButton (close_image, "Close");
+
                search_bar = new Toolbar ();
                search_bar.insert (search_field_item, 0);
+               search_bar.insert (close_button, 1);
 
                add_toolbar (search_bar);
 
@@ -40,7 +44,31 @@ public class MovieListWindow : StackableWindow {
 
                add (vbox);
 
+               // Connect signals
+               close_button.clicked.connect (on_close_button_clicked);
+               key_press_event.connect (on_key_press_event);
+
+               search_field.set_flags (WidgetFlags.CAN_DEFAULT);
+               search_field.grab_default ();
+
                show_all ();
+               search_bar.hide ();
+       }
+
+       private void on_close_button_clicked () {
+               search_field.set_text ("");
+               search_bar.hide ();
+       }
+
+       private bool on_key_press_event (Widget widget, Gdk.EventKey event) {
+               if (event.str != "") {
+                       if (!search_bar.visible) {
+                               search_bar.show ();
+                       }
+                       search_field.grab_focus ();
+               }
+
+               return false;
        }
 }