cleanup: Port GObject classes to JS6 classes

GJS added API for defining GObject classes with ES6 class syntax
last cycle, use it to port the remaining Lang.Class classes to
the new syntax.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:
Florian Müllner
2017-10-31 02:23:39 +01:00
committed by Georges Basile Stavracas Neto
parent bacfdbbb03
commit e68dfed1f7
43 changed files with 1036 additions and 1235 deletions

View File

@ -5,14 +5,11 @@ const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Pango = imports.gi.Pango;
const St = imports.gi.St;
const Lang = imports.lang;
var Dialog = new Lang.Class({
Name: 'Dialog',
Extends: St.Widget,
var Dialog = GObject.registerClass(
class Dialog extends St.Widget {
_init(parentActor, styleClass) {
this.parent({ layout_manager: new Clutter.BinLayout() });
super._init({ layout_manager: new Clutter.BinLayout() });
this.connect('destroy', this._onDestroy.bind(this));
this._initialKeyFocus = null;
@ -28,7 +25,7 @@ var Dialog = new Lang.Class({
this._parentActor = parentActor;
this._eventId = this._parentActor.connect('event', this._modalEventHandler.bind(this));
this._parentActor.add_child(this);
},
}
_createDialog() {
this._dialog = new St.BoxLayout({ style_class: 'modal-dialog',
@ -55,13 +52,13 @@ var Dialog = new Lang.Class({
this._dialog.add(this.buttonLayout,
{ x_align: St.Align.MIDDLE,
y_align: St.Align.START });
},
}
_onDestroy() {
if (this._eventId != 0)
this._parentActor.disconnect(this._eventId);
this._eventId = 0;
},
}
_modalEventHandler(actor, event) {
if (event.type() == Clutter.EventType.KEY_PRESS) {
@ -87,7 +84,7 @@ var Dialog = new Lang.Class({
}
return Clutter.EVENT_PROPAGATE;
},
}
_setInitialKeyFocus(actor) {
if (this._initialKeyFocus)
@ -99,15 +96,15 @@ var Dialog = new Lang.Class({
this._initialKeyFocus = null;
this._initialKeyFocusDestroyId = 0;
});
},
}
get initialKeyFocus() {
return this._initialKeyFocus || this;
},
}
addContent(actor) {
this.contentLayout.add (actor, { expand: true });
},
}
addButton(buttonInfo) {
let { label, action, key } = buttonInfo;
@ -144,17 +141,15 @@ var Dialog = new Lang.Class({
this.buttonLayout.add_actor(button);
return button;
},
}
clearButtons() {
this.buttonLayout.destroy_all_children();
this._buttonKeys = {};
},
}
});
var MessageDialogContent = new Lang.Class({
Name: 'MessageDialogContent',
Extends: St.BoxLayout,
var MessageDialogContent = GObject.registerClass({
Properties: {
'icon': GObject.ParamSpec.object('icon', 'icon', 'icon',
GObject.ParamFlags.READWRITE |
@ -172,8 +167,8 @@ var MessageDialogContent = new Lang.Class({
GObject.ParamFlags.READWRITE |
GObject.ParamFlags.CONSTRUCT,
null)
},
}
}, class MessageDialogContent extends St.BoxLayout {
_init(params) {
this._icon = new St.Icon({ y_align: Clutter.ActorAlign.START });
this._title = new St.Label({ style_class: 'headline' });
@ -192,7 +187,7 @@ var MessageDialogContent = new Lang.Class({
if (!params.hasOwnProperty('style_class'))
params.style_class = 'message-dialog-main-layout';
this.parent(params);
super._init(params);
this.messageBox = new St.BoxLayout({ style_class: 'message-dialog-content',
x_expand: true,
@ -204,45 +199,45 @@ var MessageDialogContent = new Lang.Class({
this.add_actor(this._icon);
this.add_actor(this.messageBox);
},
}
get icon() {
return this._icon.gicon;
},
}
get title() {
return this._title.text;
},
}
get subtitle() {
return this._subtitle.text;
},
}
get body() {
return this._body.text;
},
}
set icon(icon) {
Object.assign(this._icon, { gicon: icon, visible: icon != null });
this.notify('icon');
},
}
set title(title) {
this._setLabel(this._title, 'title', title);
},
}
set subtitle(subtitle) {
this._setLabel(this._subtitle, 'subtitle', subtitle);
},
}
set body(body) {
this._setLabel(this._body, 'body', body);
},
}
_setLabel(label, prop, value) {
Object.assign(label, { text: value || '', visible: value != null });
this.notify(prop);
},
}
insertBeforeBody(actor) {
this.messageBox.insert_child_below(actor, this._body);