[gnome-calendar/wip/keyboard-navigation] window: add view switching shortcuts



commit 6a017cca8b1fcb76e9c5e6561406f6da611f70ca
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed May 13 20:13:18 2015 -0300

    window: add view switching shortcuts
    
    <Ctrl>PgUp to go to the previous view
    <Ctrl>PgDn to go to the next view
    <Ctrl>2 to go to month view
    <Ctrl>3 to go to year view

 src/gcal-window.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/gcal-window.c b/src/gcal-window.c
index f86d09d..8b3b682 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -140,6 +140,10 @@ static void           on_date_action_activated           (GSimpleAction       *a
                                                           GVariant            *param,
                                                           gpointer             user_data);
 
+static void           on_view_action_activated           (GSimpleAction       *action,
+                                                          GVariant            *param,
+                                                          gpointer             user_data);
+
 static gboolean       key_pressed                        (GtkWidget           *widget,
                                                           GdkEvent            *event,
                                                           gpointer             user_data);
@@ -269,7 +273,8 @@ G_DEFINE_TYPE_WITH_PRIVATE (GcalWindow, gcal_window, GTK_TYPE_APPLICATION_WINDOW
 static const GActionEntry actions[] = {
   {"next",     on_date_action_activated },
   {"previous", on_date_action_activated },
-  {"today",    on_date_action_activated }
+  {"today",    on_date_action_activated },
+  {"change-view", on_view_action_activated, "i" },
 };
 
 static void
@@ -293,6 +298,31 @@ on_date_action_activated (GSimpleAction *action,
     date_updated (GTK_BUTTON (priv->today_button), user_data);
 }
 
+static void
+on_view_action_activated (GSimpleAction *action,
+                          GVariant      *param,
+                          gpointer       user_data)
+{
+  GcalWindowPrivate *priv;
+  guint view;
+
+  g_return_if_fail (GCAL_IS_WINDOW (user_data));
+
+  priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
+  view = g_variant_get_int32 (param);
+
+  // -1 means next view
+  if (view == -1)
+    view = ++(priv->active_view);
+  else if (view == -2)
+    view = --(priv->active_view);
+
+  priv->active_view = CLAMP (view, GCAL_WINDOW_VIEW_MONTH, GCAL_WINDOW_VIEW_YEAR);
+  gtk_stack_set_visible_child (GTK_STACK (priv->views_stack), priv->views[priv->active_view]);
+
+  g_object_notify (G_OBJECT (user_data), "active-view");
+}
+
 static gboolean
 key_pressed (GtkWidget *widget,
              GdkEvent  *event,
@@ -1636,6 +1666,11 @@ gcal_window_new_with_view_and_date (GcalApplication   *app,
   gcal_window_add_accelerator (app, "win.today",    "<Ctrl>Down");
   gcal_window_add_accelerator (app, "win.today",    "<Ctrl>t");
 
+  gcal_window_add_accelerator (app, "win.change-view(-1)", "<Ctrl>Page_Down");
+  gcal_window_add_accelerator (app, "win.change-view(-2)", "<Ctrl>Page_Up");
+  gcal_window_add_accelerator (app, "win.change-view(2)",  "<Ctrl>2");
+  gcal_window_add_accelerator (app, "win.change-view(3)",  "<Ctrl>3");
+
   /* loading size */
   load_geometry (win);
 


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