From fbbde136cb36f62593705b6cdb05c7136f1a242d Mon Sep 17 00:00:00 2001 From: Benjamin Kitt Date: Mon, 31 Jan 2022 18:15:03 -0600 Subject: [PATCH] #270: Add button for adding event Addresses issue #270, Add button for adding event. --- src/Widgets/calendar/CalendarView.vala | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Widgets/calendar/CalendarView.vala b/src/Widgets/calendar/CalendarView.vala index cb542539..2bbc9ff0 100644 --- a/src/Widgets/calendar/CalendarView.vala +++ b/src/Widgets/calendar/CalendarView.vala @@ -64,6 +64,9 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid { box_buttons.add (center_button); box_buttons.add (right_button); + var new_event_button = new Gtk.Button.from_icon_name ("appointment-new-symbolic"); + new_event_button.tooltip_text = _("New event"); + events_model = CalendarModel.get_default (ECal.ClientSourceType.EVENTS); tasks_model = CalendarModel.get_default (ECal.ClientSourceType.TASKS); start_month = Util.get_start_of_month (); @@ -108,7 +111,8 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid { margin_start = margin_end = 10; attach (label, 0, 0); attach (box_buttons, 1, 0); - attach (carousel, 0, 1, 2); + attach (new_event_button, 2, 0); + attach (carousel, 0, 1, 3); left_button.clicked.connect (() => { carousel.switch_child ((int) carousel.get_position () - 1, carousel.get_animation_duration ()); @@ -122,6 +126,10 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid { show_today (); }); + new_event_button.clicked.connect (() => { + open_maya_with_options (selected_date, true); + }); + carousel.page_changed.connect ((index) => { events_model.change_month (-rel_postion); tasks_model.change_month (-rel_postion); @@ -241,8 +249,11 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid { } // TODO: As far as maya supports it use the Dbus Activation feature to run the calendar-app. - public void show_date_in_maya (GLib.DateTime date) { - var command = "io.elementary.calendar --show-day %s".printf (date.format ("%F")); + private void open_maya_with_options (GLib.DateTime? day_to_show, bool add_event = false) { + day_to_show = day_to_show ?? new GLib.DateTime.now_local (); + var command = "io.elementary.calendar"; + command += add_event ? " --add-event" : ""; + command += " --show-day %s".printf (day_to_show.format ("%F")); try { var appinfo = AppInfo.create_from_commandline (command, null, AppInfoCreateFlags.NONE); @@ -259,6 +270,10 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid { } } + public void show_date_in_maya (GLib.DateTime date) { + open_maya_with_options (date); + } + public void refresh () { show_today (true); }