Commit b9fad15e authored by Benjamin Otte's avatar Benjamin Otte

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
parent 640754e9
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment