[gnome-calendar] window: Add new event button



commit 79eea9376b733b53885e3599ea2a91352a493fc7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu May 9 17:39:35 2019 -0300

    window: Add new event button
    
    As per the latest mockups [1]
    
    [1] https://teams.pages.gitlab.gnome.org/Design/web-experiments/calendar/headerbar

 data/ui/window.ui     | 17 ++++++++++++++---
 src/gui/gcal-window.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 622e9ed8..066f6f1a 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -162,6 +162,20 @@
         <property name="visible">True</property>
         <property name="show_close_button">True</property>
         <property name="title" translatable="yes">Calendar</property>
+        <child>
+          <object class="GtkButton" id="new_event_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="action-name">win.new-event</property>
+            <property name="tooltip_text" translatable="yes" context="tooltip">Add a new event</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">list-add-symbolic</property>
+              </object>
+            </child>
+          </object>
+        </child>
         <child>
           <object class="GtkButton" id="today_button">
             <property name="label" translatable="yes">Today</property>
@@ -172,9 +186,6 @@
             <accelerator key="t" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
             <accelerator key="Home" signal="clicked"/>
           </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
         </child>
         <child>
           <object class="GtkBox" id="button_box">
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index 2438e025..d3431c96 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -360,6 +360,38 @@ on_window_next_date_activated_cb (GSimpleAction *action,
   update_active_date (self, next_date);
 }
 
+static void
+on_window_new_event_cb (GSimpleAction *action,
+                        GVariant      *param,
+                        gpointer       user_data)
+{
+  g_autoptr (ECalComponent) comp = NULL;
+  g_autoptr (GDateTime) start = NULL;
+  g_autoptr (GDateTime) end = NULL;
+  GcalCalendar *default_calendar;
+  GcalManager *manager;
+  GcalWindow *self;
+  GcalEvent *event;
+
+  self = GCAL_WINDOW (user_data);
+  start = g_date_time_new (gcal_context_get_timezone (self->context),
+                           g_date_time_get_year (self->active_date),
+                           g_date_time_get_month (self->active_date),
+                           g_date_time_get_day_of_month (self->active_date),
+                           0, 0, 0);
+  end = g_date_time_add_days (start, 1);
+
+  manager = gcal_context_get_manager (self->context);
+  comp = build_component_from_details ("", start, end);
+  default_calendar = gcal_manager_get_default_calendar (manager);
+  event = gcal_event_new (default_calendar, comp, NULL);
+
+  gcal_edit_dialog_set_event_is_new (GCAL_EDIT_DIALOG (self->edit_dialog), TRUE);
+  gcal_edit_dialog_set_event (GCAL_EDIT_DIALOG (self->edit_dialog), event);
+
+  gtk_widget_show (self->edit_dialog);
+}
+
 static void
 on_window_previous_date_activated_cb (GSimpleAction *action,
                                       GVariant      *param,
@@ -1053,6 +1085,7 @@ gcal_window_init (GcalWindow *self)
   static const GActionEntry actions[] = {
     {"change-view", on_view_action_activated, "i" },
     {"next-date", on_window_next_date_activated_cb },
+    {"new-event", on_window_new_event_cb },
     {"previous-date", on_window_previous_date_activated_cb },
     {"show-calendars", on_show_calendars_action_activated },
     {"today", on_window_today_activated_cb }


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