[gnome-calendar/wip/keyboard-navigation] window: add accelerators to change date
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/keyboard-navigation] window: add accelerators to change date
- Date: Wed, 13 May 2015 14:40:57 +0000 (UTC)
commit 052e64eb533d5d3fac16eab23465e107b57a5951
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed May 13 11:39:14 2015 -0300
window: add accelerators to change date
<Alt>Left for previous date
<Alt>Down or <Ctrl>t for today
<Alt>Right for next date
More expected shortcuts are being discussed and
registered at https://etherpad.gnome.org/p/calendar-keynav.
data/ui/window.ui | 6 +++---
src/gcal-window.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index dbcccf2..cc36d3a 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -206,7 +206,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="date_updated" swapped="no"/>
+ <property name="action_name">win.previous</property>
<child>
<object class="GtkImage" id="go_back_image">
<property name="visible">True</property>
@@ -227,7 +227,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="date_updated" object="GcalWindow" swapped="no"/>
+ <property name="action_name">win.today</property>
</object>
<packing>
<property name="expand">False</property>
@@ -240,7 +240,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="date_updated" swapped="no"/>
+ <property name="action_name">win.next</property>
<child>
<object class="GtkImage" id="go_next_image">
<property name="visible">True</property>
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 2467ce0..6f720bc 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -130,6 +130,10 @@ enum
#define FAST_REFRESH_TIMEOUT 900000 /* ms */
#define SLOW_REFRESH_TIMEOUT 3600000 /* ms */
+static void on_date_action_activated (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data);
+
static gboolean key_pressed (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
@@ -256,6 +260,33 @@ static gboolean gcal_window_state_event (GtkWidget *w
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 }
+};
+
+static void
+on_date_action_activated (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GcalWindowPrivate *priv;
+ const gchar *action_name;
+
+ g_return_if_fail (GCAL_IS_WINDOW (user_data));
+
+ priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
+ action_name = g_action_get_name (G_ACTION (action));
+
+ if (g_strcmp0 (action_name, "next") == 0)
+ date_updated (GTK_BUTTON (priv->forward_button), user_data);
+ else if (g_strcmp0 (action_name, "previous") == 0)
+ date_updated (GTK_BUTTON (priv->back_button), user_data);
+ else if (g_strcmp0 (action_name, "today") == 0)
+ date_updated (GTK_BUTTON (priv->today_button), user_data);
+}
+
static gboolean
key_pressed (GtkWidget *widget,
GdkEvent *event,
@@ -1374,6 +1405,12 @@ gcal_window_constructed (GObject *object)
// Prevents nameless events' creation
g_signal_handlers_block_by_func (priv->new_event_what_entry, create_event, object);
+ // Setup actions
+ g_action_map_add_action_entries (G_ACTION_MAP (object),
+ actions,
+ G_N_ELEMENTS (actions),
+ object);
+
/* header_bar: menu */
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder,
@@ -1578,12 +1615,20 @@ gcal_window_new_with_view_and_date (GcalApplication *app,
{
GcalWindow *win;
GcalManager *manager;
+ const gchar *next_accel[] = {"<Alt>Right", NULL};
+ const gchar *previous_accel[] = {"<Alt>Left", NULL};
+ const gchar *today_accel[] = {"<Alt>Down", "<Ctrl>t", NULL};
manager = gcal_application_get_manager (GCAL_APPLICATION (app));
win = g_object_new (GCAL_TYPE_WINDOW, "application", GTK_APPLICATION (app), "manager", manager,
"active-date", date,
NULL);
+ /* setup accels */
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.next", next_accel);
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.previous", previous_accel);
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.today", today_accel);
+
/* loading size */
load_geometry (win);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]