2009-08-02 07:46:01 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Big = imports.gi.Big;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 */
|
2009-08-02 07:46:01 +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; " +
|
|
|
|
/* Utility functions...we should probably be able to use these
|
|
|
|
* in the shell core code too. */
|
|
|
|
"const stage = global.stage; " +
|
|
|
|
"const color = function(pixel) { let c= new Clutter.Color(); c.from_pixel(pixel); return c; }; " +
|
|
|
|
/* Special lookingGlass functions */
|
2009-08-04 13:49:03 +00:00
|
|
|
"const it = Main.lookingGlass.getIt(); " +
|
2009-08-02 07:46:01 +00:00
|
|
|
"const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); ";
|
|
|
|
|
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
|
|
|
|
|
|
|
this.tabControls = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
|
|
|
spacing: 4, padding: 2 });
|
|
|
|
|
|
|
|
this._selectedIndex = -1;
|
|
|
|
this._tabs = [];
|
|
|
|
},
|
|
|
|
|
|
|
|
appendPage: function(name, child) {
|
|
|
|
let labelOuterBox = new Big.Box({ padding: 2 });
|
2009-09-10 05:38:13 +00:00
|
|
|
let labelBox = new St.BoxLayout({ reactive: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
labelOuterBox.append(labelBox, Big.BoxPackFlags.NONE);
|
2009-09-10 05:38:13 +00:00
|
|
|
let label = new St.Label({ text: name });
|
2009-08-04 13:49:03 +00:00
|
|
|
labelBox.connect('button-press-event', Lang.bind(this, function () {
|
|
|
|
this.selectChild(child);
|
|
|
|
return true;
|
|
|
|
}));
|
2009-09-10 05:38:13 +00:00
|
|
|
labelBox.add(label, { expand: true });
|
2009-08-04 13:49:03 +00:00
|
|
|
this.tabControls.append(labelOuterBox, Big.BoxPackFlags.NONE);
|
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,
|
|
|
|
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];
|
|
|
|
tabData.labelBox.padding = 2;
|
|
|
|
tabData.labelBox.border = 0;
|
|
|
|
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];
|
|
|
|
tabData.labelBox.padding = 1;
|
|
|
|
tabData.labelBox.border = 1;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
Signals.addSignalMethods(Notebook.prototype);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
this.actor = new Big.Box();
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
let cmdTxt = new St.Label({ text: command });
|
|
|
|
cmdTxt.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this.actor.append(cmdTxt, Big.BoxPackFlags.NONE);
|
2009-09-10 05:38:13 +00:00
|
|
|
let resultTxt = new St.Label({ text: "r(" + index + ") = " + o });
|
|
|
|
resultTxt.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this.actor.append(resultTxt, Big.BoxPackFlags.NONE);
|
2009-09-10 05:38:13 +00:00
|
|
|
let line = new Clutter.Rectangle({ name: "Separator",
|
|
|
|
height: 1 });
|
|
|
|
let padBin = new St.Bin({ name: "Separator", x_fill: true, y_fill: true });
|
|
|
|
padBin.add_actor(line);
|
|
|
|
this.actor.append(padBin, Big.BoxPackFlags.NONE);
|
2009-08-02 07:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ActorHierarchy() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorHierarchy.prototype = {
|
|
|
|
_init : function () {
|
|
|
|
this._previousTarget = null;
|
|
|
|
this._target = null;
|
|
|
|
|
|
|
|
this._parentList = [];
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor = new St.BoxLayout({ name: "ActorHierarchy", vertical: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setTarget: function(actor) {
|
|
|
|
this._previousTarget = this._target;
|
|
|
|
this.target = actor;
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor.get_children().forEach(function (child) { child.destroy(); });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
2009-08-04 13:49:03 +00:00
|
|
|
if (!(actor instanceof Clutter.Actor))
|
|
|
|
return;
|
2009-08-02 07:46:01 +00:00
|
|
|
|
|
|
|
if (this.target == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._parentList = [];
|
|
|
|
let parent = actor;
|
|
|
|
while ((parent = parent.get_parent()) != null) {
|
|
|
|
this._parentList.push(parent);
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
let link = new St.Label({ reactive: true,
|
|
|
|
text: "" + parent });
|
|
|
|
this.actor.add_actor(link);
|
2009-08-02 07:46:01 +00:00
|
|
|
let parentTarget = parent;
|
|
|
|
link.connect('button-press-event', Lang.bind(this, function () {
|
|
|
|
this._selectByActor(parentTarget);
|
2009-08-04 05:37:54 +00:00
|
|
|
return true;
|
2009-08-02 07:46:01 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
this.emit('selection', actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_selectByActor: function(actor) {
|
|
|
|
let idx = this._parentList.indexOf(actor);
|
|
|
|
let children = this.actor.get_children();
|
|
|
|
let link = children[idx];
|
|
|
|
this.emit('selection', actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Signals.addSignalMethods(ActorHierarchy.prototype);
|
|
|
|
|
|
|
|
function PropertyInspector() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInspector.prototype = {
|
|
|
|
_init : function () {
|
|
|
|
this._target = null;
|
|
|
|
|
|
|
|
this._parentList = [];
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor = new St.BoxLayout({ name: "PropertyInspector", vertical: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setTarget: function(actor) {
|
|
|
|
this.target = actor;
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
this.actor.get_children().forEach(function (child) { child.destroy(); });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
|
|
|
for (let propName in actor) {
|
|
|
|
let valueStr;
|
|
|
|
try {
|
|
|
|
valueStr = "" + actor[propName];
|
|
|
|
} catch (e) {
|
|
|
|
valueStr = '<error>';
|
|
|
|
}
|
|
|
|
let propText = propName + ": " + valueStr;
|
2009-09-10 05:38:13 +00:00
|
|
|
let propDisplay = new St.Label({ reactive: true,
|
|
|
|
text: propText });
|
|
|
|
this.actor.add_actor(propDisplay);
|
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();
|
2009-09-10 05:38:13 +00:00
|
|
|
let eventHandler = new St.BoxLayout({ name: "LookingGlassDialog",
|
|
|
|
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
|
|
|
}));
|
|
|
|
global.stage.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);
|
|
|
|
displayText.text = '<inspect x: ' + stageX + ' y: ' + stageY + '> ' + target;
|
|
|
|
if (borderPaintTarget != null)
|
|
|
|
borderPaintTarget.disconnect(borderPaintId);
|
|
|
|
borderPaintTarget = target;
|
|
|
|
borderPaintId = Shell.add_hook_paint_red_border(target);
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
Clutter.grab_pointer(eventHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Signals.addSignalMethods(Inspector.prototype);
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
function LookingGlass() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
LookingGlass.prototype = {
|
|
|
|
_init : function() {
|
|
|
|
this._idleHistorySaveId = 0;
|
2009-08-04 00:36:53 +00:00
|
|
|
let historyPath = global.configdir + "/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 = [];
|
|
|
|
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;
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ name: "LookingGlassDialog",
|
|
|
|
vertical: true,
|
|
|
|
visible: false });
|
2009-09-22 00:13:00 +00:00
|
|
|
|
|
|
|
let gconf = Shell.GConf.get_default();
|
|
|
|
gconf.watch_directory("/desktop/gnome/interface");
|
|
|
|
gconf.connect("changed::/desktop/gnome/interface/monospace_font_name",
|
|
|
|
Lang.bind(this, this._updateFont));
|
|
|
|
this._updateFont();
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
global.stage.add_actor(this.actor);
|
|
|
|
|
2009-09-10 05:38:13 +00:00
|
|
|
let toolbar = new St.BoxLayout({ name: "Toolbar" });
|
|
|
|
this.actor.add_actor(toolbar);
|
2009-08-02 07:46:01 +00:00
|
|
|
let inspectIcon = Shell.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);
|
|
|
|
this._hierarchy.setTarget(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
|
|
|
|
2009-09-10 05:38:13 +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
|
|
|
|
|
|
|
this._resultsArea = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
2009-08-04 00:21:07 +00:00
|
|
|
spacing: 4 });
|
2009-09-10 05:38:13 +00:00
|
|
|
this._evalBox.add(this._resultsArea, { expand: true });
|
2009-08-02 07:46:01 +00:00
|
|
|
|
|
|
|
let entryArea = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL });
|
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>>> ' });
|
2009-08-02 07:46:01 +00:00
|
|
|
entryArea.append(label, Big.BoxPackFlags.NONE);
|
|
|
|
|
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);
|
|
|
|
}));
|
2009-08-02 07:46:01 +00:00
|
|
|
entryArea.append(this._entry, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
this._hierarchy = new ActorHierarchy();
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.appendPage('Hierarchy', this._hierarchy.actor);
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this._propInspector = new PropertyInspector();
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.appendPage('Properties', this._propInspector.actor);
|
2009-08-04 05:37:54 +00:00
|
|
|
this._hierarchy.connect('selection', Lang.bind(this, function (h, actor) {
|
|
|
|
this._pushResult('<parent selection>', actor);
|
2009-08-04 13:49:03 +00:00
|
|
|
notebook.selectIndex(0);
|
2009-08-02 07:46:01 +00:00
|
|
|
}));
|
|
|
|
|
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
|
|
|
|
text = text.replace(/^\s+/g, "").replace(/\s+$/g, "");
|
|
|
|
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-08-02 07:46:01 +00:00
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.Up) {
|
|
|
|
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() {
|
|
|
|
let gconf = Shell.GConf.get_default();
|
|
|
|
let fontName = gconf.get_string("/desktop/gnome/interface/monospace_font_name");
|
|
|
|
// 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);
|
|
|
|
this._resultsArea.append(result.actor, Big.BoxPackFlags.NONE);
|
|
|
|
this._propInspector.setTarget(obj);
|
|
|
|
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) {
|
|
|
|
resultObj = "<exception " + e + ">";
|
|
|
|
}
|
|
|
|
|
|
|
|
this._pushResult(command, resultObj);
|
|
|
|
this._hierarchy.setTarget(null);
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
slaveTo: function(actor) {
|
|
|
|
this._slaveTo = actor;
|
|
|
|
actor.connect('notify::allocation', Lang.bind(this, function () {
|
|
|
|
this._resizeTo(actor);
|
|
|
|
}));
|
|
|
|
this._resizeTo(actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
open : function() {
|
|
|
|
if (this._open)
|
|
|
|
return;
|
|
|
|
|
2009-09-16 15:37:51 +00:00
|
|
|
if (!Main.pushModal(this.actor))
|
|
|
|
return;
|
|
|
|
|
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,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
y: this._targetY
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
close : function() {
|
|
|
|
if (!this._open)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._historyNavIndex = -1;
|
|
|
|
this._open = false;
|
|
|
|
Tweener.removeTweens(this.actor);
|
|
|
|
|
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,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
y: this._hiddenY,
|
|
|
|
onComplete: Lang.bind(this, function () {
|
|
|
|
this.actor.hide();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(LookingGlass.prototype);
|