calendar: Use GDateTime for selected-date-changed signal

Since GObject derived classes can't use JS objects as signal parameters, let's
go native and use GLib.DateTime instead.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
Marco Trevisan (Treviño) 2019-09-02 21:18:54 +02:00 committed by Florian Müllner
parent 7f9c709c85
commit ff775213a5
2 changed files with 15 additions and 8 deletions

View File

@ -373,7 +373,10 @@ var Calendar = class Calendar {
this._selectedDate = date; this._selectedDate = date;
this._update(); this._update();
this.emit('selected-date-changed', new Date(this._selectedDate));
let datetime = GLib.DateTime.new_from_unix_local(
this._selectedDate.getTime() / 1000);
this.emit('selected-date-changed', datetime);
} }
updateTimeZone() { updateTimeZone() {

View File

@ -25,6 +25,10 @@ function _isToday(date) {
now.getDate() == date.getDate(); now.getDate() == date.getDate();
} }
function _gDateTimeToDate(datetime) {
return new Date(datetime.to_unix() * 1000 + datetime.get_microsecond() / 1000);
}
var TodayButton = class TodayButton { var TodayButton = class TodayButton {
constructor(calendar) { constructor(calendar) {
// Having the ability to go to the current date if the user is already // Having the ability to go to the current date if the user is already
@ -52,10 +56,10 @@ var TodayButton = class TodayButton {
hbox.add_actor(this._dateLabel); hbox.add_actor(this._dateLabel);
this._calendar = calendar; this._calendar = calendar;
this._calendar.connect('selected-date-changed', (calendar, date) => { this._calendar.connect('selected-date-changed', (_calendar, datetime) => {
// Make the button reactive only if the selected date is not the // Make the button reactive only if the selected date is not the
// current date. // current date.
this.actor.reactive = !_isToday(date); this.actor.reactive = !_isToday(_gDateTimeToDate(datetime));
}); });
} }
@ -529,11 +533,11 @@ class DateMenuButton extends PanelMenu.Button {
bin.add_actor(hbox); bin.add_actor(hbox);
this._calendar = new Calendar.Calendar(); this._calendar = new Calendar.Calendar();
this._calendar.connect('selected-date-changed', this._calendar.connect('selected-date-changed', (_calendar, datetime) => {
(calendar, date) => { let date = _gDateTimeToDate(datetime);
layout.frozen = !_isToday(date); layout.frozen = !_isToday(date);
this._messageList.setDate(date); this._messageList.setDate(date);
}); });
this.menu.connect('open-state-changed', (menu, isOpen) => { this.menu.connect('open-state-changed', (menu, isOpen) => {
// Whenever the menu is opened, select today // Whenever the menu is opened, select today