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:

committed by
Georges Basile Stavracas Neto

parent
bacfdbbb03
commit
e68dfed1f7
@ -3,7 +3,7 @@
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const Lang = imports.lang;
|
||||
const GObject = imports.gi.GObject;
|
||||
const Mainloop = imports.mainloop;
|
||||
const St = imports.gi.St;
|
||||
|
||||
@ -34,12 +34,10 @@ const KEY_TEXT_SCALING_FACTOR = 'text-scaling-factor';
|
||||
|
||||
const HIGH_CONTRAST_THEME = 'HighContrast';
|
||||
|
||||
var ATIndicator = new Lang.Class({
|
||||
Name: 'ATIndicator',
|
||||
Extends: PanelMenu.Button,
|
||||
|
||||
var ATIndicator = GObject.registerClass(
|
||||
class ATIndicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
this.parent(0.0, _("Accessibility"));
|
||||
super._init(0.0, _("Accessibility"));
|
||||
|
||||
this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
|
||||
this._hbox.add_child(new St.Icon({ style_class: 'system-status-icon',
|
||||
@ -85,7 +83,7 @@ var ATIndicator = new Lang.Class({
|
||||
this.menu.addMenuItem(mouseKeys);
|
||||
|
||||
this._syncMenuVisibility();
|
||||
},
|
||||
}
|
||||
|
||||
_syncMenuVisibility() {
|
||||
this._syncMenuVisibilityIdle = 0;
|
||||
@ -96,7 +94,7 @@ var ATIndicator = new Lang.Class({
|
||||
this.actor.visible = alwaysShow || items.some(f => !!f.state);
|
||||
|
||||
return GLib.SOURCE_REMOVE;
|
||||
},
|
||||
}
|
||||
|
||||
_queueSyncMenuVisibility() {
|
||||
if (this._syncMenuVisibilityIdle)
|
||||
@ -104,7 +102,7 @@ var ATIndicator = new Lang.Class({
|
||||
|
||||
this._syncMenuVisibilityIdle = Mainloop.idle_add(this._syncMenuVisibility.bind(this));
|
||||
GLib.Source.set_name_by_id(this._syncMenuVisibilityIdle, '[gnome-shell] this._syncMenuVisibility');
|
||||
},
|
||||
}
|
||||
|
||||
_buildItemExtended(string, initial_value, writable, on_set) {
|
||||
let widget = new PopupMenu.PopupSwitchMenuItem(string, initial_value);
|
||||
@ -115,7 +113,7 @@ var ATIndicator = new Lang.Class({
|
||||
on_set(item.state);
|
||||
});
|
||||
return widget;
|
||||
},
|
||||
}
|
||||
|
||||
_buildItem(string, schema, key) {
|
||||
let settings = new Gio.Settings({ schema_id: schema });
|
||||
@ -130,7 +128,7 @@ var ATIndicator = new Lang.Class({
|
||||
settings.is_writable(key),
|
||||
enabled => settings.set_boolean(key, enabled));
|
||||
return widget;
|
||||
},
|
||||
}
|
||||
|
||||
_buildHCItem() {
|
||||
let interfaceSettings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
|
||||
@ -183,7 +181,7 @@ var ATIndicator = new Lang.Class({
|
||||
}
|
||||
});
|
||||
return highContrast;
|
||||
},
|
||||
}
|
||||
|
||||
_buildFontItem() {
|
||||
let settings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
|
||||
|
@ -3,8 +3,8 @@
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const GObject = imports.gi.GObject;
|
||||
const IBus = imports.gi.IBus;
|
||||
const Lang = imports.lang;
|
||||
const Meta = imports.gi.Meta;
|
||||
const Shell = imports.gi.Shell;
|
||||
const Signals = imports.signals;
|
||||
@ -73,18 +73,16 @@ var InputSource = class {
|
||||
};
|
||||
Signals.addSignalMethods(InputSource.prototype);
|
||||
|
||||
var InputSourcePopup = new Lang.Class({
|
||||
Name: 'InputSourcePopup',
|
||||
Extends: SwitcherPopup.SwitcherPopup,
|
||||
|
||||
var InputSourcePopup = GObject.registerClass(
|
||||
class InputSourcePopup extends SwitcherPopup.SwitcherPopup {
|
||||
_init(items, action, actionBackward) {
|
||||
this.parent(items);
|
||||
super._init(items);
|
||||
|
||||
this._action = action;
|
||||
this._actionBackward = actionBackward;
|
||||
|
||||
this._switcherList = new InputSourceSwitcher(this._items);
|
||||
},
|
||||
}
|
||||
|
||||
_keyPressHandler(keysym, action) {
|
||||
if (action == this._action)
|
||||
@ -99,25 +97,23 @@ var InputSourcePopup = new Lang.Class({
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
|
||||
return Clutter.EVENT_STOP;
|
||||
},
|
||||
}
|
||||
|
||||
_finish() {
|
||||
this.parent();
|
||||
super._finish();
|
||||
|
||||
this._items[this._selectedIndex].activate(true);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
var InputSourceSwitcher = new Lang.Class({
|
||||
Name: 'InputSourceSwitcher',
|
||||
Extends: SwitcherPopup.SwitcherList,
|
||||
|
||||
var InputSourceSwitcher = GObject.registerClass(
|
||||
class InputSourceSwitcher extends SwitcherPopup.SwitcherList {
|
||||
_init(items) {
|
||||
this.parent(true);
|
||||
super._init(true);
|
||||
|
||||
for (let i = 0; i < items.length; i++)
|
||||
this._addIcon(items[i]);
|
||||
},
|
||||
}
|
||||
|
||||
_addIcon(item) {
|
||||
let box = new St.BoxLayout({ vertical: true });
|
||||
@ -780,9 +776,8 @@ function getInputSourceManager() {
|
||||
return _inputSourceManager;
|
||||
}
|
||||
|
||||
var InputSourceIndicatorContainer = new Lang.Class({
|
||||
Name: 'InputSourceIndicatorContainer',
|
||||
Extends: St.Widget,
|
||||
var InputSourceIndicatorContainer = GObject.registerClass(
|
||||
class InputSourceIndicatorContainer extends St.Widget {
|
||||
|
||||
vfunc_get_preferred_width(forHeight) {
|
||||
// Here, and in vfunc_get_preferred_height, we need to query
|
||||
@ -793,7 +788,7 @@ var InputSourceIndicatorContainer = new Lang.Class({
|
||||
return [Math.max(maxWidth[0], width[0]),
|
||||
Math.max(maxWidth[1], width[1])];
|
||||
}, [0, 0]);
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_get_preferred_height(forWidth) {
|
||||
return this.get_children().reduce((maxHeight, child) => {
|
||||
@ -801,7 +796,7 @@ var InputSourceIndicatorContainer = new Lang.Class({
|
||||
return [Math.max(maxHeight[0], height[0]),
|
||||
Math.max(maxHeight[1], height[1])];
|
||||
}, [0, 0]);
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_allocate(box, flags) {
|
||||
this.set_allocation(box, flags);
|
||||
@ -818,12 +813,10 @@ var InputSourceIndicatorContainer = new Lang.Class({
|
||||
}
|
||||
});
|
||||
|
||||
var InputSourceIndicator = new Lang.Class({
|
||||
Name: 'InputSourceIndicator',
|
||||
Extends: PanelMenu.Button,
|
||||
|
||||
var InputSourceIndicator = GObject.registerClass(
|
||||
class InputSourceIndicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
this.parent(0.0, _("Keyboard"));
|
||||
super._init(0.0, _("Keyboard"));
|
||||
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
|
||||
@ -856,7 +849,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
this._inputSourceManagerCurrentSourceChangedId =
|
||||
this._inputSourceManager.connect('current-source-changed', this._currentSourceChanged.bind(this));
|
||||
this._inputSourceManager.reload();
|
||||
},
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
if (this._inputSourceManager) {
|
||||
@ -864,7 +857,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
this._inputSourceManager.disconnect(this._inputSourceManagerCurrentSourceChangedId);
|
||||
this._inputSourceManager = null;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_sessionUpdated() {
|
||||
// re-using "allowSettings" for the keyboard layout is a bit shady,
|
||||
@ -872,7 +865,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
// from shell menus"; we can always add a separate sessionMode
|
||||
// option if need arises.
|
||||
this._showLayoutItem.actor.visible = Main.sessionMode.allowSettings;
|
||||
},
|
||||
}
|
||||
|
||||
_sourcesChanged() {
|
||||
for (let i in this._menuItems)
|
||||
@ -903,7 +896,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
this.menu.addMenuItem(menuItem, menuIndex++);
|
||||
this._container.add_actor(indicatorLabel);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_currentSourceChanged(manager, oldSource) {
|
||||
let nVisibleSources = Object.keys(this._inputSourceManager.inputSources).length;
|
||||
@ -932,7 +925,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
|
||||
this._menuItems[newSource.index].setOrnament(PopupMenu.Ornament.DOT);
|
||||
this._indicatorLabels[newSource.index].show();
|
||||
},
|
||||
}
|
||||
|
||||
_buildPropSection(properties) {
|
||||
this._propSeparator.actor.hide();
|
||||
@ -945,7 +938,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
this._propSection.actor.show();
|
||||
this._propSeparator.actor.show();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_buildPropSubMenu(menu, props) {
|
||||
if (!props)
|
||||
@ -1047,7 +1040,7 @@ var InputSourceIndicator = new Lang.Class({
|
||||
item.setSensitive(prop.get_sensitive());
|
||||
menu.addMenuItem(item);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_showLayout() {
|
||||
Main.overview.hide();
|
||||
@ -1074,5 +1067,5 @@ var InputSourceIndicator = new Lang.Class({
|
||||
description = description + '\t' + xkbVariant;
|
||||
|
||||
Util.spawn(['gkbd-keyboard-display', '-l', description]);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user