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

@ -2,8 +2,8 @@
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Signals = imports.signals;
const St = imports.gi.St;
@ -13,14 +13,12 @@ const Main = imports.ui.main;
const Params = imports.misc.params;
const PopupMenu = imports.ui.popupMenu;
var ButtonBox = new Lang.Class({
Name: 'ButtonBox',
Extends: St.Widget,
var ButtonBox = GObject.registerClass(
class ButtonBox extends St.Widget {
_init(params) {
params = Params.parse(params, { style_class: 'panel-button' }, true);
this.parent(params);
super._init(params);
this.actor = this;
this._delegate = this;
@ -33,14 +31,14 @@ var ButtonBox = new Lang.Class({
this.connect('destroy', this._onDestroy.bind(this));
this._minHPadding = this._natHPadding = 0.0;
},
}
_onStyleChanged(actor) {
let themeNode = actor.get_theme_node();
this._minHPadding = themeNode.get_length('-minimum-hpadding');
this._natHPadding = themeNode.get_length('-natural-hpadding');
},
}
vfunc_get_preferred_width(forHeight) {
let child = this.get_first_child();
@ -55,7 +53,7 @@ var ButtonBox = new Lang.Class({
naturalSize += 2 * this._natHPadding;
return [minimumSize, naturalSize];
},
}
vfunc_get_preferred_height(forWidth) {
let child = this.get_first_child();
@ -64,7 +62,7 @@ var ButtonBox = new Lang.Class({
return child.get_preferred_height(-1);
return [0, 0];
},
}
vfunc_allocate(box, flags) {
this.set_allocation(box, flags);
@ -91,21 +89,19 @@ var ButtonBox = new Lang.Class({
childBox.y2 = availHeight;
child.allocate(childBox, flags);
},
}
_onDestroy() {
this.container.child = null;
this.container.destroy();
},
}
});
var Button = new Lang.Class({
Name: 'PanelMenuButton',
Extends: ButtonBox,
var Button = GObject.registerClass({
Signals: {'menu-set': {} },
}, class PanelMenuButton extends ButtonBox {
_init(menuAlignment, nameText, dontCreateMenu) {
this.parent({ reactive: true,
super._init({ reactive: true,
can_focus: true,
track_hover: true,
accessible_name: nameText ? nameText : "",
@ -118,13 +114,13 @@ var Button = new Lang.Class({
this.menu = new PopupMenu.PopupDummyMenu(this.actor);
else
this.setMenu(new PopupMenu.PopupMenu(this.actor, menuAlignment, St.Side.TOP, 0));
},
}
setSensitive(sensitive) {
this.reactive = sensitive;
this.can_focus = sensitive;
this.track_hover = sensitive;
},
}
setMenu(menu) {
if (this.menu)
@ -140,7 +136,7 @@ var Button = new Lang.Class({
this.menu.actor.hide();
}
this.emit('menu-set');
},
}
_onEvent(actor, event) {
if (this.menu &&
@ -149,7 +145,7 @@ var Button = new Lang.Class({
this.menu.toggle();
return Clutter.EVENT_PROPAGATE;
},
}
_onVisibilityChanged() {
if (!this.menu)
@ -157,7 +153,7 @@ var Button = new Lang.Class({
if (!this.actor.visible)
this.menu.close();
},
}
_onMenuKeyPress(actor, event) {
if (global.focus_manager.navigate_from_event(event))
@ -173,7 +169,7 @@ var Button = new Lang.Class({
}
}
return Clutter.EVENT_PROPAGATE;
},
}
_onOpenStateChanged(menu, open) {
if (open)
@ -193,10 +189,10 @@ var Button = new Lang.Class({
// factor when computing max-height
let maxHeight = Math.round((workArea.height - verticalMargins) / scaleFactor);
this.menu.actor.style = ('max-height: %spx;').format(maxHeight);
},
}
_onDestroy() {
this.parent();
super._onDestroy();
if (this.menu)
this.menu.destroy();