cleanup: Use inheritance for Actor classes instead of composition
Remove the `this.actor = ...` and `this.actor._delegate = this` patterns in most of classes, by inheriting all the actor container classes. Uses interfaces when needed for making sure that multiple classes will implement some required methods or to avoid redefining the same code multiple times. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:

committed by
Florian Müllner

parent
f67b409fc1
commit
c4c5c4fd5c
@ -1,8 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported ScreenshotService */
|
||||
|
||||
const { Clutter, Graphene, Gio, GLib, Meta, Shell, St } = imports.gi;
|
||||
const Signals = imports.signals;
|
||||
const { Clutter, Graphene, Gio, GObject, GLib, Meta, Shell, St } = imports.gi;
|
||||
|
||||
const GrabHelper = imports.ui.grabHelper;
|
||||
const Lightbox = imports.ui.lightbox;
|
||||
@ -219,48 +218,53 @@ var ScreenshotService = class {
|
||||
}
|
||||
};
|
||||
|
||||
var SelectArea = class {
|
||||
constructor() {
|
||||
var SelectArea = GObject.registerClass({
|
||||
GTypeName: 'Screenshot_SelectArea',
|
||||
Signals: { 'finished': { param_types: [Meta.Rectangle.$gtype] } }
|
||||
}, class SelectArea extends St.Widget {
|
||||
_init() {
|
||||
this._startX = -1;
|
||||
this._startY = -1;
|
||||
this._lastX = 0;
|
||||
this._lastY = 0;
|
||||
this._result = null;
|
||||
|
||||
this._group = new St.Widget({ visible: false,
|
||||
reactive: true,
|
||||
x: 0,
|
||||
y: 0 });
|
||||
Main.uiGroup.add_actor(this._group);
|
||||
super._init({
|
||||
visible: false,
|
||||
reactive: true,
|
||||
x: 0,
|
||||
y: 0
|
||||
});
|
||||
Main.uiGroup.add_actor(this);
|
||||
|
||||
this._grabHelper = new GrabHelper.GrabHelper(this._group);
|
||||
this._grabHelper = new GrabHelper.GrabHelper(this);
|
||||
|
||||
this._group.connect('button-press-event',
|
||||
this._onButtonPress.bind(this));
|
||||
this._group.connect('button-release-event',
|
||||
this._onButtonRelease.bind(this));
|
||||
this._group.connect('motion-event',
|
||||
this._onMotionEvent.bind(this));
|
||||
this.connect('button-press-event',
|
||||
this._onButtonPress.bind(this));
|
||||
this.connect('button-release-event',
|
||||
this._onButtonRelease.bind(this));
|
||||
this.connect('motion-event',
|
||||
this._onMotionEvent.bind(this));
|
||||
|
||||
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
||||
coordinate: Clutter.BindCoordinate.ALL });
|
||||
this._group.add_constraint(constraint);
|
||||
this.add_constraint(constraint);
|
||||
|
||||
this._rubberband = new St.Widget({
|
||||
style_class: 'select-area-rubberband',
|
||||
visible: false
|
||||
});
|
||||
this._group.add_actor(this._rubberband);
|
||||
this.add_actor(this._rubberband);
|
||||
}
|
||||
|
||||
show() {
|
||||
if (!this._grabHelper.grab({ actor: this._group,
|
||||
vfunc_show() {
|
||||
if (!this._grabHelper.grab({ actor: this,
|
||||
onUngrab: this._onUngrab.bind(this) }))
|
||||
return;
|
||||
|
||||
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
|
||||
Main.uiGroup.set_child_above_sibling(this._group, null);
|
||||
this._group.visible = true;
|
||||
Main.uiGroup.set_child_above_sibling(this, null);
|
||||
super.vfunc_show();
|
||||
}
|
||||
|
||||
_getGeometry() {
|
||||
@ -299,7 +303,7 @@ var SelectArea = class {
|
||||
|
||||
_onButtonRelease() {
|
||||
this._result = this._getGeometry();
|
||||
this._group.ease({
|
||||
this.ease({
|
||||
opacity: 0,
|
||||
duration: 200,
|
||||
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
||||
@ -313,39 +317,40 @@ var SelectArea = class {
|
||||
this.emit('finished', this._result);
|
||||
|
||||
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
this._group.destroy();
|
||||
this.destroy();
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(SelectArea.prototype);
|
||||
});
|
||||
|
||||
var PickPixel = GObject.registerClass({
|
||||
GTypeName: 'Screenshot_PickPixel',
|
||||
Signals: { 'finished': { param_types: [Graphene.Point.$gtype] } }
|
||||
}, class PickPixel extends St.Widget {
|
||||
_init() {
|
||||
super._init({ visible: false, reactive: true });
|
||||
|
||||
var PickPixel = class {
|
||||
constructor() {
|
||||
this._result = null;
|
||||
|
||||
this._group = new St.Widget({ visible: false,
|
||||
reactive: true });
|
||||
Main.uiGroup.add_actor(this._group);
|
||||
Main.uiGroup.add_actor(this);
|
||||
|
||||
this._grabHelper = new GrabHelper.GrabHelper(this._group);
|
||||
this._grabHelper = new GrabHelper.GrabHelper(this);
|
||||
|
||||
this._group.connect('button-release-event',
|
||||
this._onButtonRelease.bind(this));
|
||||
this.connect('button-release-event', this._onButtonRelease.bind(this));
|
||||
|
||||
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
||||
coordinate: Clutter.BindCoordinate.ALL });
|
||||
this._group.add_constraint(constraint);
|
||||
this.add_constraint(constraint);
|
||||
}
|
||||
|
||||
show() {
|
||||
if (!this._grabHelper.grab({ actor: this._group,
|
||||
vfunc_show() {
|
||||
if (!this._grabHelper.grab({ actor: this,
|
||||
onUngrab: this._onUngrab.bind(this) }))
|
||||
return;
|
||||
|
||||
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
|
||||
Main.uiGroup.set_child_above_sibling(this._group, null);
|
||||
this._group.visible = true;
|
||||
Main.uiGroup.set_child_above_sibling(this, null);
|
||||
super.vfunc_show();
|
||||
}
|
||||
|
||||
_onButtonRelease(actor, event) {
|
||||
@ -360,29 +365,29 @@ var PickPixel = class {
|
||||
this.emit('finished', this._result);
|
||||
|
||||
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
this._group.destroy();
|
||||
this.destroy();
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(PickPixel.prototype);
|
||||
});
|
||||
|
||||
var FLASHSPOT_ANIMATION_OUT_TIME = 500; // milliseconds
|
||||
|
||||
var Flashspot = class extends Lightbox.Lightbox {
|
||||
constructor(area) {
|
||||
super(Main.uiGroup, { inhibitEvents: true,
|
||||
width: area.width,
|
||||
height: area.height });
|
||||
|
||||
this.actor.style_class = 'flashspot';
|
||||
this.actor.set_position(area.x, area.y);
|
||||
var Flashspot = GObject.registerClass(
|
||||
class Flashspot extends Lightbox.Lightbox {
|
||||
_init(area) {
|
||||
super._init(Main.uiGroup, {
|
||||
inhibitEvents: true,
|
||||
width: area.width,
|
||||
height: area.height
|
||||
});
|
||||
this.style_class = 'flashspot';
|
||||
this.set_position(area.x, area.y);
|
||||
}
|
||||
|
||||
fire(doneCallback) {
|
||||
this.actor.show();
|
||||
this.actor.opacity = 255;
|
||||
this.actor.ease({
|
||||
this.set({ visible: true, opacity: 255 });
|
||||
this.ease({
|
||||
opacity: 0,
|
||||
duration: FLASHSPOT_ANIMATION_OUT_TIME,
|
||||
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
||||
@ -393,4 +398,4 @@ var Flashspot = class extends Lightbox.Lightbox {
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user