[recipes] Improve keynav in the ingredient edit popover
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Improve keynav in the ingredient edit popover
- Date: Mon, 26 Dec 2016 03:07:56 +0000 (UTC)
commit 2762ea642021cb73b73a3bba124df3369e8f96b6
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Dec 25 22:05:47 2016 -0500
Improve keynav in the ingredient edit popover
The improvements are similar to the ones in the search popover:
if the focus is not already in the right place, grab it to one
of the revealed entries, and activate the button when appropriate.
src/gr-edit-page.c | 37 +++++++++++++++++++++++++++++++++++++
src/gr-edit-page.ui | 2 ++
2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index ad1e173..bd1cc5f 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -849,6 +849,42 @@ gr_edit_page_init (GrEditPage *page)
gspell_text_view_basic_setup (gspell_view);
}
+static gboolean
+popover_keypress_handler (GtkWidget *widget,
+ GdkEvent *event,
+ GrEditPage *page)
+{
+ GtkWidget *focus;
+
+ focus = gtk_window_get_focus (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page))));
+
+ if (gtk_revealer_get_child_revealed (GTK_REVEALER (page->ing_search_revealer))) {
+ if (focus == NULL || !gtk_widget_is_ancestor (focus, page->ing_search_revealer)) {
+ gtk_widget_grab_focus (page->new_ingredient_name);
+ return gtk_widget_event (page->new_ingredient_name, event);
+ }
+ }
+ else if (gtk_revealer_get_child_revealed (GTK_REVEALER (page->amount_search_revealer))) {
+ if (focus == NULL || !gtk_widget_is_ancestor (focus, page->amount_search_revealer)) {
+ gtk_widget_grab_focus (page->new_ingredient_unit);
+ return gtk_widget_event (page->new_ingredient_unit, event);
+ }
+ }
+ else if (gtk_widget_is_sensitive (page->new_ingredient_add_button)) {
+ if (event->type == GDK_KEY_PRESS) {
+ GdkEventKey *e = (GdkEventKey *) event;
+ if (e->keyval == GDK_KEY_Return ||
+ e->keyval == GDK_KEY_ISO_Enter ||
+ e->keyval == GDK_KEY_KP_Enter) {
+ gtk_widget_activate (page->new_ingredient_add_button);
+ return GDK_EVENT_STOP;
+ }
+ }
+ }
+
+ return GDK_EVENT_PROPAGATE;
+}
+
static void
gr_edit_page_class_init (GrEditPageClass *klass)
{
@@ -918,6 +954,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, unit_filter_stop);
gtk_widget_class_bind_template_callback (widget_class, unit_filter_activated);
gtk_widget_class_bind_template_callback (widget_class, amount_search_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, popover_keypress_handler);
}
GtkWidget *
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index 89b154c..a7c19d9 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -622,7 +622,9 @@
</template>
<object class="GtkPopover" id="ingredient_popover">
<property name="position">top</property>
+ <property name="modal">1</property>
<property name="constrain-to">none</property>
+ <signal name="key-press-event" handler="popover_keypress_handler" after="yes"/>
<child>
<object class="GtkBox">
<property name="visible">1</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]