cleanup: Port non-GObject classes to JS6 classes

ES6 finally adds standard class syntax to the language, so we can
replace our custom Lang.Class framework with the new syntax. Any
classes that inherit from GObject will need special treatment,
so limit the port to regular javascript classes for now.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:
Florian Müllner
2017-10-31 02:19:44 +01:00
committed by Georges Basile Stavracas Neto
parent 99ce3deeb0
commit bacfdbbb03
102 changed files with 3454 additions and 4183 deletions

View File

@ -31,10 +31,8 @@ function _isToday(date) {
now.getDate() == date.getDate();
}
var TodayButton = new Lang.Class({
Name: 'TodayButton',
_init(calendar) {
var TodayButton = class TodayButton {
constructor(calendar) {
// Having the ability to go to the current date if the user is already
// on the current date can be confusing. So don't make the button reactive
// until the selected date changes.
@ -63,7 +61,7 @@ var TodayButton = new Lang.Class({
// current date.
this.actor.reactive = !_isToday(date)
});
},
}
setDate(date) {
this._dayLabel.set_text(date.toLocaleFormat('%A'));
@ -83,12 +81,10 @@ var TodayButton = new Lang.Class({
dateFormat = Shell.util_translate_time_string (N_("%A %B %e %Y"));
this.actor.accessible_name = date.toLocaleFormat(dateFormat);
}
});
};
var WorldClocksSection = new Lang.Class({
Name: 'WorldClocksSection',
_init() {
var WorldClocksSection = class WorldClocksSection {
constructor() {
this._clock = new GnomeDesktop.WallClock();
this._clockNotifyId = 0;
@ -118,11 +114,11 @@ var WorldClocksSection = new Lang.Class({
this._clockAppMon.watchSetting('world-clocks',
this._clocksChanged.bind(this));
this._sync();
},
}
_sync() {
this.actor.visible = this._clockAppMon.available;
},
}
_clocksChanged(settings) {
this._grid.destroy_all_children();
@ -187,7 +183,7 @@ var WorldClocksSection = new Lang.Class({
this._clock.disconnect(this._clockNotifyId);
this._clockNotifyId = 0;
}
},
}
_updateLabels() {
for (let i = 0; i < this._locations.length; i++) {
@ -197,12 +193,10 @@ var WorldClocksSection = new Lang.Class({
l.actor.text = Util.formatTime(now, { timeOnly: true });
}
}
});
};
var WeatherSection = new Lang.Class({
Name: 'WeatherSection',
_init() {
var WeatherSection = class WeatherSection {
constructor() {
this._weatherClient = new Weather.WeatherClient();
this.actor = new St.Button({ style_class: 'weather-button',
@ -236,7 +230,7 @@ var WeatherSection = new Lang.Class({
this._weatherClient.connect('changed', this._sync.bind(this));
this._sync();
},
}
_getSummary(info, capitalize=false) {
let options = capitalize ? GWeather.FormatOptions.SENTENCE_CAPITALIZATION
@ -250,7 +244,7 @@ var WeatherSection = new Lang.Class({
let [, sky] = info.get_value_sky();
return GWeather.Sky.to_string_full(sky, options);
},
}
_sameSummary(info1, info2) {
let [ok1, phenom1, qualifier1] = info1.get_value_conditions();
@ -261,7 +255,7 @@ var WeatherSection = new Lang.Class({
let [, sky1] = info1.get_value_sky();
let [, sky2] = info2.get_value_sky();
return sky1 == sky2;
},
}
_getSummaryText() {
let info = this._weatherClient.info;
@ -309,7 +303,7 @@ var WeatherSection = new Lang.Class({
return this._getSummary(info, capitalize);
});
return String.prototype.format.apply(fmt, summaries);
},
}
_getLabelText() {
if (!this._weatherClient.hasLocation)
@ -328,7 +322,7 @@ var WeatherSection = new Lang.Class({
return _("Go online for weather information");
return _("Weather information is currently unavailable");
},
}
_sync() {
this.actor.visible = this._weatherClient.available;
@ -338,12 +332,10 @@ var WeatherSection = new Lang.Class({
this._conditionsLabel.text = this._getLabelText();
}
});
};
var MessagesIndicator = new Lang.Class({
Name: 'MessagesIndicator',
_init() {
var MessagesIndicator = class MessagesIndicator {
constructor() {
this.actor = new St.Icon({ icon_name: 'message-indicator-symbolic',
icon_size: 16,
visible: false, y_expand: true,
@ -357,18 +349,18 @@ var MessagesIndicator = new Lang.Class({
let sources = Main.messageTray.getSources();
sources.forEach(source => { this._onSourceAdded(null, source); });
},
}
_onSourceAdded(tray, source) {
source.connect('count-updated', this._updateCount.bind(this));
this._sources.push(source);
this._updateCount();
},
}
_onSourceRemoved(tray, source) {
this._sources.splice(this._sources.indexOf(source), 1);
this._updateCount();
},
}
_updateCount() {
let count = 0;
@ -377,7 +369,7 @@ var MessagesIndicator = new Lang.Class({
this.actor.visible = (count > 0);
}
});
};
var IndicatorPad = new Lang.Class({
Name: 'IndicatorPad',
@ -592,5 +584,5 @@ var DateMenuButton = new Lang.Class({
// but the corresponding app (clocks, weather); however we can consider
// that display-specific settings, so re-use "allowSettings" here ...
this._displaysSection.visible = Main.sessionMode.allowSettings;
}
},
});