[gtk+/gtk-2-24] filechooserentry: Catch tab key earlier
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] filechooserentry: Catch tab key earlier
- Date: Thu, 10 Mar 2016 21:32:00 +0000 (UTC)
commit b65de86fe8ef1fa1a7423894f499f8205b73d046
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
Conflicts:
gtk/gtkfilechooserentry.c
gtk/gtkfilechooserentry.c | 50 ++++++++++++++++++--------------------------
1 files changed, 21 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index 90fa62f..134fb03 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -77,8 +77,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);
@@ -157,7 +157,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;
}
@@ -196,6 +195,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",
@@ -381,46 +384,35 @@ 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);
-
- control_pressed = FALSE;
+ return FALSE;
- if (gtk_get_current_event_state (&state))
- {
- if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
- control_pressed = TRUE;
- }
+ if (event->keyval != GDK_KEY_Tab)
+ 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_Tab && !control_pressed)
- {
- gint start, end;
+ if (gtk_get_current_event_state (&state) &&
+ (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+ return FALSE;
- 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]