2009-08-02 07:46:01 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2010-05-05 21:05:42 +00:00
|
|
|
const GConf = imports.gi.GConf;
|
2010-05-15 16:43:56 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
2009-08-02 07:46:01 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Pango = imports.gi.Pango;
|
2009-09-10 05:38:13 +00:00
|
|
|
const St = imports.gi.St;
|
2009-08-02 07:46:01 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2009-10-28 22:05:34 +00:00
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-10-28 22:05:34 +00:00
|
|
|
const ExtensionSystem = imports.ui.extensionSystem;
|
|
|
|
const Link = imports.ui.link;
|
2009-08-02 07:46:01 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
/* Imports...feel free to add here as needed */
|
2010-05-13 19:46:04 +00:00
|
|
|
var commandHeader = 'const Clutter = imports.gi.Clutter; ' +
|
|
|
|
'const GLib = imports.gi.GLib; ' +
|
|
|
|
'const Gtk = imports.gi.Gtk; ' +
|
|
|
|
'const Mainloop = imports.mainloop; ' +
|
|
|
|
'const Meta = imports.gi.Meta; ' +
|
|
|
|
'const Shell = imports.gi.Shell; ' +
|
|
|
|
'const Main = imports.ui.main; ' +
|
|
|
|
'const Lang = imports.lang; ' +
|
|
|
|
'const Tweener = imports.ui.tweener; ' +
|
2009-08-02 07:46:01 +00:00
|
|
|
/* Utility functions...we should probably be able to use these
|
|
|
|
* in the shell core code too. */
|
2010-05-13 19:46:04 +00:00
|
|
|
'const stage = global.stage; ' +
|
|
|
|
'const color = function(pixel) { let c= new Clutter.Color(); c.from_pixel(pixel); return c; }; ' +
|
2009-08-02 07:46:01 +00:00
|
|
|
/* Special lookingGlass functions */
|
2010-05-13 19:46:04 +00:00
|
|
|
'const it = Main.lookingGlass.getIt(); ' +
|
|
|
|
'const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); ';
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-08-04 13:49:03 +00:00
|
|
|
function Notebook() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Notebook.prototype = {
|
|
|
|
_init: function() {
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor = new St.BoxLayout({ vertical: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
this.tabControls = new St.BoxLayout({ style_class: 'labels' });
|
2009-08-04 13:49:03 +00:00
|
|
|
|
|
|
|
this._selectedIndex = -1;
|
|
|
|
this._tabs = [];
|
|
|
|
},
|
|
|
|
|
|
|
|
appendPage: function(name, child) {
|
2010-05-15 16:43:56 +00:00
|
|
|
let labelBox = new St.BoxLayout({ style_class: 'notebook-tab',
|
|
|
|
reactive: true,
|
|
|
|
track_hover: true });
|
2009-10-27 17:27:00 +00:00
|
|
|
let label = new St.Button({ label: name });
|
|
|
|
label.connect('clicked', Lang.bind(this, function () {
|
2009-08-04 13:49:03 +00:00
|
|
|
this.selectChild(child);
|
|
|
|
return true;
|
|
|
|
}));
|
2009-09-10 05:38:13 +00:00
|
|
|
labelBox.add(label, { expand: true });
|
2009-10-27 17:27:00 +00:00
|
|
|
this.tabControls.add(labelBox);
|
2009-09-10 05:38:13 +00:00
|
|
|
|
|
|
|
let scrollview = new St.ScrollView({ x_fill: true, y_fill: true });
|
|
|
|
scrollview.get_hscroll_bar().hide();
|
|
|
|
scrollview.add_actor(child);
|
|
|
|
|
2009-10-09 00:11:45 +00:00
|
|
|
let tabData = { child: child,
|
|
|
|
labelBox: labelBox,
|
2009-10-27 17:27:00 +00:00
|
|
|
label: label,
|
2009-10-09 00:11:45 +00:00
|
|
|
scrollView: scrollview,
|
|
|
|
_scrollToBottom: false };
|
|
|
|
this._tabs.push(tabData);
|
2009-09-10 05:38:13 +00:00
|
|
|
scrollview.hide();
|
|
|
|
this.actor.add(scrollview, { expand: true });
|
|
|
|
|
2009-10-09 00:11:45 +00:00
|
|
|
let vAdjust = scrollview.vscroll.adjustment;
|
|
|
|
vAdjust.connect('changed', Lang.bind(this, function () { this._onAdjustScopeChanged(tabData); }));
|
|
|
|
vAdjust.connect('notify::value', Lang.bind(this, function() { this._onAdjustValueChanged(tabData); }));
|
|
|
|
|
2009-08-04 13:49:03 +00:00
|
|
|
if (this._selectedIndex == -1)
|
|
|
|
this.selectIndex(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
_unselect: function() {
|
|
|
|
if (this._selectedIndex < 0)
|
|
|
|
return;
|
2009-10-09 00:11:45 +00:00
|
|
|
let tabData = this._tabs[this._selectedIndex];
|
2010-03-19 15:37:04 +00:00
|
|
|
tabData.labelBox.remove_style_pseudo_class('selected');
|
2009-10-09 00:11:45 +00:00
|
|
|
tabData.scrollView.hide();
|
2009-08-04 13:49:03 +00:00
|
|
|
this._selectedIndex = -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
selectIndex: function(index) {
|
|
|
|
if (index == this._selectedIndex)
|
|
|
|
return;
|
|
|
|
this._unselect();
|
|
|
|
if (index < 0) {
|
|
|
|
this.emit('selection', null);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-09 00:11:45 +00:00
|
|
|
let tabData = this._tabs[index];
|
2010-03-19 15:37:04 +00:00
|
|
|
tabData.labelBox.add_style_pseudo_class('selected');
|
2009-10-09 00:11:45 +00:00
|
|
|
tabData.scrollView.show();
|
2009-08-04 13:49:03 +00:00
|
|
|
this._selectedIndex = index;
|
2009-10-09 00:11:45 +00:00
|
|
|
this.emit('selection', tabData.child);
|
2009-08-04 13:49:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
selectChild: function(child) {
|
|
|
|
if (child == null)
|
|
|
|
this.selectIndex(-1);
|
|
|
|
else {
|
|
|
|
for (let i = 0; i < this._tabs.length; i++) {
|
2009-10-09 00:11:45 +00:00
|
|
|
let tabData = this._tabs[i];
|
|
|
|
if (tabData.child == child) {
|
2009-08-04 13:49:03 +00:00
|
|
|
this.selectIndex(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-09 00:11:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
scrollToBottom: function(index) {
|
|
|
|
let tabData = this._tabs[index];
|
|
|
|
tabData._scrollToBottom = true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_onAdjustValueChanged: function (tabData) {
|
|
|
|
let vAdjust = tabData.scrollView.vscroll.adjustment;
|
|
|
|
if (vAdjust.value < (vAdjust.upper - vAdjust.lower - 0.5))
|
|
|
|
tabData._scrolltoBottom = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onAdjustScopeChanged: function (tabData) {
|
|
|
|
if (!tabData._scrollToBottom)
|
|
|
|
return;
|
|
|
|
let vAdjust = tabData.scrollView.vscroll.adjustment;
|
|
|
|
vAdjust.value = vAdjust.upper - vAdjust.page_size;
|
2009-08-04 13:49:03 +00:00
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2009-08-04 13:49:03 +00:00
|
|
|
Signals.addSignalMethods(Notebook.prototype);
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
function objectToString(o) {
|
|
|
|
if (typeof(o) == typeof(objectToString)) {
|
|
|
|
// special case this since the default is way, way too verbose
|
|
|
|
return "<js function>";
|
|
|
|
} else {
|
|
|
|
return "" + o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ObjLink(o, title) {
|
|
|
|
this._init(o, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjLink.prototype = {
|
|
|
|
__proto__: Link.Link,
|
|
|
|
|
|
|
|
_init: function(o, title) {
|
|
|
|
let text;
|
|
|
|
if (title)
|
|
|
|
text = title;
|
|
|
|
else
|
|
|
|
text = objectToString(o);
|
|
|
|
text = GLib.markup_escape_text(text, -1);
|
|
|
|
this._obj = o;
|
|
|
|
Link.Link.prototype._init.call(this, { label: text });
|
|
|
|
this.actor.get_child().single_line_mode = true;
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClicked: function (link) {
|
|
|
|
Main.lookingGlass.inspectObject(this._obj, this.actor);
|
|
|
|
}
|
2010-05-19 17:26:41 +00:00
|
|
|
};
|
2010-05-15 16:43:56 +00:00
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
function Result(command, o, index) {
|
|
|
|
this._init(command, o, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result.prototype = {
|
|
|
|
_init : function(command, o, index) {
|
|
|
|
this.index = index;
|
|
|
|
this.o = o;
|
|
|
|
|
2010-03-31 20:40:32 +00:00
|
|
|
this.actor = new St.BoxLayout({ vertical: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
let cmdTxt = new St.Label({ text: command });
|
2010-05-15 16:43:56 +00:00
|
|
|
cmdTxt.clutter_text.ellipsize = Pango.EllipsizeMode.END;
|
2010-03-31 20:40:32 +00:00
|
|
|
this.actor.add(cmdTxt);
|
2010-05-15 16:43:56 +00:00
|
|
|
let box = new St.BoxLayout({});
|
|
|
|
this.actor.add(box);
|
|
|
|
let resultTxt = new St.Label({ text: 'r(' + index + ') = ' });
|
|
|
|
resultTxt.clutter_text.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
box.add(resultTxt);
|
|
|
|
let objLink = new ObjLink(o);
|
|
|
|
box.add(objLink.actor);
|
|
|
|
let line = new Clutter.Rectangle({ name: 'Separator' });
|
2010-05-13 19:46:04 +00:00
|
|
|
let padBin = new St.Bin({ name: 'Separator', x_fill: true, y_fill: true });
|
2009-09-10 05:38:13 +00:00
|
|
|
padBin.add_actor(line);
|
2010-03-31 20:40:32 +00:00
|
|
|
this.actor.add(padBin);
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-04-20 18:57:31 +00:00
|
|
|
function WindowList() {
|
2009-08-02 07:46:01 +00:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2010-04-20 18:57:31 +00:00
|
|
|
WindowList.prototype = {
|
2009-08-02 07:46:01 +00:00
|
|
|
_init : function () {
|
2010-05-13 19:46:04 +00:00
|
|
|
this.actor = new St.BoxLayout({ name: 'Windows', vertical: true, style: 'spacing: 8px' });
|
2010-04-20 18:57:31 +00:00
|
|
|
let display = global.screen.get_display();
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
this._updateId = Main.initializeDeferredWork(this.actor, Lang.bind(this, this._updateWindowList));
|
|
|
|
display.connect('window-created', Lang.bind(this, this._updateWindowList));
|
|
|
|
tracker.connect('tracked-windows-changed', Lang.bind(this, this._updateWindowList));
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
2010-04-20 18:57:31 +00:00
|
|
|
_updateWindowList: function() {
|
|
|
|
this.actor.get_children().forEach(function (actor) { actor.destroy(); });
|
|
|
|
let windows = global.get_windows();
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let metaWindow = windows[i].metaWindow;
|
2010-05-30 20:48:41 +00:00
|
|
|
// Avoid multiple connections
|
|
|
|
if (!metaWindow._lookingGlassManaged) {
|
|
|
|
metaWindow.connect('unmanaged', Lang.bind(this, this._updateWindowList));
|
|
|
|
metaWindow._lookingGlassManaged = true;
|
|
|
|
}
|
2010-04-20 18:57:31 +00:00
|
|
|
let box = new St.BoxLayout({ vertical: true });
|
|
|
|
this.actor.add(box);
|
2010-05-15 16:43:56 +00:00
|
|
|
let windowLink = new ObjLink(metaWindow, metaWindow.title);
|
|
|
|
box.add(windowLink.actor, { x_align: St.Align.START, x_fill: false });
|
2010-04-20 18:57:31 +00:00
|
|
|
let propsBox = new St.BoxLayout({ vertical: true, style: 'padding-left: 6px;' });
|
|
|
|
box.add(propsBox);
|
2010-05-13 19:46:04 +00:00
|
|
|
propsBox.add(new St.Label({ text: 'wmclass: ' + metaWindow.get_wm_class() }));
|
2010-04-20 18:57:31 +00:00
|
|
|
let app = tracker.get_window_app(metaWindow);
|
|
|
|
if (app != null && !app.is_transient()) {
|
|
|
|
let icon = app.create_icon_texture(22);
|
|
|
|
let propBox = new St.BoxLayout({ style: 'spacing: 6px; ' });
|
|
|
|
propsBox.add(propBox);
|
2010-05-15 16:43:56 +00:00
|
|
|
propBox.add(new St.Label({ text: 'app: ' }), { y_fill: false });
|
|
|
|
let appLink = new ObjLink(app, app.get_id());
|
|
|
|
propBox.add(appLink.actor, { y_fill: false });
|
|
|
|
propBox.add(icon, { y_fill: false });
|
2010-04-20 18:57:31 +00:00
|
|
|
} else {
|
2010-05-13 19:46:04 +00:00
|
|
|
propsBox.add(new St.Label({ text: '<untracked>' }));
|
2010-04-20 18:57:31 +00:00
|
|
|
}
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2010-04-20 18:57:31 +00:00
|
|
|
Signals.addSignalMethods(WindowList.prototype);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
function ObjInspector() {
|
2009-08-02 07:46:01 +00:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
ObjInspector.prototype = {
|
2009-08-02 07:46:01 +00:00
|
|
|
_init : function () {
|
2010-05-15 16:43:56 +00:00
|
|
|
this._obj = null;
|
|
|
|
this._previousObj = null;
|
2009-08-02 07:46:01 +00:00
|
|
|
|
|
|
|
this._parentList = [];
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
this.actor = new St.ScrollView({ x_fill: true, y_fill: true });
|
|
|
|
this.actor.get_hscroll_bar().hide();
|
|
|
|
this._container = new St.BoxLayout({ name: 'LookingGlassPropertyInspector',
|
|
|
|
style_class: 'lg-dialog',
|
|
|
|
vertical: true });
|
|
|
|
this.actor.add_actor(this._container);
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
selectObject: function(obj, skipPrevious) {
|
|
|
|
if (!skipPrevious)
|
|
|
|
this._previousObj = this._obj;
|
|
|
|
else
|
|
|
|
this._previousObj = null;
|
|
|
|
this._obj = obj;
|
|
|
|
|
|
|
|
this._container.get_children().forEach(function (child) { child.destroy(); });
|
|
|
|
|
|
|
|
let hbox = new St.BoxLayout({ style_class: 'lg-obj-inspector-title' });
|
|
|
|
this._container.add_actor(hbox);
|
|
|
|
let label = new St.Label({ text: 'Inspecting: %s: %s'.format(typeof(obj),
|
|
|
|
objectToString(obj)) });
|
|
|
|
label.single_line_mode = true;
|
|
|
|
hbox.add(label, { expand: true, y_fill: false });
|
|
|
|
let button = new St.Button({ label: 'Insert', style_class: 'lg-obj-inspector-button' });
|
|
|
|
button.connect('clicked', Lang.bind(this, this._onInsert));
|
|
|
|
hbox.add(button);
|
|
|
|
|
|
|
|
if (this._previousObj != null) {
|
|
|
|
button = new St.Button({ label: 'Back', style_class: 'lg-obj-inspector-button' });
|
|
|
|
button.connect('clicked', Lang.bind(this, this._onBack));
|
|
|
|
hbox.add(button);
|
|
|
|
}
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
button = new St.Button({ style_class: 'window-close' });
|
|
|
|
button.connect('clicked', Lang.bind(this, this.close));
|
|
|
|
hbox.add(button);
|
|
|
|
if (typeof(obj) == typeof({})) {
|
|
|
|
for (let propName in obj) {
|
|
|
|
let valueStr;
|
|
|
|
let link;
|
|
|
|
try {
|
|
|
|
let prop = obj[propName];
|
|
|
|
link = new ObjLink(prop).actor;
|
|
|
|
} catch (e) {
|
|
|
|
link = new St.Label({ text: '<error>' });
|
|
|
|
}
|
|
|
|
let hbox = new St.BoxLayout();
|
|
|
|
let propText = propName + ": " + valueStr;
|
|
|
|
hbox.add(new St.Label({ text: propName + ': ' }));
|
|
|
|
hbox.add(link);
|
|
|
|
this._container.add_actor(hbox);
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-15 16:43:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
open: function(sourceActor) {
|
|
|
|
if (this._open)
|
|
|
|
return;
|
|
|
|
this._previousObj = null;
|
|
|
|
this._open = true;
|
|
|
|
this.actor.show();
|
|
|
|
if (sourceActor) {
|
|
|
|
this.actor.set_scale(0, 0);
|
|
|
|
let [sourceX, sourceY] = sourceActor.get_transformed_position();
|
|
|
|
let [sourceWidth, sourceHeight] = sourceActor.get_transformed_size();
|
|
|
|
this.actor.move_anchor_point(Math.floor(sourceX + sourceWidth / 2),
|
|
|
|
Math.floor(sourceY + sourceHeight / 2));
|
|
|
|
Tweener.addTween(this.actor, { scale_x: 1, scale_y: 1,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
time: 0.2 });
|
|
|
|
} else {
|
|
|
|
this.actor.set_scale(1, 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
if (!this._open)
|
|
|
|
return;
|
|
|
|
this._open = false;
|
|
|
|
this.actor.hide();
|
|
|
|
this._previousObj = null;
|
|
|
|
this._obj = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onInsert: function() {
|
|
|
|
let obj = this._obj;
|
|
|
|
this.close();
|
|
|
|
Main.lookingGlass.insertObject(obj);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onBack: function() {
|
|
|
|
this.selectObject(this._previousObj, true);
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-08-04 13:49:03 +00:00
|
|
|
function Inspector() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Inspector.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
let width = 150;
|
2009-08-25 19:23:53 +00:00
|
|
|
let primary = global.get_primary_monitor();
|
2010-05-13 19:46:04 +00:00
|
|
|
let eventHandler = new St.BoxLayout({ name: 'LookingGlassDialog',
|
2009-09-10 05:38:13 +00:00
|
|
|
vertical: false,
|
|
|
|
y: primary.y + Math.floor(primary.height / 2),
|
|
|
|
reactive: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
eventHandler.connect('notify::allocation', Lang.bind(this, function () {
|
2009-08-25 19:23:53 +00:00
|
|
|
eventHandler.x = primary.x + Math.floor((primary.width - eventHandler.width) / 2);
|
2009-08-04 13:49:03 +00:00
|
|
|
}));
|
2010-05-06 21:18:10 +00:00
|
|
|
Main.uiGroup.add_actor(eventHandler);
|
2009-09-10 05:38:13 +00:00
|
|
|
let displayText = new St.Label();
|
|
|
|
eventHandler.add(displayText, { expand: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
|
|
|
|
let borderPaintTarget = null;
|
|
|
|
let borderPaintId = null;
|
|
|
|
eventHandler.connect('destroy', Lang.bind(this, function() {
|
|
|
|
if (borderPaintTarget != null)
|
|
|
|
borderPaintTarget.disconnect(borderPaintId);
|
|
|
|
}));
|
|
|
|
|
|
|
|
eventHandler.connect('button-press-event', Lang.bind(this, function (actor, event) {
|
|
|
|
Clutter.ungrab_pointer(eventHandler);
|
|
|
|
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
let target = global.stage.get_actor_at_pos(Clutter.PickMode.ALL,
|
|
|
|
stageX,
|
|
|
|
stageY);
|
|
|
|
this.emit('target', target, stageX, stageY);
|
|
|
|
eventHandler.destroy();
|
|
|
|
this.emit('closed');
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
eventHandler.connect('motion-event', Lang.bind(this, function (actor, event) {
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
let target = global.stage.get_actor_at_pos(Clutter.PickMode.ALL,
|
|
|
|
stageX,
|
|
|
|
stageY);
|
2010-06-11 17:45:43 +00:00
|
|
|
let position = '[inspect x: ' + stageX + ' y: ' + stageY + ']';
|
|
|
|
displayText.text = '';
|
2010-06-17 17:19:07 +00:00
|
|
|
displayText.text = position + ' ' + target;
|
2009-08-04 13:49:03 +00:00
|
|
|
if (borderPaintTarget != null)
|
|
|
|
borderPaintTarget.disconnect(borderPaintId);
|
|
|
|
borderPaintTarget = target;
|
|
|
|
borderPaintId = Shell.add_hook_paint_red_border(target);
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
Clutter.grab_pointer(eventHandler);
|
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2009-08-04 13:49:03 +00:00
|
|
|
|
|
|
|
Signals.addSignalMethods(Inspector.prototype);
|
|
|
|
|
2009-10-24 17:36:52 +00:00
|
|
|
function ErrorLog() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorLog.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new St.BoxLayout();
|
|
|
|
this.text = new St.Label();
|
|
|
|
this.actor.add(this.text);
|
2010-06-03 16:47:15 +00:00
|
|
|
// We need to override StLabel's default ellipsization when
|
|
|
|
// using line_wrap; otherwise ClutterText's layout is going
|
|
|
|
// to constrain both the width and height, which prevents
|
|
|
|
// scrolling.
|
|
|
|
this.text.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
2009-10-24 17:36:52 +00:00
|
|
|
this.text.clutter_text.line_wrap = true;
|
2009-12-03 17:19:38 +00:00
|
|
|
this.actor.connect('notify::mapped', Lang.bind(this, this._renderText));
|
2009-10-24 17:36:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_formatTime: function(d){
|
2010-03-15 13:50:05 +00:00
|
|
|
function pad(n) { return n < 10 ? '0' + n : n; }
|
2009-10-24 17:36:52 +00:00
|
|
|
return d.getUTCFullYear()+'-'
|
|
|
|
+ pad(d.getUTCMonth()+1)+'-'
|
|
|
|
+ pad(d.getUTCDate())+'T'
|
|
|
|
+ pad(d.getUTCHours())+':'
|
|
|
|
+ pad(d.getUTCMinutes())+':'
|
2010-03-15 13:50:05 +00:00
|
|
|
+ pad(d.getUTCSeconds())+'Z';
|
2009-10-24 17:36:52 +00:00
|
|
|
},
|
|
|
|
|
2009-12-03 17:19:38 +00:00
|
|
|
_renderText: function() {
|
|
|
|
if (!this.actor.mapped)
|
2009-10-24 17:36:52 +00:00
|
|
|
return;
|
|
|
|
let text = this.text.text;
|
|
|
|
let stack = Main._getAndClearErrorStack();
|
|
|
|
for (let i = 0; i < stack.length; i++) {
|
|
|
|
let logItem = stack[i];
|
2010-05-13 19:46:04 +00:00
|
|
|
text += logItem.category + ' t=' + this._formatTime(new Date(logItem.timestamp)) + ' ' + logItem.message + '\n';
|
2009-10-24 17:36:52 +00:00
|
|
|
}
|
|
|
|
this.text.text = text;
|
|
|
|
}
|
2010-03-15 13:50:05 +00:00
|
|
|
};
|
2009-10-24 17:36:52 +00:00
|
|
|
|
2009-10-28 22:05:34 +00:00
|
|
|
function Extensions() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Extensions.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new St.BoxLayout({ vertical: true,
|
|
|
|
name: 'lookingGlassExtensions' });
|
|
|
|
this._noExtensions = new St.Label({ style_class: 'lg-extensions-none',
|
|
|
|
text: _("No extensions installed") });
|
|
|
|
this._extensionsList = new St.BoxLayout({ vertical: true,
|
|
|
|
style_class: 'lg-extensions-list' });
|
|
|
|
this.actor.add(this._extensionsList);
|
|
|
|
this._loadExtensionList();
|
|
|
|
},
|
|
|
|
|
|
|
|
_loadExtensionList: function() {
|
|
|
|
let extensions = ExtensionSystem.extensionMeta;
|
|
|
|
let totalExtensions = 0;
|
|
|
|
for (let uuid in extensions) {
|
|
|
|
let extensionDisplay = this._createExtensionDisplay(extensions[uuid]);
|
|
|
|
this._extensionsList.add(extensionDisplay);
|
|
|
|
totalExtensions++;
|
|
|
|
}
|
|
|
|
if (totalExtensions == 0) {
|
|
|
|
this._extensionsList.add(this._noExtensions);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onViewSource: function (actor) {
|
|
|
|
let meta = actor._extensionMeta;
|
|
|
|
let file = Gio.file_new_for_path(meta.path);
|
|
|
|
let uri = file.get_uri();
|
|
|
|
Gio.app_info_launch_default_for_uri(uri, global.create_app_launch_context());
|
|
|
|
Main.lookingGlass.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onWebPage: function (actor) {
|
|
|
|
let meta = actor._extensionMeta;
|
|
|
|
Gio.app_info_launch_default_for_uri(meta.url, global.create_app_launch_context());
|
|
|
|
Main.lookingGlass.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
_stateToString: function(extensionState) {
|
|
|
|
switch (extensionState) {
|
|
|
|
case ExtensionSystem.ExtensionState.ENABLED:
|
|
|
|
return _("Enabled");
|
|
|
|
case ExtensionSystem.ExtensionState.DISABLED:
|
|
|
|
return _("Disabled");
|
|
|
|
case ExtensionSystem.ExtensionState.ERROR:
|
|
|
|
return _("Error");
|
|
|
|
case ExtensionSystem.ExtensionState.OUT_OF_DATE:
|
|
|
|
return _("Out of date");
|
|
|
|
}
|
2010-05-13 19:46:04 +00:00
|
|
|
return 'Unknown'; // Not translated, shouldn't appear
|
2009-10-28 22:05:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_createExtensionDisplay: function(meta) {
|
|
|
|
let box = new St.BoxLayout({ style_class: 'lg-extension', vertical: true });
|
|
|
|
let name = new St.Label({ style_class: 'lg-extension-name',
|
|
|
|
text: meta.name });
|
|
|
|
box.add(name, { expand: true });
|
|
|
|
let description = new St.Label({ style_class: 'lg-extension-description',
|
|
|
|
text: meta.description });
|
|
|
|
box.add(description, { expand: true });
|
|
|
|
|
|
|
|
let metaBox = new St.BoxLayout();
|
|
|
|
box.add(metaBox);
|
|
|
|
let stateString = this._stateToString(meta.state);
|
|
|
|
let state = new St.Label({ style_class: 'lg-extension-state',
|
|
|
|
text: this._stateToString(meta.state) });
|
|
|
|
|
|
|
|
let actionsContainer = new St.Bin({ x_align: St.Align.END });
|
|
|
|
metaBox.add(actionsContainer);
|
|
|
|
let actionsBox = new St.BoxLayout({ style_class: 'lg-extension-actions' });
|
|
|
|
actionsContainer.set_child(actionsBox);
|
|
|
|
|
|
|
|
let viewsource = new Link.Link({ label: _("View Source") });
|
|
|
|
viewsource.actor._extensionMeta = meta;
|
|
|
|
viewsource.actor.connect('clicked', Lang.bind(this, this._onViewSource));
|
|
|
|
actionsBox.add(viewsource.actor);
|
|
|
|
|
|
|
|
if (meta.url) {
|
|
|
|
let webpage = new Link.Link({ label: _("Web Page") });
|
|
|
|
webpage.actor._extensionMeta = meta;
|
|
|
|
webpage.actor.connect('clicked', Lang.bind(this, this._onWebPage));
|
|
|
|
actionsBox.add(webpage.actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
function LookingGlass() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
LookingGlass.prototype = {
|
|
|
|
_init : function() {
|
|
|
|
this._idleHistorySaveId = 0;
|
2010-05-13 19:46:04 +00:00
|
|
|
let historyPath = global.userdatadir + '/lookingglass-history.txt';
|
2009-08-02 07:46:01 +00:00
|
|
|
this._historyFile = Gio.file_new_for_path(historyPath);
|
|
|
|
this._savedText = null;
|
|
|
|
this._historyNavIndex = -1;
|
|
|
|
this._history = [];
|
2009-11-11 18:12:55 +00:00
|
|
|
this._borderPaintTarget = null;
|
|
|
|
this._borderPaintId = 0;
|
|
|
|
this._borderDestroyId = 0;
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this._readHistory();
|
|
|
|
|
|
|
|
this._open = false;
|
|
|
|
|
|
|
|
this._offset = 0;
|
|
|
|
this._results = [];
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
// Sort of magic, but...eh.
|
|
|
|
this._maxItems = 150;
|
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
this.actor = new St.BoxLayout({ name: 'LookingGlassDialog',
|
2010-05-15 16:43:56 +00:00
|
|
|
style_class: 'lg-dialog',
|
2009-09-10 05:38:13 +00:00
|
|
|
vertical: true,
|
|
|
|
visible: false });
|
2009-09-22 00:13:00 +00:00
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
let gconf = GConf.Client.get_default();
|
|
|
|
gconf.add_dir('/desktop/gnome/interface', GConf.ClientPreloadType.PRELOAD_NONE);
|
|
|
|
gconf.notify_add('/desktop/gnome/interface/monospace_font_name',
|
|
|
|
Lang.bind(this, this._updateFont));
|
2009-09-22 00:13:00 +00:00
|
|
|
this._updateFont();
|
|
|
|
|
2010-05-06 21:18:10 +00:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
this._objInspector = new ObjInspector();
|
|
|
|
Main.uiGroup.add_actor(this._objInspector.actor);
|
|
|
|
this._objInspector.actor.hide();
|
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
let toolbar = new St.BoxLayout({ name: 'Toolbar' });
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor.add_actor(toolbar);
|
2010-02-09 17:42:07 +00:00
|
|
|
let inspectIcon = St.TextureCache.get_default().load_gicon(new Gio.ThemedIcon({ name: 'gtk-color-picker' }),
|
|
|
|
24);
|
2009-09-10 05:38:13 +00:00
|
|
|
toolbar.add_actor(inspectIcon);
|
2009-08-02 07:46:01 +00:00
|
|
|
inspectIcon.reactive = true;
|
|
|
|
inspectIcon.connect('button-press-event', Lang.bind(this, function () {
|
2009-08-04 13:49:03 +00:00
|
|
|
let inspector = new Inspector();
|
|
|
|
inspector.connect('target', Lang.bind(this, function(i, target, stageX, stageY) {
|
2009-08-02 07:46:01 +00:00
|
|
|
this._pushResult('<inspect x:' + stageX + ' y:' + stageY + '>',
|
|
|
|
target);
|
2009-08-04 13:49:03 +00:00
|
|
|
}));
|
|
|
|
inspector.connect('closed', Lang.bind(this, function() {
|
2009-08-02 07:46:01 +00:00
|
|
|
this.actor.show();
|
|
|
|
global.stage.set_key_focus(this._entry);
|
|
|
|
}));
|
|
|
|
this.actor.hide();
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
|
2009-08-04 13:49:03 +00:00
|
|
|
let notebook = new Notebook();
|
2009-10-09 00:11:45 +00:00
|
|
|
this._notebook = notebook;
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor.add(notebook.actor, { expand: true });
|
|
|
|
|
|
|
|
let emptyBox = new St.Bin();
|
|
|
|
toolbar.add(emptyBox, { expand: true });
|
|
|
|
toolbar.add_actor(notebook.tabControls);
|
2009-08-04 13:49:03 +00:00
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
this._evalBox = new St.BoxLayout({ name: 'EvalBox', vertical: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.appendPage('Evaluator', this._evalBox);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
this._resultsArea = new St.BoxLayout({ name: 'ResultsArea', vertical: true });
|
2009-09-10 05:38:13 +00:00
|
|
|
this._evalBox.add(this._resultsArea, { expand: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
let entryArea = new St.BoxLayout({ name: 'EntryArea' });
|
2009-09-10 05:38:13 +00:00
|
|
|
this._evalBox.add_actor(entryArea);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
let label = new St.Label({ text: 'js>>> ' });
|
2010-03-31 20:40:32 +00:00
|
|
|
entryArea.add(label);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this._entry = new St.Entry();
|
2009-09-15 19:53:07 +00:00
|
|
|
/* unmapping the edit box will un-focus it, undo that */
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.connect('selection', Lang.bind(this, function (nb, child) {
|
|
|
|
if (child == this._evalBox)
|
|
|
|
global.stage.set_key_focus(this._entry);
|
|
|
|
}));
|
2010-03-31 20:40:32 +00:00
|
|
|
entryArea.add(this._entry, { expand: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2010-04-20 18:57:31 +00:00
|
|
|
this._windowList = new WindowList();
|
|
|
|
this._windowList.connect('selected', Lang.bind(this, function(list, window) {
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.selectIndex(0);
|
2010-04-20 18:57:31 +00:00
|
|
|
this._pushResult('<window selection>', window);
|
2009-08-02 07:46:01 +00:00
|
|
|
}));
|
2010-04-20 18:57:31 +00:00
|
|
|
notebook.appendPage('Windows', this._windowList.actor);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-10-24 17:36:52 +00:00
|
|
|
this._errorLog = new ErrorLog();
|
|
|
|
notebook.appendPage('Errors', this._errorLog.actor);
|
|
|
|
|
2009-10-28 22:05:34 +00:00
|
|
|
this._extensions = new Extensions();
|
|
|
|
notebook.appendPage('Extensions', this._extensions.actor);
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this._entry.clutter_text.connect('activate', Lang.bind(this, function (o, e) {
|
2009-08-02 07:46:01 +00:00
|
|
|
let text = o.get_text();
|
|
|
|
// Ensure we don't get newlines in the command; the history file is
|
|
|
|
// newline-separated.
|
|
|
|
text.replace('\n', ' ');
|
2009-08-04 05:37:54 +00:00
|
|
|
// Strip leading and trailing whitespace
|
2010-05-13 19:46:04 +00:00
|
|
|
text = text.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
2009-08-04 05:37:54 +00:00
|
|
|
if (text == '')
|
|
|
|
return true;
|
2009-08-02 07:46:01 +00:00
|
|
|
this._evaluate(text);
|
|
|
|
this._historyNavIndex = -1;
|
|
|
|
return true;
|
|
|
|
}));
|
2009-09-10 05:38:13 +00:00
|
|
|
this._entry.clutter_text.connect('key-press-event', Lang.bind(this, function(o, e) {
|
2009-09-08 20:58:57 +00:00
|
|
|
let symbol = e.get_key_symbol();
|
2009-12-18 20:22:58 +00:00
|
|
|
if (symbol == Clutter.Up) {
|
2009-08-02 07:46:01 +00:00
|
|
|
if (this._historyNavIndex >= this._history.length - 1)
|
|
|
|
return true;
|
|
|
|
this._historyNavIndex++;
|
|
|
|
if (this._historyNavIndex == 0)
|
|
|
|
this._savedText = this._entry.text;
|
|
|
|
this._entry.text = this._history[this._history.length - this._historyNavIndex - 1];
|
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.Down) {
|
|
|
|
if (this._historyNavIndex <= 0)
|
|
|
|
return true;
|
|
|
|
this._historyNavIndex--;
|
|
|
|
if (this._historyNavIndex < 0)
|
|
|
|
this._entry.text = this._savedText;
|
|
|
|
else
|
|
|
|
this._entry.text = this._history[this._history.length - this._historyNavIndex - 1];
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
this._historyNavIndex = -1;
|
|
|
|
this._savedText = null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2009-09-22 00:13:00 +00:00
|
|
|
_updateFont: function() {
|
2010-05-05 21:05:42 +00:00
|
|
|
let gconf = GConf.Client.get_default();
|
2010-05-13 19:46:04 +00:00
|
|
|
let fontName = gconf.get_string('/desktop/gnome/interface/monospace_font_name');
|
2009-09-22 00:13:00 +00:00
|
|
|
// This is mishandled by the scanner - should by Pango.FontDescription_from_string(fontName);
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=595889
|
|
|
|
let fontDesc = Pango.Font.description_from_string(fontName);
|
|
|
|
// We ignore everything but size and style; you'd be crazy to set your system-wide
|
|
|
|
// monospace font to be bold/oblique/etc. Could easily be added here.
|
|
|
|
this.actor.style =
|
|
|
|
'font-size: ' + fontDesc.get_size() / 1024. + (fontDesc.get_size_is_absolute() ? 'px' : 'pt') + ';'
|
|
|
|
+ 'font-family: "' + fontDesc.get_family() + '";';
|
|
|
|
},
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
_readHistory: function () {
|
|
|
|
if (!this._historyFile.query_exists(null))
|
|
|
|
return;
|
|
|
|
let [result, contents, length, etag] = this._historyFile.load_contents(null);
|
2009-08-04 05:37:54 +00:00
|
|
|
this._history = contents.split('\n').filter(function (e) { return e != ''; });
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_queueHistorySave: function() {
|
|
|
|
if (this._idleHistorySaveId > 0)
|
|
|
|
return;
|
2009-08-04 05:37:54 +00:00
|
|
|
this._idleHistorySaveId = Mainloop.timeout_add_seconds(5, Lang.bind(this, this._doSaveHistory));
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_doSaveHistory: function () {
|
|
|
|
this._idleHistorySaveId = false;
|
|
|
|
let output = this._historyFile.replace(null, true, Gio.FileCreateFlags.NONE, null);
|
|
|
|
let dataOut = new Gio.DataOutputStream({ base_stream: output });
|
|
|
|
dataOut.put_string(this._history.join('\n'), null);
|
|
|
|
dataOut.put_string('\n', null);
|
|
|
|
dataOut.close(null);
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_pushResult: function(command, obj) {
|
|
|
|
let index = this._results.length + this._offset;
|
|
|
|
let result = new Result('>>> ' + command, obj, index);
|
|
|
|
this._results.push(result);
|
2010-03-31 20:40:32 +00:00
|
|
|
this._resultsArea.add(result.actor);
|
2009-11-11 18:12:55 +00:00
|
|
|
if (this._borderPaintTarget != null) {
|
|
|
|
this._borderPaintTarget.disconnect(this._borderPaintId);
|
|
|
|
this._borderPaintTarget = null;
|
|
|
|
}
|
|
|
|
if (obj instanceof Clutter.Actor) {
|
|
|
|
this._borderPaintTarget = obj;
|
|
|
|
this._borderPaintId = Shell.add_hook_paint_red_border(obj);
|
|
|
|
this._borderDestroyId = obj.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._borderDestroyId = 0;
|
|
|
|
this._borderPaintTarget = null;
|
|
|
|
}));
|
|
|
|
}
|
2009-08-02 07:46:01 +00:00
|
|
|
let children = this._resultsArea.get_children();
|
|
|
|
if (children.length > this._maxItems) {
|
|
|
|
this._results.shift();
|
|
|
|
children[0].destroy();
|
|
|
|
this._offset++;
|
|
|
|
}
|
|
|
|
this._it = obj;
|
2009-10-09 00:11:45 +00:00
|
|
|
|
|
|
|
// Scroll to bottom
|
|
|
|
this._notebook.scrollToBottom(0);
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_evaluate : function(command) {
|
|
|
|
this._history.push(command);
|
|
|
|
this._queueHistorySave();
|
|
|
|
|
|
|
|
let fullCmd = commandHeader + command;
|
|
|
|
|
|
|
|
let resultObj;
|
|
|
|
try {
|
|
|
|
resultObj = eval(fullCmd);
|
|
|
|
} catch (e) {
|
2010-05-13 19:46:04 +00:00
|
|
|
resultObj = '<exception ' + e + '>';
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._pushResult(command, resultObj);
|
|
|
|
this._entry.text = '';
|
|
|
|
},
|
|
|
|
|
|
|
|
getIt: function () {
|
|
|
|
return this._it;
|
|
|
|
},
|
|
|
|
|
|
|
|
getResult: function(idx) {
|
|
|
|
return this._results[idx - this._offset].o;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
if (this._open)
|
|
|
|
this.close();
|
|
|
|
else
|
|
|
|
this.open();
|
|
|
|
},
|
|
|
|
|
|
|
|
_resizeTo: function(actor) {
|
2009-08-25 19:23:53 +00:00
|
|
|
let primary = global.get_primary_monitor();
|
|
|
|
let myWidth = primary.width * 0.7;
|
|
|
|
let myHeight = primary.height * 0.7;
|
2009-08-02 07:46:01 +00:00
|
|
|
let [srcX, srcY] = actor.get_transformed_position();
|
2009-08-25 19:23:53 +00:00
|
|
|
this.actor.x = srcX + (primary.width - myWidth) / 2;
|
2009-08-02 07:46:01 +00:00
|
|
|
this._hiddenY = srcY + actor.height - myHeight - 4; // -4 to hide the top corners
|
|
|
|
this._targetY = this._hiddenY + myHeight;
|
|
|
|
this.actor.y = this._hiddenY;
|
|
|
|
this.actor.width = myWidth;
|
|
|
|
this.actor.height = myHeight;
|
2010-05-15 16:43:56 +00:00
|
|
|
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));
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
slaveTo: function(actor) {
|
|
|
|
this._slaveTo = actor;
|
|
|
|
actor.connect('notify::allocation', Lang.bind(this, function () {
|
|
|
|
this._resizeTo(actor);
|
|
|
|
}));
|
|
|
|
this._resizeTo(actor);
|
|
|
|
},
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
insertObject: function(obj) {
|
|
|
|
this._pushResult('<insert>', obj);
|
|
|
|
},
|
|
|
|
|
|
|
|
inspectObject: function(obj, sourceActor) {
|
|
|
|
this._objInspector.open(sourceActor);
|
|
|
|
this._objInspector.selectObject(obj);
|
|
|
|
},
|
|
|
|
|
2009-12-18 20:22:58 +00:00
|
|
|
// Handle key events which are relevant for all tabs of the LookingGlass
|
|
|
|
_globalKeyPressEvent : function(actor, event) {
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol == Clutter.Escape) {
|
2010-05-15 16:43:56 +00:00
|
|
|
if (this._objInspector.actor.visible) {
|
|
|
|
this._objInspector.close();
|
|
|
|
} else {
|
|
|
|
this.close();
|
|
|
|
}
|
2009-12-18 20:22:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
open : function() {
|
|
|
|
if (this._open)
|
|
|
|
return;
|
|
|
|
|
2009-09-16 15:37:51 +00:00
|
|
|
if (!Main.pushModal(this.actor))
|
|
|
|
return;
|
|
|
|
|
2009-12-18 20:22:58 +00:00
|
|
|
this._keyPressEventId = global.stage.connect('key-press-event',
|
|
|
|
Lang.bind(this, this._globalKeyPressEvent));
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this.actor.show();
|
|
|
|
this.actor.lower(Main.chrome.actor);
|
|
|
|
this._open = true;
|
|
|
|
|
|
|
|
Tweener.removeTweens(this.actor);
|
|
|
|
|
|
|
|
global.stage.set_key_focus(this._entry);
|
|
|
|
|
|
|
|
Tweener.addTween(this.actor, { time: 0.5,
|
2010-05-13 19:46:04 +00:00
|
|
|
transition: 'easeOutQuad',
|
2009-08-02 07:46:01 +00:00
|
|
|
y: this._targetY
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
close : function() {
|
|
|
|
if (!this._open)
|
|
|
|
return;
|
|
|
|
|
2009-12-18 20:22:58 +00:00
|
|
|
if (this._keyPressEventId)
|
|
|
|
global.stage.disconnect(this._keyPressEventId);
|
|
|
|
|
2010-05-15 16:43:56 +00:00
|
|
|
this._objInspector.actor.hide();
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this._historyNavIndex = -1;
|
|
|
|
this._open = false;
|
|
|
|
Tweener.removeTweens(this.actor);
|
|
|
|
|
2009-11-11 18:12:55 +00:00
|
|
|
if (this._borderPaintTarget != null) {
|
|
|
|
this._borderPaintTarget.disconnect(this._borderPaintId);
|
|
|
|
this._borderPaintTarget.disconnect(this._borderDestroyId);
|
|
|
|
this._borderPaintTarget = null;
|
|
|
|
}
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
Main.popModal(this.actor);
|
2009-08-02 07:46:01 +00:00
|
|
|
|
|
|
|
Tweener.addTween(this.actor, { time: 0.5,
|
2010-05-13 19:46:04 +00:00
|
|
|
transition: 'easeOutQuad',
|
2009-08-02 07:46:01 +00:00
|
|
|
y: this._hiddenY,
|
|
|
|
onComplete: Lang.bind(this, function () {
|
|
|
|
this.actor.hide();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(LookingGlass.prototype);
|