app: be smarter about handling the Space key in GimpPopup

Don't remove the GDK_KEY_space in GimpSearchPopup because that's
impossible and removes it from the entire GimpPopup class. Instead,
don't handle the "space -> confirm" binding manually if the focus
widget is a text widget.
This commit is contained in:
Michael Natterer 2016-07-12 20:35:41 +02:00
parent 23d5944ef8
commit bb66166e22
2 changed files with 31 additions and 19 deletions

View File

@ -222,19 +222,39 @@ static gboolean
gimp_popup_key_press (GtkWidget *widget,
GdkEventKey *kevent)
{
GtkBindingSet *binding_set;
GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (widget));
gboolean activate_binding = TRUE;
binding_set = gtk_binding_set_by_class (g_type_class_peek (GIMP_TYPE_POPUP));
/* invoke the popup's binding entries manually, because otherwise
* the focus widget (GtkTreeView e.g.) would consume it
*/
if (gtk_binding_set_activate (binding_set,
kevent->keyval,
kevent->state,
GTK_OBJECT (widget)))
if (focus &&
(GTK_IS_EDITABLE (focus) ||
GTK_IS_TEXT_VIEW (focus)) &&
(kevent->keyval == GDK_KEY_space ||
kevent->keyval == GDK_KEY_KP_Space))
{
return TRUE;
/* if a text widget has the focus, and the key was space,
* don't manually activate the binding to allow entering the
* space in the focus widget.
*/
activate_binding = FALSE;
}
if (activate_binding)
{
GtkBindingSet *binding_set;
binding_set = gtk_binding_set_by_class (g_type_class_peek (GIMP_TYPE_POPUP));
/* invoke the popup's binding entries manually, because
* otherwise the focus widget (GtkTreeView e.g.) would consume
* it
*/
if (gtk_binding_set_activate (binding_set,
kevent->keyval,
kevent->state,
GTK_OBJECT (widget)))
{
return TRUE;
}
}
return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, kevent);

View File

@ -124,7 +124,6 @@ gimp_search_popup_class_init (GimpSearchPopupClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpPopupClass *popup_class = GIMP_POPUP_CLASS (klass);
GtkBindingSet *binding_set;
object_class->constructed = gimp_search_popup_constructed;
object_class->set_property = gimp_search_popup_set_property;
@ -164,13 +163,6 @@ gimp_search_popup_class_init (GimpSearchPopupClass *klass)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
/* We don't want space to activate actions in the search widget, since
* we allow search with spaces in it. */
binding_set = gtk_binding_set_by_class (g_type_class_peek (GIMP_TYPE_POPUP));
gtk_binding_entry_remove (binding_set, GDK_KEY_space, 0);
gtk_binding_entry_remove (binding_set, GDK_KEY_KP_Space, 0);
g_type_class_add_private (klass, sizeof (GimpSearchPopupPrivate));
}