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-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
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const OVERLAY_COLOR = new Clutter.Color();
|
|
|
|
OVERLAY_COLOR.from_pixel(0x00000044);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const BOX_WIDTH = 320;
|
|
|
|
const BOX_HEIGHT = 56;
|
|
|
|
|
|
|
|
function RunDialog() {
|
|
|
|
this._init();
|
|
|
|
};
|
|
|
|
|
|
|
|
RunDialog.prototype = {
|
2008-12-01 14:51:43 -05:00
|
|
|
_init : function() {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._isOpen = false;
|
|
|
|
|
2009-08-02 03:46:01 -04:00
|
|
|
this._internalCommands = { 'lg':
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Mainloop.idle_add(function() { Main.createLookingGlass().open(); });
|
|
|
|
}),
|
|
|
|
|
|
|
|
'restart': Lang.bind(this, function() {
|
2009-08-03 17:52:45 -04:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
global.reexec_self();
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
// All actors are inside _group. We create it initially
|
|
|
|
// hidden then show it in show()
|
|
|
|
this._group = new Clutter.Group({ visible: false });
|
|
|
|
global.stage.add_actor(this._group);
|
|
|
|
|
|
|
|
this._overlay = new Clutter.Rectangle({ color: OVERLAY_COLOR,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height,
|
|
|
|
border_width: 0,
|
|
|
|
reactive: true });
|
|
|
|
this._group.add_actor(this._overlay);
|
|
|
|
|
|
|
|
let boxGroup = new Clutter.Group();
|
|
|
|
boxGroup.set_position((global.screen_width - BOX_WIDTH) / 2,
|
|
|
|
(global.screen_height - BOX_HEIGHT) / 2);
|
|
|
|
this._group.add_actor(boxGroup);
|
|
|
|
|
2009-08-01 21:46:02 -04:00
|
|
|
let box = new Big.Box({ background_color: BOX_BACKGROUND_COLOR,
|
|
|
|
corner_radius: 4,
|
|
|
|
reactive: false,
|
|
|
|
width: BOX_WIDTH,
|
|
|
|
height: BOX_HEIGHT
|
|
|
|
});
|
2008-12-01 14:51:43 -05:00
|
|
|
boxGroup.add_actor(box);
|
|
|
|
|
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:") });
|
2008-12-01 14:51:43 -05:00
|
|
|
label.set_position(6, 6);
|
|
|
|
boxGroup.add_actor(label);
|
|
|
|
|
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,
|
|
|
|
singleLineMode: true,
|
|
|
|
text: '',
|
|
|
|
width: BOX_WIDTH - 12,
|
|
|
|
height: BOX_HEIGHT - 12 });
|
2008-12-01 14:51:43 -05:00
|
|
|
// TODO: Implement relative positioning using Tidy.
|
|
|
|
this._entry.set_position(6, 30);
|
|
|
|
boxGroup.add_actor(this._entry);
|
|
|
|
|
2009-08-03 17:52:45 -04:00
|
|
|
this._entry.connect('activate', Lang.bind(this, function (o, e) {
|
|
|
|
this._run(o.get_text());
|
|
|
|
this.close();
|
2008-12-01 14:51:43 -05:00
|
|
|
return false;
|
2009-08-03 17:52:45 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
this._entry.connect('key-press-event', Lang.bind(this, function(o, e) {
|
|
|
|
let symbol = Shell.get_event_key_symbol(e);
|
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_run : function(command) {
|
2009-08-03 17:52:45 -04:00
|
|
|
let f = this._internalCommands[command];
|
|
|
|
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) {
|
|
|
|
// TODO: Give the user direct feedback.
|
2009-08-10 15:49:25 -04:00
|
|
|
log('Could not run command ' + command + ': ' + e);
|
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
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
if (!Main.startModal())
|
2009-08-03 17:52:45 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._isOpen = true;
|
|
|
|
this._group.show();
|
2008-11-24 14:07:18 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
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;
|
|
|
|
|
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-08-03 17:52:45 -04:00
|
|
|
Main.endModal();
|
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);
|