[gnome-logs/wip/batching] Add keyboard navigation for the back button



commit d9ac0250eb5fe5648fb28e95276e0e086b653845
Author: David King <davidk gnome org>
Date:   Wed Feb 26 12:34:56 2014 +0000

    Add keyboard navigation for the back button
    
    Thanks to Joanmarie Diggs for the suggestion.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724980

 src/gl-eventtoolbar.c |   32 ++++++++++++++++++++++++++++++++
 src/gl-eventtoolbar.h |    2 ++
 src/gl-window.c       |   42 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 72 insertions(+), 4 deletions(-)
---
diff --git a/src/gl-eventtoolbar.c b/src/gl-eventtoolbar.c
index eb2515f..9146d98 100644
--- a/src/gl-eventtoolbar.c
+++ b/src/gl-eventtoolbar.c
@@ -194,6 +194,38 @@ gl_event_toolbar_init (GlEventToolbar *toolbar)
     }
 }
 
+gboolean
+gl_event_toolbar_handle_back_button_event (GlEventToolbar *toolbar,
+                                           GdkEventKey *event)
+{
+    GlEventToolbarPrivate *priv;
+    GdkModifierType state;
+    GdkKeymap *keymap;
+    gboolean is_rtl;
+
+    g_return_val_if_fail (toolbar != NULL && event != NULL,
+                          GDK_EVENT_PROPAGATE);
+
+    priv = gl_event_toolbar_get_instance_private (toolbar);
+
+    state = event->state;
+    keymap = gdk_keymap_get_default ();
+    gdk_keymap_add_virtual_modifiers (keymap, &state);
+    state = state & gtk_accelerator_get_default_mod_mask ();
+    is_rtl = gtk_widget_get_direction (priv->back_button) == GTK_TEXT_DIR_RTL;
+
+    if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left)
+        || (is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right)
+        || event->keyval == GDK_KEY_Back)
+    {
+        return GDK_EVENT_STOP;
+    }
+    else
+    {
+        return GDK_EVENT_PROPAGATE;
+    }
+}
+
 void
 gl_event_toolbar_set_mode (GlEventToolbar *toolbar, GlEventToolbarMode mode)
 {
diff --git a/src/gl-eventtoolbar.h b/src/gl-eventtoolbar.h
index 31f4bb6..9accb93 100644
--- a/src/gl-eventtoolbar.h
+++ b/src/gl-eventtoolbar.h
@@ -53,6 +53,8 @@ typedef enum
 
 GType gl_event_toolbar_get_type (void);
 GtkWidget * gl_event_toolbar_new (void);
+gboolean gl_event_toolbar_handle_back_button_event (GlEventToolbar *toolbar,
+                                                    GdkEventKey *event);
 void gl_event_toolbar_set_mode (GlEventToolbar *toolbar,
                                 GlEventToolbarMode mode);
 
diff --git a/src/gl-window.c b/src/gl-window.c
index e9e4351..82ee364 100644
--- a/src/gl-window.c
+++ b/src/gl-window.c
@@ -198,22 +198,56 @@ on_gl_window_key_press_event (GlWindow *window,
                               gpointer user_data)
 {
     GlWindowPrivate *priv;
-    GAction *search;
+    GAction *action;
+    GVariant *variant;
+    const gchar *mode;
+    GEnumClass *eclass;
+    GEnumValue *evalue;
 
     priv = gl_window_get_instance_private (window);
-    search = g_action_map_lookup_action (G_ACTION_MAP (window), "search");
+    action = g_action_map_lookup_action (G_ACTION_MAP (window), "search");
 
-    if (g_action_get_enabled (search))
+    if (g_action_get_enabled (action))
     {
         if (gtk_search_bar_handle_event (GTK_SEARCH_BAR (priv->event_search),
                                          event) == GDK_EVENT_STOP)
         {
-            g_action_change_state (search, g_variant_new_boolean (TRUE));
+            g_action_change_state (action, g_variant_new_boolean (TRUE));
 
             return GDK_EVENT_STOP;
         }
     }
 
+    action = g_action_map_lookup_action (G_ACTION_MAP (window), "view-mode");
+    variant = g_action_get_state (action);
+    mode = g_variant_get_string (variant, NULL);
+    eclass = g_type_class_ref (GL_TYPE_EVENT_VIEW_MODE);
+    evalue = g_enum_get_value_by_nick (eclass, mode);
+
+    g_variant_unref (variant);
+
+    switch (evalue->value)
+    {
+        case GL_EVENT_VIEW_MODE_LIST:
+            break; /* Ignored, as there is no back button. */
+        case GL_EVENT_VIEW_MODE_DETAIL:
+            if (gl_event_toolbar_handle_back_button_event (GL_EVENT_TOOLBAR (priv->event_toolbar),
+                                                           (GdkEventKey*)event)
+                == GDK_EVENT_STOP)
+            {
+                GlEventView *events;
+
+                events = GL_EVENT_VIEW (priv->events);
+                gl_event_view_set_mode (events, GL_EVENT_VIEW_MODE_LIST);
+                g_type_class_unref (eclass);
+
+                return GDK_EVENT_STOP;
+            }
+            break;
+    }
+
+    g_type_class_unref (eclass);
+
     return GDK_EVENT_PROPAGATE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]