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:
parent
7f9c709c85
commit
ff775213a5
@ -373,7 +373,10 @@ var Calendar = class Calendar {
|
||||
|
||||
this._selectedDate = date;
|
||||
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() {
|
||||
|
@ -25,6 +25,10 @@ function _isToday(date) {
|
||||
now.getDate() == date.getDate();
|
||||
}
|
||||
|
||||
function _gDateTimeToDate(datetime) {
|
||||
return new Date(datetime.to_unix() * 1000 + datetime.get_microsecond() / 1000);
|
||||
}
|
||||
|
||||
var TodayButton = class TodayButton {
|
||||
constructor(calendar) {
|
||||
// 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);
|
||||
|
||||
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
|
||||
// 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);
|
||||
|
||||
this._calendar = new Calendar.Calendar();
|
||||
this._calendar.connect('selected-date-changed',
|
||||
(calendar, date) => {
|
||||
layout.frozen = !_isToday(date);
|
||||
this._messageList.setDate(date);
|
||||
});
|
||||
this._calendar.connect('selected-date-changed', (_calendar, datetime) => {
|
||||
let date = _gDateTimeToDate(datetime);
|
||||
layout.frozen = !_isToday(date);
|
||||
this._messageList.setDate(date);
|
||||
});
|
||||
|
||||
this.menu.connect('open-state-changed', (menu, isOpen) => {
|
||||
// Whenever the menu is opened, select today
|
||||
|
Loading…
Reference in New Issue
Block a user