Cleanups for runDialog

Using an internal boolean rather than the visibility property seems
more reliable to me.  Add a list of internal functions rather than
an if/else chain, so for example an extension could hook something on.

Delete the javascript evaluator in favor of the upcoming lookingGlass.js.
This commit is contained in:
Colin Walters 2009-08-03 17:52:45 -04:00
parent 45dc34bfa2
commit 224538c885
2 changed files with 41 additions and 62 deletions

View File

@ -51,17 +51,10 @@ function start() {
global.connect('panel-run-dialog', function(panel) {
// Make sure not more than one run dialog is shown.
if (!runDialog) {
if (runDialog == null) {
runDialog = new RunDialog.RunDialog();
let endHandler = function() {
runDialog.destroy();
runDialog = null;
};
runDialog.connect('run', endHandler);
runDialog.connect('cancel', endHandler);
if (!runDialog.show())
endHandler();
}
runDialog.open();
});
overlay = new Overlay.Overlay();

View File

@ -2,6 +2,8 @@
const Big = imports.gi.Big;
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell;
const Signals = imports.signals;
@ -27,6 +29,14 @@ RunDialog.prototype = {
_init : function() {
let global = Shell.Global.get();
this._isOpen = false;
this._internalCommands = { 'restart': Lang.bind(this, function() {
let global = Shell.Global.get();
global.reexec_self();
})
};
// All actors are inside _group. We create it initially
// hidden then show it in show()
this._group = new Clutter.Group({ visible: false });
@ -70,35 +80,27 @@ RunDialog.prototype = {
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());
this._entry.connect('activate', Lang.bind(this, function (o, e) {
this._run(o.get_text());
this._entry.text = '';
this.close();
return false;
});
}));
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;
}));
},
_run : function(command) {
if (command.slice(0, 3) == 'js ') {
let 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; ";
let cmd = commandHeader + command.substring(2);
try {
let result = eval(cmd);
log("" + result);
} catch (e) {
log(e);
}
} else if (command == 'restart') {
let global = Shell.Global.get();
global.reexec_self();
let f = this._internalCommands[command];
if (f) {
f();
} else if (command) {
var p = new Shell.Process({'args' : [command]});
try {
@ -108,47 +110,31 @@ RunDialog.prototype = {
log('Could not run command ' + command + '.');
}
}
this.emit('run');
},
show : function() {
let me = this;
if (this._group.visible) // Already shown
return false;
open : function() {
if (this._isOpen) // Already shown
return;
if (!Main.startModal())
return false;
this._group.show_all();
this._entry.connect('key-press-event', function(o, e) {
if (Shell.get_event_key_symbol(e) == Clutter.Escape) {
me.hide();
me.emit('cancel');
return true;
} else
return false;
});
return;
this._isOpen = true;
this._group.show();
let global = Shell.Global.get();
global.stage.set_key_focus(this._entry);
return true;
},
hide : function() {
if (!this._group.visible)
close : function() {
if (!this._isOpen)
return;
this._isOpen = false;
this._group.hide();
Main.endModal();
},
destroy : function(){
this.hide();
this._group.destroy();
Main.endModal();
}
};
Signals.addSignalMethods(RunDialog.prototype);