diff --git a/src/Indicator.vala b/src/Indicator.vala index a8851bdc..a5e86af5 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -52,28 +52,6 @@ public class DateTime.Indicator : Wingpanel.Indicator { panel_label = new Widgets.PanelLabel () { tooltip_markup = Granite.TOOLTIP_SECONDARY_TEXT_MARKUP.printf (_("Middle-click to open Calendar")) }; - - panel_label.button_press_event.connect ((e) => { - if (e.button == Gdk.BUTTON_MIDDLE) { - var command = "io.elementary.calendar --show-day %s".printf (new GLib.DateTime.now_local ().format ("%F")); - try { - var appinfo = AppInfo.create_from_commandline (command, null, AppInfoCreateFlags.NONE); - appinfo.launch_uris (null, null); - } catch (GLib.Error e) { - var dialog = new Granite.MessageDialog.with_image_from_icon_name ( - _("Unable To Launch Calendar"), - _("The program \"io.elementary.calendar\" may not be installed"), - "dialog-error" - ); - dialog.show_error_details (e.message); - dialog.run (); - dialog.destroy (); - } - return Gdk.EVENT_STOP; - } - - return Gdk.EVENT_PROPAGATE; - }); } return panel_label; @@ -107,9 +85,9 @@ public class DateTime.Indicator : Wingpanel.Indicator { component_listbox.set_sort_func (sort_function); var scrolled_window = new Gtk.ScrolledWindow (null, null) { - hscrollbar_policy = Gtk.PolicyType.NEVER + hscrollbar_policy = Gtk.PolicyType.NEVER, + child = component_listbox }; - scrolled_window.add (component_listbox); var settings_button = new Gtk.ModelButton () { text = _("Date & Time Settings…") @@ -157,8 +135,8 @@ public class DateTime.Indicator : Wingpanel.Indicator { "dialog-error" ); dialog.show_error_details (e.message); - dialog.run (); - dialog.destroy (); + dialog.response.connect ((_dialog, response) => _dialog.destroy ()); + dialog.present (); } close (); } diff --git a/src/Services/TimeManager.vala b/src/Services/TimeManager.vala index b68f158a..7c23d7eb 100644 --- a/src/Services/TimeManager.vala +++ b/src/Services/TimeManager.vala @@ -32,7 +32,7 @@ interface FDO.Accounts : Object { public abstract string find_user_by_name (string username) throws GLib.Error; } -public class DateTime.Services.TimeManager : Gtk.Calendar { +public class DateTime.Services.TimeManager : Object { private static TimeManager? instance = null; public signal void minute_changed (); diff --git a/src/Widgets/PanelLabel.vala b/src/Widgets/PanelLabel.vala index 973a0847..51086621 100644 --- a/src/Widgets/PanelLabel.vala +++ b/src/Widgets/PanelLabel.vala @@ -26,6 +26,8 @@ public class DateTime.Widgets.PanelLabel : Gtk.Box { public bool clock_show_seconds { get; set; } public bool clock_show_weekday { get; set; } + private Gtk.GestureMultiPress gesture_click; + construct { date_label = new Gtk.Label (null) { margin_end = 12 @@ -57,6 +59,11 @@ public class DateTime.Widgets.PanelLabel : Gtk.Box { time_manager = Services.TimeManager.get_default (); time_manager.minute_changed.connect (update_labels); time_manager.notify["is-12h"].connect (update_labels); + + gesture_click = new Gtk.GestureMultiPress (this) { + button = Gdk.BUTTON_MIDDLE + }; + gesture_click.pressed.connect (on_pressed); } private void update_labels () { @@ -72,4 +79,21 @@ public class DateTime.Widgets.PanelLabel : Gtk.Box { string time_format = Granite.DateTime.get_default_time_format (time_manager.is_12h, clock_show_seconds); time_label.label = GLib.Markup.printf_escaped ("%s", time_manager.format (time_format)); } + + private void on_pressed () { + var command = "io.elementary.calendar --show-day %s".printf (new GLib.DateTime.now_local ().format ("%F")); + try { + var appinfo = AppInfo.create_from_commandline (command, null, AppInfoCreateFlags.NONE); + appinfo.launch_uris (null, null); + } catch (GLib.Error e) { + var dialog = new Granite.MessageDialog.with_image_from_icon_name ( + _("Unable To Launch Calendar"), + _("The program \"io.elementary.calendar\" may not be installed"), + "dialog-error" + ); + dialog.show_error_details (e.message); + dialog.response.connect ((_dialog, response) => _dialog.destroy ()); + dialog.present (); + } + } } diff --git a/src/Widgets/calendar/Grid.vala b/src/Widgets/calendar/Grid.vala index e4403068..f5e5440e 100644 --- a/src/Widgets/calendar/Grid.vala +++ b/src/Widgets/calendar/Grid.vala @@ -62,9 +62,9 @@ namespace DateTime.Widgets { }; var week_sep_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT, + child = week_sep }; - week_sep_revealer.add (week_sep); hexpand = true; attach (week_sep_revealer, 1, 1, 1, 6); @@ -255,9 +255,9 @@ namespace DateTime.Widgets { week_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); week_labels[c] = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT, + child = week_label }; - week_labels[c].add (week_label); week_labels[c].show_all (); DateTime.Indicator.settings.bind ("show-weeks", week_labels[c], "reveal-child", GLib.SettingsBindFlags.DEFAULT); diff --git a/src/Widgets/calendar/GridDay.vala b/src/Widgets/calendar/GridDay.vala index a3e144f0..c4b1b19b 100644 --- a/src/Widgets/calendar/GridDay.vala +++ b/src/Widgets/calendar/GridDay.vala @@ -36,6 +36,9 @@ public class DateTime.Widgets.GridDay : Gtk.EventBox { private Gtk.Label label; private bool valid_grab = false; + private Gtk.GestureMultiPress click_gesture; + private Gtk.EventControllerKey key_controller; + public GridDay (GLib.DateTime date) { Object (date: date); } @@ -76,8 +79,12 @@ public class DateTime.Widgets.GridDay : Gtk.EventBox { show_all (); // Signals and handlers - button_press_event.connect (on_button_press); - key_press_event.connect (on_key_press); + click_gesture = new Gtk.GestureMultiPress (this); + click_gesture.pressed.connect (on_button_press); + + key_controller = new Gtk.EventControllerKey (this); + key_controller.key_pressed.connect (on_key_press); + bind_property ("date", label, "label", GLib.BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => { unowned var new_date = (GLib.DateTime) from_value.get_boxed (); to_value.take_string (new_date.get_day_of_month ().to_string ()); @@ -150,17 +157,16 @@ public class DateTime.Widgets.GridDay : Gtk.EventBox { event_box.sensitive = sens; } - private bool on_button_press (Gdk.EventButton event) { - if (event.type == Gdk.EventType.2BUTTON_PRESS && event.button == Gdk.BUTTON_PRIMARY) { + private void on_button_press (int n_press) { + if (n_press == 2) { on_event_add (date); } valid_grab = true; grab_focus (); - return false; } - private bool on_key_press (Gdk.EventKey event) { - if (event.keyval == Gdk.keyval_from_name ("Return") ) { + private bool on_key_press (uint keyval) { + if (keyval == Gdk.keyval_from_name ("Return") ) { on_event_add (date); return true; }