[gnome-calendar/wip/sadiq: 3/3] window: Simplify navigation code



commit f1a8aaed5fc171aba65d44ab0dcc1b51af4154e7
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Wed Dec 6 21:36:56 2017 +0530

    window: Simplify navigation code
    
    Using <accelerator> in GtkBuilder can simplify lots of C code.

 data/ui/window.ui | 12 +++++++++---
 src/gcal-window.c | 40 +++-------------------------------------
 2 files changed, 12 insertions(+), 40 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 6c06078e..0acb8c0b 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -188,7 +188,9 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
-            <property name="action_name">win.today</property>
+            <accelerator key="t" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
+            <accelerator key="Home" signal="clicked"/>
+            <signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
           </object>
           <packing>
             <property name="position">1</property>
@@ -202,7 +204,9 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="action_name">win.previous</property>
+                <accelerator key="Left" modifiers="GDK_MOD1_MASK" signal="clicked"/>
+                <accelerator key="Page_Up" signal="clicked"/>
+                <signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
                 <child>
                   <object class="GtkImage" id="go_back_image">
                     <property name="visible">True</property>
@@ -216,7 +220,9 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="action_name">win.next</property>
+                <accelerator key="Right" modifiers="GDK_MOD1_MASK" signal="clicked"/>
+                <accelerator key="Page_Down" signal="clicked"/>
+                <signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
                 <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 d0c627ea..1e7d1b73 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -197,10 +197,6 @@ static void           on_show_calendars_action_activated (GSimpleAction       *a
                                                           GVariant            *param,
                                                           gpointer             user_data);
 
-static void           on_date_action_activated           (GSimpleAction       *action,
-                                                          GVariant            *param,
-                                                          gpointer             user_data);
-
 static void           on_view_action_activated           (GSimpleAction       *action,
                                                           GVariant            *param,
                                                           gpointer             user_data);
@@ -212,9 +208,6 @@ static void           on_toggle_search_bar_activated     (GSimpleAction       *a
 G_DEFINE_TYPE (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 },
   {"change-view", on_view_action_activated, "i" },
   {"show-calendars", on_show_calendars_action_activated },
   {"toggle-search-bar", on_toggle_search_bar_activated }
@@ -375,11 +368,9 @@ update_active_date (GcalWindow   *window,
 }
 
 static void
-date_updated (GtkButton  *button,
-              gpointer    user_data)
+date_updated (GcalWindow *window,
+              GtkButton  *button)
 {
-  GcalWindow *window = GCAL_WINDOW (user_data);
-
   icaltimetype *new_date;
   gboolean move_back, move_today;
   gint factor;
@@ -426,7 +417,7 @@ date_updated (GtkButton  *button,
       *new_date = icaltime_normalize (*new_date);
     }
 
-  update_active_date (user_data, new_date);
+  update_active_date (window, new_date);
 
   GCAL_EXIT;
 }
@@ -447,27 +438,6 @@ on_show_calendars_action_activated (GSimpleAction *action,
 }
 
 static void
-on_date_action_activated (GSimpleAction *action,
-                          GVariant      *param,
-                          gpointer       user_data)
-{
-  GcalWindow *window;
-  const gchar *action_name;
-
-  g_return_if_fail (GCAL_IS_WINDOW (user_data));
-
-  window = GCAL_WINDOW (user_data);
-  action_name = g_action_get_name (G_ACTION (action));
-
-  if (g_strcmp0 (action_name, "next") == 0)
-    date_updated (GTK_BUTTON (window->forward_button), user_data);
-  else if (g_strcmp0 (action_name, "previous") == 0)
-    date_updated (GTK_BUTTON (window->back_button), user_data);
-  else if (g_strcmp0 (action_name, "today") == 0)
-    date_updated (GTK_BUTTON (window->today_button), user_data);
-}
-
-static void
 on_view_action_activated (GSimpleAction *action,
                           GVariant      *param,
                           gpointer       user_data)
@@ -1588,10 +1558,6 @@ gcal_window_init (GcalWindow *self)
   /* setup accels */
   app = g_application_get_default ();
 
-  gcal_window_add_accelerator (app, "win.next",     "<Alt>Right", "Page_Down");
-  gcal_window_add_accelerator (app, "win.previous", "<Alt>Left", "Page_Up");
-  gcal_window_add_accelerator (app, "win.today",    "<Alt>Down", "<Ctrl>t", "Home");
-
   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(1)",    "<Ctrl>1")


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