aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2011-07-18 12:20:05 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-07-18 12:20:05 +0800
commit3b225294da4fb6f57d147f83c7ed78c8a44f0aec (patch)
tree30894b562f5fff9ac1ea44732af96759fe2d15be /libempathy-gtk
parentb7c238e691a8f2a171b9efa2e5f38af0f0c2a56f (diff)
downloadgsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar.gz
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar.bz2
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar.lz
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar.xz
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.tar.zst
gsoc2013-empathy-3b225294da4fb6f57d147f83c7ed78c8a44f0aec.zip
Populate spelling suggestions when menu key is pressed
Track what kind of event generated the populate-popup event and then use the cursor position or mouse position as appropriate. Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=654669
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-chat.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 239be0b1f..5f441af19 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -149,6 +149,11 @@ struct _EmpathyChatPriv {
* messages in tab will be properly shown */
gboolean retrieving_backlogs;
gboolean sms_channel;
+
+ /* we need to know whether populate-popup happened in response to
+ * the keyboard or the mouse. We can't ask GTK for the most recent
+ * event, because it will be a notify event. Instead we track it here */
+ GdkEventType most_recent_event_type;
};
typedef struct {
@@ -1702,6 +1707,8 @@ chat_input_key_press_event_cb (GtkWidget *widget,
priv = GET_PRIV (chat);
+ priv->most_recent_event_type = event->type;
+
/* Catch ctrl+up/down so we can traverse messages we sent */
if ((event->state & GDK_CONTROL_MASK) &&
(event->keyval == GDK_KEY_Up ||
@@ -2157,11 +2164,24 @@ chat_text_send_cb (GtkMenuItem *menuitem,
chat_input_text_view_send (chat);
}
+static gboolean
+chat_input_button_press_event_cb (GtkTextView *view,
+ GdkEventButton *event,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ priv->most_recent_event_type = event->type;
+
+ return FALSE;
+}
+
static void
chat_input_populate_popup_cb (GtkTextView *view,
GtkMenu *menu,
EmpathyChat *chat)
{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
GtkTextBuffer *buffer;
GtkTextTagTable *table;
GtkTextTag *tag;
@@ -2212,12 +2232,29 @@ chat_input_populate_popup_cb (GtkTextView *view,
/* Add the spell check menu item. */
table = gtk_text_buffer_get_tag_table (buffer);
tag = gtk_text_tag_table_lookup (table, "misspelled");
- gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
- GTK_TEXT_WINDOW_WIDGET,
- x, y,
- &x, &y);
- gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
+
+ switch (priv->most_recent_event_type) {
+ case GDK_BUTTON_PRESS:
+ /* get the location from the pointer */
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
+ GTK_TEXT_WINDOW_WIDGET,
+ x, y,
+ &x, &y);
+ gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view),
+ &iter, x, y);
+ break;
+
+ case GDK_KEY_PRESS:
+ /* get the location from the cursor */
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter,
+ gtk_text_buffer_get_insert (buffer));
+ break;
+
+ default:
+ break;
+ }
+
start = end = iter;
if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
@@ -2891,6 +2928,9 @@ chat_create_ui (EmpathyChat *chat)
g_signal_connect (chat->input_text_view, "realize",
G_CALLBACK (chat_input_realize_cb),
chat);
+ g_signal_connect (chat->input_text_view, "button-press-event",
+ G_CALLBACK (chat_input_button_press_event_cb),
+ chat);
g_signal_connect (chat->input_text_view, "populate-popup",
G_CALLBACK (chat_input_populate_popup_cb),
chat);