[gtk+] filechooserentry: Catch tab key earlier
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] filechooserentry: Catch tab key earlier
- Date: Fri, 16 Dec 2011 19:15:50 +0000 (UTC)
commit b9fad15ee635f576b7450cd3fec6a84b2f3e010e
Author: Benjamin Otte <otte redhat com>
Date: Fri Dec 16 19:52:46 2011 +0100
filechooserentry: Catch tab key earlier
Instead of in the key_press handler, use a signal handler. The signal
handler runs before the default handler, and before other signal
handlers. In particular it runs before the signal handler installed via
gtk_entry_set_completion() which pops down the entry completion, and we
don't want that to happen.
The code does not change the code of the handler in any significant way,
it just refacotrs it to not call the parent anymore.
https://bugzilla.gnome.org/show_bug.cgi?id=663573
gtk/gtkfilechooserentry.c | 48 +++++++++++++++++++-------------------------
1 files changed, 21 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index 50d3462..fb6c2b0 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -74,8 +74,8 @@ enum
static void gtk_file_chooser_entry_finalize (GObject *object);
static void gtk_file_chooser_entry_dispose (GObject *object);
static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
-static gboolean gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
- GdkEventKey *event);
+static gboolean gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
+ GdkEventKey *event);
static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
@@ -154,7 +154,6 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
gobject_class->dispatch_properties_changed = gtk_file_chooser_entry_dispatch_properties_changed;
widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
- widget_class->key_press_event = gtk_file_chooser_entry_key_press_event;
widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
}
@@ -193,6 +192,10 @@ _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
g_object_unref (comp);
+ /* NB: This needs to happen after the completion is set, so this handler
+ * runs before the handler installed by entrycompletion */
+ g_signal_connect (chooser_entry, "key-press-event",
+ G_CALLBACK (gtk_file_chooser_entry_tab_handler), NULL);
#ifdef G_OS_WIN32
g_signal_connect (chooser_entry, "insert-text",
@@ -378,46 +381,37 @@ start_explicit_completion (GtkFileChooserEntry *chooser_entry)
}
static gboolean
-gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
+gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
+ GdkEventKey *event)
{
GtkFileChooserEntry *chooser_entry;
GtkEditable *editable;
GdkModifierType state;
- gboolean control_pressed;
+ gint start, end;
chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
editable = GTK_EDITABLE (widget);
if (!chooser_entry->eat_tabs)
- return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
+ return FALSE;
- control_pressed = FALSE;
+ if (event->keyval != GDK_KEY_Tab)
+ return FALSE;
- if (gtk_get_current_event_state (&state))
- {
- if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
- control_pressed = TRUE;
- }
+ if (gtk_get_current_event_state (&state) &&
+ (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+ return FALSE;
/* This is a bit evil -- it makes Tab never leave the entry. It basically
* makes it 'safe' for people to hit. */
- if (event->keyval == GDK_KEY_Tab && !control_pressed)
- {
- gint start, end;
-
- gtk_editable_get_selection_bounds (editable, &start, &end);
+ gtk_editable_get_selection_bounds (editable, &start, &end);
- if (start != end)
- gtk_editable_set_position (editable, MAX (start, end));
- else
- start_explicit_completion (chooser_entry);
-
- return TRUE;
- }
-
- return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
+ if (start != end)
+ gtk_editable_set_position (editable, MAX (start, end));
+ else
+ start_explicit_completion (chooser_entry);
+ return TRUE;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]