[gimp] libgimpwidgets: handle Enter/Esc keys in GimpSpinButton
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpwidgets: handle Enter/Esc keys in GimpSpinButton
- Date: Tue, 14 Jul 2020 10:02:01 +0000 (UTC)
commit e5310230317854ecd5399f6db6de38d08dea8f3b
Author: Ell <ell_se yahoo com>
Date: Tue Jul 14 12:50:04 2020 +0300
libgimpwidgets: handle Enter/Esc keys in GimpSpinButton
In GimpSpinButton, don't propagate Enter key-press events if
updating the spin-button's value in response changes the entered
text. This prevents confirming dialogs when hitting Enter after
entering a math expression in size entries, updating their value
instead.
Likewise, don't propagate Escape key-press events if a new value
was entered, and restore the original value instead.
libgimpwidgets/gimpspinbutton.c | 52 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
---
diff --git a/libgimpwidgets/gimpspinbutton.c b/libgimpwidgets/gimpspinbutton.c
index 115d0585de..7abd79a62e 100644
--- a/libgimpwidgets/gimpspinbutton.c
+++ b/libgimpwidgets/gimpspinbutton.c
@@ -21,8 +21,11 @@
#include "config.h"
+#include <string.h>
+
#include <gegl.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include "libgimpmath/gimpmath.h"
@@ -62,6 +65,8 @@ struct _GimpSpinButtonPrivate
static gboolean gimp_spin_button_scroll (GtkWidget *widget,
GdkEventScroll *event);
+static gboolean gimp_spin_button_key_press (GtkWidget *widget,
+ GdkEventKey *event);
static gboolean gimp_spin_button_focus_in (GtkWidget *widget,
GdkEventFocus *event);
static gboolean gimp_spin_button_focus_out (GtkWidget *widget,
@@ -90,6 +95,7 @@ gimp_spin_button_class_init (GimpSpinButtonClass *klass)
GtkSpinButtonClass *spin_button_class = GTK_SPIN_BUTTON_CLASS (klass);
widget_class->scroll_event = gimp_spin_button_scroll;
+ widget_class->key_press_event = gimp_spin_button_key_press;
widget_class->focus_in_event = gimp_spin_button_focus_in;
widget_class->focus_out_event = gimp_spin_button_focus_out;
@@ -152,6 +158,52 @@ gimp_spin_button_scroll (GtkWidget *widget,
return GTK_WIDGET_CLASS (parent_class)->scroll_event (widget, event);
}
+static gboolean
+gimp_spin_button_key_press (GtkWidget *widget,
+ GdkEventKey *event)
+{
+ switch (event->keyval)
+ {
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ case GDK_KEY_ISO_Enter:
+ case GDK_KEY_Escape:
+ {
+ GtkEntry *entry = GTK_ENTRY (widget);
+ GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
+ gchar *text;
+ gboolean changed;
+
+ text = g_strdup (gtk_entry_get_text (entry));
+
+ if (event->keyval == GDK_KEY_Escape)
+ {
+ gtk_spin_button_set_value (
+ spin_button,
+ gtk_spin_button_get_value (spin_button));
+ }
+ else
+ {
+ gtk_spin_button_update (spin_button);
+ }
+
+ changed = strcmp (gtk_entry_get_text (entry), text);
+
+ g_free (text);
+
+ if (changed)
+ {
+ gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+
+ return TRUE;
+ }
+ }
+ break;
+ }
+
+ return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
+}
+
static gboolean
gimp_spin_button_focus_in (GtkWidget *widget,
GdkEventFocus *event)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]