[gnome-video-arcade] Add a "clear search" button to the search entry.



commit 892d6373bb24fb295dc1164dbbc4da2c9bdfbf82
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Mar 6 14:23:33 2010 -0500

    Add a "clear search" button to the search entry.

 data/gnome-video-arcade.builder                |    5 ++
 docs/reference/gnome-video-arcade-sections.txt |    4 ++
 docs/reference/tmpl/gva-main.sgml              |   25 +++++++++
 src/gva-main.c                                 |   64 +++++++++++++++++++++++-
 src/gva-main.h                                 |    6 ++
 5 files changed, 102 insertions(+), 2 deletions(-)
---
diff --git a/data/gnome-video-arcade.builder b/data/gnome-video-arcade.builder
index 6948655..f22f87b 100644
--- a/data/gnome-video-arcade.builder
+++ b/data/gnome-video-arcade.builder
@@ -159,6 +159,11 @@
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="secondary_icon_stock">gtk-clear</property>
+                        <property name="secondary_icon_activatable">True</property>
+                        <property name="secondary_icon_tooltip_text">Clear the search</property>
+                        <signal name="icon_release" handler="gva_main_search_entry_icon_release_cb"/>
+                        <signal name="changed" handler="gva_main_search_entry_changed_cb"/>
                         <signal name="remove_widget" handler="gtk_widget_hide" object="main-search-hbox"/>
                         <signal name="notify" handler="gva_main_search_entry_notify_cb"/>
                         <signal name="activate" handler="gva_main_search_entry_activate_cb"/>
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index 31b63ad..d1fad94 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -195,12 +195,15 @@ gva_main_statusbar_get_context_id
 gva_main_statusbar_push
 gva_main_statusbar_pop
 gva_main_statusbar_remove
+gva_main_clear_search
 gva_main_execute_search
 gva_main_get_last_search_text
 gva_main_set_last_search_text
 gva_main_get_last_selected_match
 gva_main_set_last_selected_match
 gva_main_search_entry_activate_cb
+gva_main_search_entry_changed_cb
+gva_main_search_entry_icon_release_cb
 gva_main_search_entry_notify_cb
 gva_main_search_query_tooltip_cb
 gva_main_window_destroy_cb
@@ -482,6 +485,7 @@ GVA_WIDGET_PROPERTIES_IMPERFECT_SOUND_LABEL
 GVA_WIDGET_PROPERTIES_MUSIC_AUTO_PLAY
 GVA_WIDGET_PROPERTIES_MUSIC_BUTTON
 GVA_WIDGET_PROPERTIES_MUSIC_STATUS
+GVA_WIDGET_PROPERTIES_MUSIC_TABLE
 GVA_WIDGET_PROPERTIES_NOTEBOOK
 GVA_WIDGET_PROPERTIES_ORIGINAL_LINKS
 GVA_WIDGET_PROPERTIES_ORIGINAL_VBOX
diff --git a/docs/reference/tmpl/gva-main.sgml b/docs/reference/tmpl/gva-main.sgml
index 5520bf3..e727a48 100644
--- a/docs/reference/tmpl/gva-main.sgml
+++ b/docs/reference/tmpl/gva-main.sgml
@@ -134,6 +134,13 @@
 @message_id: 
 
 
+<!-- ##### FUNCTION gva_main_clear_search ##### -->
+<para>
+
+</para>
+
+
+
 <!-- ##### FUNCTION gva_main_execute_search ##### -->
 <para>
 
@@ -184,6 +191,24 @@
 @entry: 
 
 
+<!-- ##### FUNCTION gva_main_search_entry_changed_cb ##### -->
+<para>
+
+</para>
+
+ entry: 
+
+
+<!-- ##### FUNCTION gva_main_search_entry_icon_release_cb ##### -->
+<para>
+
+</para>
+
+ entry: 
+ position: 
+ event: 
+
+
 <!-- ##### FUNCTION gva_main_search_entry_notify_cb ##### -->
 <para>
 
diff --git a/src/gva-main.c b/src/gva-main.c
index 2f681ce..2d33eef 100644
--- a/src/gva-main.c
+++ b/src/gva-main.c
@@ -107,6 +107,7 @@ main_entry_completion_match_selected_cb (GtkEntryCompletion *completion,
 
         gva_main_set_last_selected_match (column_name, search_text);
         gva_main_execute_search ();
+        gtk_widget_grab_focus (GVA_WIDGET_MAIN_TREE_VIEW);
 
         g_free (column_name);
         g_free (search_text);
@@ -653,6 +654,25 @@ gva_main_statusbar_remove (guint context_id,
 }
 
 /**
+ * gva_main_clear_search:
+ *
+ * Clears the search entry and, if the Search Results view is active,
+ * any results from the previous search.
+ **/
+void
+gva_main_clear_search (void)
+{
+        GtkWidget *widget;
+
+        widget = GVA_WIDGET_MAIN_SEARCH_ENTRY;
+        gtk_entry_set_text (GTK_ENTRY (widget), "");
+        gva_main_set_last_selected_match (NULL, NULL);
+
+        if (gva_tree_view_get_selected_view () == 2)
+                gva_main_execute_search ();
+}
+
+/**
  * gva_main_execute_search:
  *
  * Executes a game database search and configures the main window to
@@ -711,8 +731,6 @@ gva_main_execute_search (void)
                         gtk_tree_path_free (path);
                 }
         }
-
-        gtk_widget_grab_focus (GTK_WIDGET (view));
 }
 
 /**
@@ -873,6 +891,48 @@ gva_main_search_entry_activate_cb (GtkEntry *entry)
 {
         gva_main_set_last_selected_match (NULL, NULL);
         gva_main_execute_search ();
+        gtk_widget_grab_focus (GVA_WIDGET_MAIN_TREE_VIEW);
+}
+
+/**
+ * gva_main_search_entry_changed_cb:
+ * @entry: the search entry
+ *
+ * Handler for #GtkEditable::changed signals to the search entry.
+ *
+ * Updates the sensitivity of the clear search icon.
+ **/
+void
+gva_main_search_entry_changed_cb (GtkEntry *entry)
+{
+        GtkEntryIconPosition position;
+        gboolean sensitive;
+        const gchar *text;
+
+        text = gtk_entry_get_text (entry);
+        position = GTK_ENTRY_ICON_SECONDARY;
+        sensitive = (text != NULL) && (*text != '\0');
+
+        gtk_entry_set_icon_sensitive (entry, position, sensitive);
+}
+
+/**
+ * gva_main_search_entry_icon_release_cb:
+ * @entry: the search entry
+ * @position: the position of the clicked icon
+ * @event: the button release event
+ *
+ * Handler for #GtkEntry::icon-release signals to the search entry.
+ *
+ * If @position is %GTK_ENTRY_ICON_SECONDARY, clears the search entry.
+ **/
+void
+gva_main_search_entry_icon_release_cb (GtkEntry *entry,
+                                       GtkEntryIconPosition position,
+                                       GdkEvent *event)
+{
+        if (position == GTK_ENTRY_ICON_SECONDARY)
+                gva_main_clear_search ();
 }
 
 /**
diff --git a/src/gva-main.h b/src/gva-main.h
index 729b5f1..4e95cc7 100644
--- a/src/gva-main.h
+++ b/src/gva-main.h
@@ -53,6 +53,7 @@ guint         gva_main_statusbar_push            (guint context_id,
 void          gva_main_statusbar_pop             (guint context_id);
 void          gva_main_statusbar_remove          (guint context_id,
                                                   guint message_id);
+void          gva_main_clear_search              (void);
 void          gva_main_execute_search            (void);
 gchar *       gva_main_get_last_search_text      (void);
 void          gva_main_set_last_search_text      (const gchar *text);
@@ -64,6 +65,11 @@ void          gva_main_set_last_selected_match   (const gchar *column_name,
 /* Signal Handlers */
 
 void          gva_main_search_entry_activate_cb  (GtkEntry *entry);
+void          gva_main_search_entry_changed_cb   (GtkEntry *entry);
+void          gva_main_search_entry_icon_release_cb
+                                                 (GtkEntry *entry,
+                                                  GtkEntryIconPosition position,
+                                                  GdkEvent *event);
 void          gva_main_search_entry_notify_cb    (GtkEntry *entry,
                                                   GParamSpec *pspec);
 gboolean      gva_main_search_query_tooltip_cb   (GtkWidget *widget,



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