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:
parent
45dc34bfa2
commit
224538c885
@ -51,17 +51,10 @@ function start() {
|
|||||||
|
|
||||||
global.connect('panel-run-dialog', function(panel) {
|
global.connect('panel-run-dialog', function(panel) {
|
||||||
// Make sure not more than one run dialog is shown.
|
// Make sure not more than one run dialog is shown.
|
||||||
if (!runDialog) {
|
if (runDialog == null) {
|
||||||
runDialog = new RunDialog.RunDialog();
|
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();
|
overlay = new Overlay.Overlay();
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
const Big = imports.gi.Big;
|
const Big = imports.gi.Big;
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
|
const Lang = imports.lang;
|
||||||
|
const Mainloop = imports.mainloop;
|
||||||
const Shell = imports.gi.Shell;
|
const Shell = imports.gi.Shell;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
@ -27,6 +29,14 @@ RunDialog.prototype = {
|
|||||||
_init : function() {
|
_init : function() {
|
||||||
let global = Shell.Global.get();
|
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
|
// All actors are inside _group. We create it initially
|
||||||
// hidden then show it in show()
|
// hidden then show it in show()
|
||||||
this._group = new Clutter.Group({ visible: false });
|
this._group = new Clutter.Group({ visible: false });
|
||||||
@ -70,35 +80,27 @@ RunDialog.prototype = {
|
|||||||
this._entry.set_position(6, 30);
|
this._entry.set_position(6, 30);
|
||||||
boxGroup.add_actor(this._entry);
|
boxGroup.add_actor(this._entry);
|
||||||
|
|
||||||
let me = this;
|
this._entry.connect('activate', Lang.bind(this, function (o, e) {
|
||||||
|
this._run(o.get_text());
|
||||||
this._entry.connect('activate', function (o, e) {
|
this._entry.text = '';
|
||||||
me.hide();
|
this.close();
|
||||||
me._run(o.get_text());
|
|
||||||
return false;
|
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) {
|
_run : function(command) {
|
||||||
if (command.slice(0, 3) == 'js ') {
|
let f = this._internalCommands[command];
|
||||||
let commandHeader = "const Clutter = imports.gi.Clutter; " +
|
if (f) {
|
||||||
"const GLib = imports.gi.GLib; " +
|
f();
|
||||||
"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();
|
|
||||||
} else if (command) {
|
} else if (command) {
|
||||||
var p = new Shell.Process({'args' : [command]});
|
var p = new Shell.Process({'args' : [command]});
|
||||||
try {
|
try {
|
||||||
@ -108,47 +110,31 @@ RunDialog.prototype = {
|
|||||||
log('Could not run command ' + command + '.');
|
log('Could not run command ' + command + '.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('run');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
show : function() {
|
open : function() {
|
||||||
let me = this;
|
if (this._isOpen) // Already shown
|
||||||
|
return;
|
||||||
if (this._group.visible) // Already shown
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!Main.startModal())
|
if (!Main.startModal())
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
this._group.show_all();
|
this._isOpen = true;
|
||||||
|
this._group.show();
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
let global = Shell.Global.get();
|
let global = Shell.Global.get();
|
||||||
global.stage.set_key_focus(this._entry);
|
global.stage.set_key_focus(this._entry);
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hide : function() {
|
close : function() {
|
||||||
if (!this._group.visible)
|
if (!this._isOpen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._group.hide();
|
this._isOpen = false;
|
||||||
Main.endModal();
|
|
||||||
},
|
|
||||||
|
|
||||||
destroy : function(){
|
this._group.hide();
|
||||||
this.hide();
|
|
||||||
this._group.destroy();
|
Main.endModal();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Signals.addSignalMethods(RunDialog.prototype);
|
Signals.addSignalMethods(RunDialog.prototype);
|
||||||
|
Loading…
Reference in New Issue
Block a user