2008-12-01 19:51:43 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-19 23:21:42 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
2008-11-19 23:21:42 +00: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 19:51:43 +00:00
|
|
|
_init : function() {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
let box = new Clutter.Rectangle({ color: BOX_BACKGROUND_COLOR,
|
|
|
|
reactive: false,
|
|
|
|
width: BOX_WIDTH,
|
|
|
|
height: BOX_HEIGHT,
|
|
|
|
border_width: 0 });
|
|
|
|
boxGroup.add_actor(box);
|
|
|
|
|
2009-02-23 19:42:00 +00:00
|
|
|
let label = new Clutter.Text({ color: BOX_TEXT_COLOR,
|
|
|
|
font_name: '18px Sans',
|
|
|
|
text: 'Please enter a command:' });
|
2008-12-01 19:51:43 +00:00
|
|
|
label.set_position(6, 6);
|
|
|
|
boxGroup.add_actor(label);
|
|
|
|
|
2009-02-23 19:42:00 +00: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 19:51:43 +00:00
|
|
|
// TODO: Implement relative positioning using Tidy.
|
|
|
|
this._entry.set_position(6, 30);
|
|
|
|
boxGroup.add_actor(this._entry);
|
|
|
|
|
|
|
|
let me = this;
|
|
|
|
|
|
|
|
this._entry.connect('activate', function (o, e) {
|
|
|
|
me.hide();
|
|
|
|
me._run(o.get_text());
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_run : function(command) {
|
2008-12-18 20:57:37 +00:00
|
|
|
if (command == 'restart') {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
global.reexec_self();
|
|
|
|
} else if (command) {
|
2008-12-01 19:51:43 +00:00
|
|
|
var p = new Shell.Process({'args' : [command]});
|
|
|
|
try {
|
|
|
|
p.run();
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: Give the user direct feedback.
|
|
|
|
log('Could not run command ' + command + '.');
|
|
|
|
}
|
2008-11-19 23:21:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this.emit('run');
|
|
|
|
},
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
show : function() {
|
|
|
|
let me = this;
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
if (this._group.visible) // Already shown
|
|
|
|
return false;
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
if (!Main.startModal())
|
2008-11-28 20:48:38 +00:00
|
|
|
return false;
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group.show_all();
|
|
|
|
|
|
|
|
this._entry.connect('key-press-event', function(o, e) {
|
2009-02-23 19:42:00 +00:00
|
|
|
if (Shell.get_event_key_symbol(e) == Clutter.Escape) {
|
2008-12-01 19:51:43 +00:00
|
|
|
me.hide();
|
|
|
|
me.emit('cancel');
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
});
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
global.stage.set_key_focus(this._entry);
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
return true;
|
|
|
|
},
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
hide : function() {
|
|
|
|
if (!this._group.visible)
|
|
|
|
return;
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group.hide();
|
|
|
|
Main.endModal();
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy : function(){
|
|
|
|
this.hide();
|
|
|
|
this._group.destroy();
|
|
|
|
}
|
2008-11-19 23:21:42 +00:00
|
|
|
};
|
2008-11-20 15:40:44 +00:00
|
|
|
Signals.addSignalMethods(RunDialog.prototype);
|