[empathy] Capture the escape key on the chat view and search bar, to make it hide the search bar



commit 7c0d4aca42f309b89684636ad84fd4969eac6943
Author: Thomas Meire <blackskad gmail com>
Date:   Thu Jan 21 01:20:08 2010 +0100

    Capture the escape key on the chat view and search bar, to make it hide the search bar

 libempathy-gtk/empathy-chat.c       |    3 +++
 libempathy-gtk/empathy-search-bar.c |   34 ++++++++++++++++++++++++++++------
 libempathy-gtk/empathy-search-bar.h |    1 +
 3 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 65676b5..2222580 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -1371,6 +1371,9 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
 		gtk_adjustment_set_value (adj, val);
 		return TRUE;
 	}
+	if (event->keyval == GDK_Escape) {
+		empathy_search_bar_hide (EMPATHY_SEARCH_BAR (priv->search_bar));
+	}
 	if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
 	    event->keyval == GDK_Tab) {
 		GtkTextBuffer *buffer;
diff --git a/libempathy-gtk/empathy-search-bar.c b/libempathy-gtk/empathy-search-bar.c
index 2526510..cc2b977 100644
--- a/libempathy-gtk/empathy-search-bar.c
+++ b/libempathy-gtk/empathy-search-bar.c
@@ -20,6 +20,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 
 #include <libempathy/empathy-utils.h>
 
@@ -155,15 +156,13 @@ empathy_search_bar_show (EmpathySearchBar *self)
   gtk_widget_show (GTK_WIDGET (self));
 }
 
-
-static void
-empathy_search_bar_close_cb (GtkButton *button,
-    gpointer user_data)
+void
+empathy_search_bar_hide (EmpathySearchBar *self)
 {
-  EmpathySearchBarPriv *priv = GET_PRIV (user_data);
+  EmpathySearchBarPriv *priv = GET_PRIV (self);
 
   empathy_chat_view_highlight (priv->chat_view, "", FALSE);
-  gtk_widget_hide (GTK_WIDGET (user_data));
+  gtk_widget_hide (GTK_WIDGET (self));
 
   /* give the focus back to the focus-chain with the chat view */
   gtk_widget_grab_focus (GTK_WIDGET (priv->chat_view));
@@ -213,12 +212,32 @@ empathy_search_bar_search (EmpathySearchBar *self,
 }
 
 static void
+empathy_search_bar_close_cb (GtkButton *button,
+    gpointer user_data)
+{
+  empathy_search_bar_hide (EMPATHY_SEARCH_BAR (user_data));
+}
+
+static void
 empathy_search_bar_entry_changed (GtkEditable *entry,
     gpointer user_data)
 {
   empathy_search_bar_search (EMPATHY_SEARCH_BAR (user_data), FALSE, TRUE);
 }
 
+static gboolean
+empathy_search_bar_key_pressed (GtkWidget   *widget,
+    GdkEventKey *event,
+    gpointer user_data)
+{
+  if (event->keyval == GDK_Escape)
+    {
+      empathy_search_bar_hide (EMPATHY_SEARCH_BAR (widget));
+      return TRUE;
+    }
+  return FALSE;
+}
+
 static void
 empathy_search_bar_next_cb (GtkButton *button,
     gpointer user_data)
@@ -274,6 +293,9 @@ empathy_search_bar_init (EmpathySearchBar * self)
       "search_match_case", "toggled", empathy_search_bar_match_case_toggled,
       NULL);
 
+  g_signal_connect (G_OBJECT (self), "key-press-event",
+      G_CALLBACK (empathy_search_bar_key_pressed), NULL);
+
   gtk_container_add (GTK_CONTAINER (self), internal);
   gtk_widget_show_all (internal);
   gtk_widget_hide (priv->search_not_found);
diff --git a/libempathy-gtk/empathy-search-bar.h b/libempathy-gtk/empathy-search-bar.h
index d4cd042..c17778b 100644
--- a/libempathy-gtk/empathy-search-bar.h
+++ b/libempathy-gtk/empathy-search-bar.h
@@ -58,6 +58,7 @@ struct _EmpathySearchBarClass
 GType       empathy_search_bar_get_type (void) G_GNUC_CONST;
 GtkWidget * empathy_search_bar_new      (EmpathyChatView  *view);
 void        empathy_search_bar_show     (EmpathySearchBar *searchbar);
+void        empathy_search_bar_hide     (EmpathySearchBar *searchbar);
 
 G_END_DECLS
 



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