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:

committed by
Georges Basile Stavracas Neto

parent
99ce3deeb0
commit
bacfdbbb03
@ -62,14 +62,12 @@ function _getAutoCompleteGlobalKeywords() {
|
||||
return keywords.concat(windowProperties).concat(headerProperties);
|
||||
}
|
||||
|
||||
var AutoComplete = new Lang.Class({
|
||||
Name: 'AutoComplete',
|
||||
|
||||
_init(entry) {
|
||||
var AutoComplete = class AutoComplete {
|
||||
constructor(entry) {
|
||||
this._entry = entry;
|
||||
this._entry.connect('key-press-event', this._entryKeyPressEvent.bind(this));
|
||||
this._lastTabTime = global.get_current_time();
|
||||
},
|
||||
}
|
||||
|
||||
_processCompletionRequest(event) {
|
||||
if (event.completions.length == 0) {
|
||||
@ -91,7 +89,7 @@ var AutoComplete = new Lang.Class({
|
||||
} else if (event.completions.length > 1 && event.tabType === 'double') {
|
||||
this.emit('suggest', { completions: event.completions});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_entryKeyPressEvent(actor, event) {
|
||||
let cursorPos = this._entry.clutter_text.get_cursor_position();
|
||||
@ -114,7 +112,7 @@ var AutoComplete = new Lang.Class({
|
||||
this._lastTabTime = currTime;
|
||||
}
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
},
|
||||
}
|
||||
|
||||
// Insert characters of text not already included in head at cursor position. i.e., if text="abc" and head="a",
|
||||
// the string "bc" will be appended to this._entry
|
||||
@ -124,21 +122,19 @@ var AutoComplete = new Lang.Class({
|
||||
|
||||
this._entry.clutter_text.insert_text(additionalCompletionText, cursorPos);
|
||||
}
|
||||
});
|
||||
};
|
||||
Signals.addSignalMethods(AutoComplete.prototype);
|
||||
|
||||
|
||||
var Notebook = new Lang.Class({
|
||||
Name: 'Notebook',
|
||||
|
||||
_init() {
|
||||
var Notebook = class Notebook {
|
||||
constructor() {
|
||||
this.actor = new St.BoxLayout({ vertical: true });
|
||||
|
||||
this.tabControls = new St.BoxLayout({ style_class: 'labels' });
|
||||
|
||||
this._selectedIndex = -1;
|
||||
this._tabs = [];
|
||||
},
|
||||
}
|
||||
|
||||
appendPage(name, child) {
|
||||
let labelBox = new St.BoxLayout({ style_class: 'notebook-tab',
|
||||
@ -171,7 +167,7 @@ var Notebook = new Lang.Class({
|
||||
|
||||
if (this._selectedIndex == -1)
|
||||
this.selectIndex(0);
|
||||
},
|
||||
}
|
||||
|
||||
_unselect() {
|
||||
if (this._selectedIndex < 0)
|
||||
@ -180,7 +176,7 @@ var Notebook = new Lang.Class({
|
||||
tabData.labelBox.remove_style_pseudo_class('selected');
|
||||
tabData.scrollView.hide();
|
||||
this._selectedIndex = -1;
|
||||
},
|
||||
}
|
||||
|
||||
selectIndex(index) {
|
||||
if (index == this._selectedIndex)
|
||||
@ -202,7 +198,7 @@ var Notebook = new Lang.Class({
|
||||
tabData.scrollView.show();
|
||||
this._selectedIndex = index;
|
||||
this.emit('selection', tabData.child);
|
||||
},
|
||||
}
|
||||
|
||||
selectChild(child) {
|
||||
if (child == null)
|
||||
@ -216,26 +212,26 @@ var Notebook = new Lang.Class({
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
scrollToBottom(index) {
|
||||
let tabData = this._tabs[index];
|
||||
tabData._scrollToBottom = true;
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
_onAdjustValueChanged(tabData) {
|
||||
let vAdjust = tabData.scrollView.vscroll.adjustment;
|
||||
if (vAdjust.value < (vAdjust.upper - vAdjust.lower - 0.5))
|
||||
tabData._scrolltoBottom = false;
|
||||
},
|
||||
}
|
||||
|
||||
_onAdjustScopeChanged(tabData) {
|
||||
if (!tabData._scrollToBottom)
|
||||
return;
|
||||
let vAdjust = tabData.scrollView.vscroll.adjustment;
|
||||
vAdjust.value = vAdjust.upper - vAdjust.page_size;
|
||||
},
|
||||
}
|
||||
|
||||
nextTab() {
|
||||
let nextIndex = this._selectedIndex;
|
||||
@ -244,7 +240,7 @@ var Notebook = new Lang.Class({
|
||||
}
|
||||
|
||||
this.selectIndex(nextIndex);
|
||||
},
|
||||
}
|
||||
|
||||
prevTab() {
|
||||
let prevIndex = this._selectedIndex;
|
||||
@ -254,7 +250,7 @@ var Notebook = new Lang.Class({
|
||||
|
||||
this.selectIndex(prevIndex);
|
||||
}
|
||||
});
|
||||
};
|
||||
Signals.addSignalMethods(Notebook.prototype);
|
||||
|
||||
function objectToString(o) {
|
||||
@ -266,10 +262,8 @@ function objectToString(o) {
|
||||
}
|
||||
}
|
||||
|
||||
var ObjLink = new Lang.Class({
|
||||
Name: 'ObjLink',
|
||||
|
||||
_init(lookingGlass, o, title) {
|
||||
var ObjLink = class ObjLink {
|
||||
constructor(lookingGlass, o, title) {
|
||||
let text;
|
||||
if (title)
|
||||
text = title;
|
||||
@ -286,17 +280,15 @@ var ObjLink = new Lang.Class({
|
||||
this.actor.connect('clicked', this._onClicked.bind(this));
|
||||
|
||||
this._lookingGlass = lookingGlass;
|
||||
},
|
||||
}
|
||||
|
||||
_onClicked(link) {
|
||||
this._lookingGlass.inspectObject(this._obj, this.actor);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var Result = new Lang.Class({
|
||||
Name: 'Result',
|
||||
|
||||
_init(lookingGlass, command, o, index) {
|
||||
var Result = class Result {
|
||||
constructor(lookingGlass, command, o, index) {
|
||||
this.index = index;
|
||||
this.o = o;
|
||||
|
||||
@ -314,12 +306,10 @@ var Result = new Lang.Class({
|
||||
let objLink = new ObjLink(this._lookingGlass, o);
|
||||
box.add(objLink.actor);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var WindowList = new Lang.Class({
|
||||
Name: 'WindowList',
|
||||
|
||||
_init(lookingGlass) {
|
||||
var WindowList = class WindowList {
|
||||
constructor(lookingGlass) {
|
||||
this.actor = new St.BoxLayout({ name: 'Windows', vertical: true, style: 'spacing: 8px' });
|
||||
let tracker = Shell.WindowTracker.get_default();
|
||||
this._updateId = Main.initializeDeferredWork(this.actor, this._updateWindowList.bind(this));
|
||||
@ -327,7 +317,7 @@ var WindowList = new Lang.Class({
|
||||
tracker.connect('tracked-windows-changed', this._updateWindowList.bind(this));
|
||||
|
||||
this._lookingGlass = lookingGlass;
|
||||
},
|
||||
}
|
||||
|
||||
_updateWindowList() {
|
||||
this.actor.destroy_all_children();
|
||||
@ -361,13 +351,11 @@ var WindowList = new Lang.Class({
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Signals.addSignalMethods(WindowList.prototype);
|
||||
|
||||
var ObjInspector = new Lang.Class({
|
||||
Name: 'ObjInspector',
|
||||
|
||||
_init(lookingGlass) {
|
||||
var ObjInspector = class ObjInspector {
|
||||
constructor(lookingGlass) {
|
||||
this._obj = null;
|
||||
this._previousObj = null;
|
||||
|
||||
@ -382,7 +370,7 @@ var ObjInspector = new Lang.Class({
|
||||
this.actor.add_actor(this._container);
|
||||
|
||||
this._lookingGlass = lookingGlass;
|
||||
},
|
||||
}
|
||||
|
||||
selectObject(obj, skipPrevious) {
|
||||
if (!skipPrevious)
|
||||
@ -436,7 +424,7 @@ var ObjInspector = new Lang.Class({
|
||||
this._container.add_actor(hbox);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
open(sourceActor) {
|
||||
if (this._open)
|
||||
@ -452,7 +440,7 @@ var ObjInspector = new Lang.Class({
|
||||
} else {
|
||||
this.actor.set_scale(1, 1);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
close() {
|
||||
if (!this._open)
|
||||
@ -461,18 +449,18 @@ var ObjInspector = new Lang.Class({
|
||||
this.actor.hide();
|
||||
this._previousObj = null;
|
||||
this._obj = null;
|
||||
},
|
||||
}
|
||||
|
||||
_onInsert() {
|
||||
let obj = this._obj;
|
||||
this.close();
|
||||
this._lookingGlass.insertObject(obj);
|
||||
},
|
||||
}
|
||||
|
||||
_onBack() {
|
||||
this.selectObject(this._previousObj, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var RedBorderEffect = new Lang.Class({
|
||||
Name: 'RedBorderEffect',
|
||||
@ -637,10 +625,8 @@ var Inspector = new Lang.Class({
|
||||
}
|
||||
});
|
||||
|
||||
var Extensions = new Lang.Class({
|
||||
Name: 'Extensions',
|
||||
|
||||
_init(lookingGlass) {
|
||||
var Extensions = class Extensions {
|
||||
constructor(lookingGlass) {
|
||||
this._lookingGlass = lookingGlass;
|
||||
this.actor = new St.BoxLayout({ vertical: true,
|
||||
name: 'lookingGlassExtensions' });
|
||||
@ -657,7 +643,7 @@ var Extensions = new Lang.Class({
|
||||
|
||||
ExtensionSystem.connect('extension-loaded',
|
||||
this._loadExtension.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
_loadExtension(o, uuid) {
|
||||
let extension = ExtensionUtils.extensions[uuid];
|
||||
@ -672,20 +658,20 @@ var Extensions = new Lang.Class({
|
||||
|
||||
this._numExtensions ++;
|
||||
this._extensionsList.add(extensionDisplay);
|
||||
},
|
||||
}
|
||||
|
||||
_onViewSource(actor) {
|
||||
let extension = actor._extension;
|
||||
let uri = extension.dir.get_uri();
|
||||
Gio.app_info_launch_default_for_uri(uri, global.create_app_launch_context(0, -1));
|
||||
this._lookingGlass.close();
|
||||
},
|
||||
}
|
||||
|
||||
_onWebPage(actor) {
|
||||
let extension = actor._extension;
|
||||
Gio.app_info_launch_default_for_uri(extension.metadata.url, global.create_app_launch_context(0, -1));
|
||||
this._lookingGlass.close();
|
||||
},
|
||||
}
|
||||
|
||||
_onViewErrors(actor) {
|
||||
let extension = actor._extension;
|
||||
@ -713,7 +699,7 @@ var Extensions = new Lang.Class({
|
||||
}
|
||||
|
||||
actor._isShowing = shouldShow;
|
||||
},
|
||||
}
|
||||
|
||||
_stateToString(extensionState) {
|
||||
switch (extensionState) {
|
||||
@ -730,7 +716,7 @@ var Extensions = new Lang.Class({
|
||||
return _("Downloading");
|
||||
}
|
||||
return 'Unknown'; // Not translated, shouldn't appear
|
||||
},
|
||||
}
|
||||
|
||||
_createExtensionDisplay(extension) {
|
||||
let box = new St.BoxLayout({ style_class: 'lg-extension', vertical: true });
|
||||
@ -778,12 +764,10 @@ var Extensions = new Lang.Class({
|
||||
|
||||
return box;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var LookingGlass = new Lang.Class({
|
||||
Name: 'LookingGlass',
|
||||
|
||||
_init() {
|
||||
var LookingGlass = class LookingGlass {
|
||||
constructor() {
|
||||
this._borderPaintTarget = null;
|
||||
this._redBorderEffect = new RedBorderEffect();
|
||||
|
||||
@ -917,7 +901,7 @@ var LookingGlass = new Lang.Class({
|
||||
});
|
||||
|
||||
this._resize();
|
||||
},
|
||||
}
|
||||
|
||||
_updateFont() {
|
||||
let fontName = this._interfaceSettings.get_string('monospace-font-name');
|
||||
@ -927,7 +911,7 @@ var LookingGlass = new Lang.Class({
|
||||
this.actor.style =
|
||||
'font-size: ' + fontDesc.get_size() / 1024. + (fontDesc.get_size_is_absolute() ? 'px' : 'pt') + ';'
|
||||
+ 'font-family: "' + fontDesc.get_family() + '";';
|
||||
},
|
||||
}
|
||||
|
||||
setBorderPaintTarget(obj) {
|
||||
if (this._borderPaintTarget != null)
|
||||
@ -935,7 +919,7 @@ var LookingGlass = new Lang.Class({
|
||||
this._borderPaintTarget = obj;
|
||||
if (this._borderPaintTarget != null)
|
||||
this._borderPaintTarget.add_effect(this._redBorderEffect);
|
||||
},
|
||||
}
|
||||
|
||||
_pushResult(command, obj) {
|
||||
let index = this._results.length + this._offset;
|
||||
@ -955,7 +939,7 @@ var LookingGlass = new Lang.Class({
|
||||
|
||||
// Scroll to bottom
|
||||
this._notebook.scrollToBottom(0);
|
||||
},
|
||||
}
|
||||
|
||||
_showCompletions(completions) {
|
||||
if (!this._completionActor) {
|
||||
@ -984,7 +968,7 @@ var LookingGlass = new Lang.Class({
|
||||
opacity: 255
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_hideCompletions() {
|
||||
if (this._completionActor) {
|
||||
@ -998,7 +982,7 @@ var LookingGlass = new Lang.Class({
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_evaluate(command) {
|
||||
this._history.addItem(command);
|
||||
@ -1017,30 +1001,30 @@ var LookingGlass = new Lang.Class({
|
||||
|
||||
this._pushResult(command, resultObj);
|
||||
this._entry.text = '';
|
||||
},
|
||||
}
|
||||
|
||||
inspect(x, y) {
|
||||
return global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
|
||||
},
|
||||
}
|
||||
|
||||
getIt() {
|
||||
return this._it;
|
||||
},
|
||||
}
|
||||
|
||||
getResult(idx) {
|
||||
return this._results[idx - this._offset].o;
|
||||
},
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this._open)
|
||||
this.close();
|
||||
else
|
||||
this.open();
|
||||
},
|
||||
}
|
||||
|
||||
_queueResize() {
|
||||
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { this._resize(); });
|
||||
},
|
||||
}
|
||||
|
||||
_resize() {
|
||||
let primary = Main.layoutManager.primaryMonitor;
|
||||
@ -1056,16 +1040,16 @@ var LookingGlass = new Lang.Class({
|
||||
this._objInspector.actor.set_size(Math.floor(myWidth * 0.8), Math.floor(myHeight * 0.8));
|
||||
this._objInspector.actor.set_position(this.actor.x + Math.floor(myWidth * 0.1),
|
||||
this._targetY + Math.floor(myHeight * 0.1));
|
||||
},
|
||||
}
|
||||
|
||||
insertObject(obj) {
|
||||
this._pushResult('<insert>', obj);
|
||||
},
|
||||
}
|
||||
|
||||
inspectObject(obj, sourceActor) {
|
||||
this._objInspector.open(sourceActor);
|
||||
this._objInspector.selectObject(obj);
|
||||
},
|
||||
}
|
||||
|
||||
// Handle key events which are relevant for all tabs of the LookingGlass
|
||||
_globalKeyPressEvent(actor, event) {
|
||||
@ -1088,7 +1072,7 @@ var LookingGlass = new Lang.Class({
|
||||
}
|
||||
}
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
},
|
||||
}
|
||||
|
||||
open() {
|
||||
if (this._open)
|
||||
@ -1110,7 +1094,7 @@ var LookingGlass = new Lang.Class({
|
||||
transition: 'easeOutQuad',
|
||||
y: this._targetY
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
close() {
|
||||
if (!this._open)
|
||||
@ -1133,5 +1117,5 @@ var LookingGlass = new Lang.Class({
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
Signals.addSignalMethods(LookingGlass.prototype);
|
||||
|
Reference in New Issue
Block a user