2008-12-01 14:51:43 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-19 18:21:42 -05:00
|
|
|
|
2009-08-01 21:46:02 -04:00
|
|
|
const Big = imports.gi.Big;
|
2008-11-19 18:21:42 -05:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-08-10 15:49:25 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2009-08-03 17:52:45 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2009-09-15 17:40:26 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
2009-08-14 09:30:48 -04:00
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
2008-11-19 18:21:42 -05:00
|
|
|
|
2009-09-22 15:24:14 -04:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
2008-11-19 18:21:42 -05:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const BOX_BACKGROUND_COLOR = new Clutter.Color();
|
|
|
|
BOX_BACKGROUND_COLOR.from_pixel(0x000000cc);
|
|
|
|
|
|
|
|
const BOX_TEXT_COLOR = new Clutter.Color();
|
|
|
|
BOX_TEXT_COLOR.from_pixel(0xffffffff);
|
|
|
|
|
2009-09-08 14:04:18 -04:00
|
|
|
const DIALOG_WIDTH = 320;
|
|
|
|
const DIALOG_PADDING = 6;
|
|
|
|
const ICON_SIZE = 24;
|
|
|
|
const ICON_BOX_SIZE = 36;
|
2008-11-19 18:21:42 -05:00
|
|
|
|
|
|
|
function RunDialog() {
|
|
|
|
this._init();
|
|
|
|
};
|
|
|
|
|
|
|
|
RunDialog.prototype = {
|
2008-12-01 14:51:43 -05:00
|
|
|
_init : function() {
|
2009-08-03 17:52:45 -04:00
|
|
|
this._isOpen = false;
|
|
|
|
|
2009-09-14 13:45:49 -04:00
|
|
|
let gconf = Shell.GConf.get_default();
|
2009-09-25 14:10:45 -04:00
|
|
|
gconf.connect('changed::development_tools', Lang.bind(this, function () {
|
|
|
|
this._enableInternalCommands = gconf.get_boolean('development_tools');
|
2009-09-14 13:45:49 -04:00
|
|
|
}));
|
|
|
|
this._enableInternalCommands = gconf.get_boolean('development_tools');
|
|
|
|
|
2009-08-02 03:46:01 -04:00
|
|
|
this._internalCommands = { 'lg':
|
|
|
|
Lang.bind(this, function() {
|
2009-09-15 15:53:07 -04:00
|
|
|
Main.createLookingGlass().open();
|
2009-08-02 03:46:01 -04:00
|
|
|
}),
|
2009-08-26 18:43:44 -04:00
|
|
|
|
|
|
|
'r': Lang.bind(this, function() {
|
|
|
|
global.reexec_self();
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Developer brain backwards compatibility
|
2009-08-02 03:46:01 -04:00
|
|
|
'restart': Lang.bind(this, function() {
|
2009-08-03 17:52:45 -04:00
|
|
|
global.reexec_self();
|
2009-09-15 17:40:26 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
'debugexit': Lang.bind(this, function() {
|
|
|
|
Meta.exit(Meta.ExitCode.ERROR);
|
2009-08-03 17:52:45 -04:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
// All actors are inside _group. We create it initially
|
|
|
|
// hidden then show it in show()
|
2009-08-25 15:23:53 -04:00
|
|
|
this._group = new Clutter.Group({ visible: false,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height });
|
2008-12-01 14:51:43 -05:00
|
|
|
global.stage.add_actor(this._group);
|
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
let lightbox = new Lightbox.Lightbox(this._group);
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
this._boxH = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
|
|
|
x_align: Big.BoxAlignment.CENTER,
|
|
|
|
y_align: Big.BoxAlignment.CENTER });
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
this._group.add_actor(this._boxH);
|
|
|
|
lightbox.highlight(this._boxH);
|
2009-09-08 14:04:18 -04:00
|
|
|
|
|
|
|
let boxV = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
y_align: Big.BoxAlignment.CENTER });
|
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
this._boxH.append(boxV, Big.BoxPackFlags.NONE);
|
2009-09-08 14:04:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
let dialogBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
background_color: BOX_BACKGROUND_COLOR,
|
|
|
|
corner_radius: 4,
|
|
|
|
reactive: false,
|
|
|
|
padding: DIALOG_PADDING,
|
|
|
|
width: DIALOG_WIDTH });
|
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
this._boxH.append(dialogBox, Big.BoxPackFlags.NONE);
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-02-23 14:42:00 -05:00
|
|
|
let label = new Clutter.Text({ color: BOX_TEXT_COLOR,
|
|
|
|
font_name: '18px Sans',
|
2009-08-14 09:30:48 -04:00
|
|
|
text: _("Please enter a command:") });
|
2009-09-08 14:04:18 -04:00
|
|
|
|
|
|
|
dialogBox.append(label, Big.BoxPackFlags.EXPAND);
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-02-23 14:42:00 -05:00
|
|
|
this._entry = new Clutter.Text({ color: BOX_TEXT_COLOR,
|
|
|
|
font_name: '20px Sans Bold',
|
|
|
|
editable: true,
|
|
|
|
activatable: true,
|
2009-09-08 14:04:18 -04:00
|
|
|
singleLineMode: true });
|
|
|
|
|
|
|
|
dialogBox.append(this._entry, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
this._errorBox = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
|
|
|
padding_top: DIALOG_PADDING });
|
|
|
|
|
|
|
|
dialogBox.append(this._errorBox, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
let iconBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
y_align: Big.BoxAlignment.CENTER,
|
|
|
|
x_align: Big.BoxAlignment.CENTER,
|
|
|
|
width: ICON_BOX_SIZE,
|
|
|
|
height: ICON_BOX_SIZE });
|
|
|
|
|
|
|
|
this._errorBox.append(iconBox, Big.BoxPackFlags.NONE);
|
|
|
|
|
|
|
|
this._commandError = false;
|
|
|
|
|
|
|
|
let errorIcon = Shell.TextureCache.get_default().load_icon_name("gtk-dialog-error", ICON_SIZE);
|
|
|
|
iconBox.append(errorIcon, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
this._errorMessage = new Clutter.Text({ color: BOX_TEXT_COLOR,
|
|
|
|
font_name: '18px Sans Bold',
|
|
|
|
line_wrap: true });
|
|
|
|
|
|
|
|
this._errorBox.append(this._errorMessage, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
this._errorBox.hide();
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._entry.connect('activate', Lang.bind(this, function (o, e) {
|
|
|
|
this._run(o.get_text());
|
2009-09-08 14:04:18 -04:00
|
|
|
if (!this._commandError)
|
|
|
|
this.close();
|
2009-08-03 17:52:45 -04:00
|
|
|
}));
|
2009-09-08 14:04:18 -04:00
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._entry.connect('key-press-event', Lang.bind(this, function(o, e) {
|
2009-09-08 16:58:57 -04:00
|
|
|
let symbol = e.get_key_symbol();
|
2009-08-03 17:52:45 -04:00
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_run : function(command) {
|
2009-10-01 17:44:16 -04:00
|
|
|
this._commandError = false;
|
2009-09-14 13:45:49 -04:00
|
|
|
let f;
|
|
|
|
if (this._enableInternalCommands)
|
|
|
|
f = this._internalCommands[command];
|
|
|
|
else
|
|
|
|
f = null;
|
2009-08-03 17:52:45 -04:00
|
|
|
if (f) {
|
|
|
|
f();
|
2008-12-18 15:57:37 -05:00
|
|
|
} else if (command) {
|
2008-12-01 14:51:43 -05:00
|
|
|
try {
|
2009-08-10 15:49:25 -04:00
|
|
|
let [ok, len, args] = GLib.shell_parse_argv(command);
|
|
|
|
let p = new Shell.Process({'args' : args});
|
2008-12-01 14:51:43 -05:00
|
|
|
p.run();
|
|
|
|
} catch (e) {
|
2009-09-08 14:04:18 -04:00
|
|
|
this._commandError = true;
|
|
|
|
/*
|
|
|
|
* The exception contains an error string like:
|
|
|
|
* Error invoking Shell.run: Failed to execute child process "foo"
|
|
|
|
* (No such file or directory)
|
|
|
|
* We are only interested in the actual error, so parse that out.
|
|
|
|
*/
|
|
|
|
let m = /.+\((.+)\)/.exec(e);
|
|
|
|
let errorStr = "Execution of '" + command + "' failed:\n" + m[1];
|
|
|
|
this._errorMessage.set_text(errorStr);
|
|
|
|
this._errorBox.show();
|
2008-12-01 14:51:43 -05:00
|
|
|
}
|
2008-11-19 18:21:42 -05:00
|
|
|
}
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
2008-11-19 18:21:42 -05:00
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
open : function() {
|
|
|
|
if (this._isOpen) // Already shown
|
|
|
|
return;
|
2008-11-24 14:07:18 -05:00
|
|
|
|
2009-09-16 11:37:51 -04:00
|
|
|
if (!Main.pushModal(this._group))
|
|
|
|
return;
|
|
|
|
|
2009-08-25 15:23:53 -04:00
|
|
|
// Position the dialog on the current monitor
|
|
|
|
let monitor = global.get_focus_monitor();
|
|
|
|
|
|
|
|
this._boxH.set_position(monitor.x, monitor.y);
|
|
|
|
this._boxH.set_size(monitor.width, monitor.height);
|
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._isOpen = true;
|
|
|
|
this._group.show();
|
2008-11-24 14:07:18 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
global.stage.set_key_focus(this._entry);
|
|
|
|
},
|
2008-11-24 14:07:18 -05:00
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
close : function() {
|
|
|
|
if (!this._isOpen)
|
2008-12-01 14:51:43 -05:00
|
|
|
return;
|
2008-11-19 18:21:42 -05:00
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._isOpen = false;
|
|
|
|
|
2009-09-08 14:04:18 -04:00
|
|
|
this._errorBox.hide();
|
|
|
|
this._commandError = false;
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
this._group.hide();
|
2009-08-05 20:04:04 -04:00
|
|
|
this._entry.text = '';
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-09-15 15:53:07 -04:00
|
|
|
Main.popModal(this._group);
|
2008-12-01 14:51:43 -05:00
|
|
|
}
|
2008-11-19 18:21:42 -05:00
|
|
|
};
|
2008-11-20 10:40:44 -05:00
|
|
|
Signals.addSignalMethods(RunDialog.prototype);
|