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-12-17 22:12:46 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2009-08-10 19:49:25 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
2009-08-03 21:52:45 +00:00
|
|
|
const Lang = imports.lang;
|
2009-09-15 21:40:26 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-02-09 17:42:07 +00:00
|
|
|
const St = imports.gi.St;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
2009-08-14 13:30:48 +00:00
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2010-02-26 20:13:11 +00:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
2008-11-19 23:21:42 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-03-17 14:36:57 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2009-12-17 22:12:46 +00:00
|
|
|
const MAX_FILE_DELETED_BEFORE_INVALID = 10;
|
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
const HISTORY_KEY = 'command-history';
|
2010-03-17 15:22:27 +00:00
|
|
|
const HISTORY_LIMIT = 512;
|
|
|
|
|
2010-06-10 15:22:23 +00:00
|
|
|
const DIALOG_FADE_TIME = 0.1;
|
2010-03-17 14:36:57 +00:00
|
|
|
|
2009-12-17 22:12:46 +00:00
|
|
|
function CommandCompleter() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandCompleter.prototype = {
|
|
|
|
_init : function() {
|
|
|
|
this._changedCount = 0;
|
|
|
|
this._paths = GLib.getenv('PATH').split(':');
|
2010-02-26 19:07:44 +00:00
|
|
|
this._paths.push(GLib.get_home_dir());
|
2009-12-17 22:12:46 +00:00
|
|
|
this._valid = false;
|
|
|
|
this._updateInProgress = false;
|
|
|
|
this._childs = new Array(this._paths.length);
|
|
|
|
this._monitors = new Array(this._paths.length);
|
|
|
|
for (let i = 0; i < this._paths.length; i++) {
|
|
|
|
this._childs[i] = [];
|
|
|
|
let file = Gio.file_new_for_path(this._paths[i]);
|
2009-12-19 05:41:05 +00:00
|
|
|
let info;
|
|
|
|
try {
|
|
|
|
info = file.query_info(Gio.FILE_ATTRIBUTE_STANDARD_TYPE, Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
} catch (e) {
|
|
|
|
// FIXME catchall
|
|
|
|
this._paths[i] = null;
|
|
|
|
continue;
|
|
|
|
}
|
2009-12-17 22:12:46 +00:00
|
|
|
|
|
|
|
if (info.get_attribute_uint32(Gio.FILE_ATTRIBUTE_STANDARD_TYPE) != Gio.FileType.DIRECTORY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
this._paths[i] = file.get_path();
|
|
|
|
this._monitors[i] = file.monitor_directory(Gio.FileMonitorFlags.NONE, null);
|
|
|
|
if (this._monitors[i] != null) {
|
2010-05-13 19:46:04 +00:00
|
|
|
this._monitors[i].connect('changed', Lang.bind(this, this._onChanged));
|
2009-12-17 22:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-19 05:41:05 +00:00
|
|
|
this._paths = this._paths.filter(function(a) {
|
|
|
|
return a != null;
|
|
|
|
});
|
2009-12-17 22:12:46 +00:00
|
|
|
this._update(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onGetEnumerateComplete : function(obj, res) {
|
|
|
|
this._enumerator = obj.enumerate_children_finish(res);
|
2010-03-19 11:13:31 +00:00
|
|
|
this._enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, Lang.bind(this, this._onNextFileComplete));
|
2009-12-17 22:12:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onNextFileComplete : function(obj, res) {
|
|
|
|
let files = obj.next_files_finish(res);
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
this._childs[this._i].push(files[i].get_name());
|
|
|
|
}
|
|
|
|
if (files.length) {
|
2010-03-19 11:13:31 +00:00
|
|
|
this._enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, Lang.bind(this, this._onNextFileComplete));
|
2009-12-17 22:12:46 +00:00
|
|
|
} else {
|
|
|
|
this._enumerator.close(null);
|
|
|
|
this._enumerator = null;
|
|
|
|
this._update(this._i + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update : function() {
|
|
|
|
if (this._valid)
|
|
|
|
return;
|
|
|
|
this._update(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
_update : function(i) {
|
|
|
|
if (i == 0 && this._updateInProgress)
|
|
|
|
return;
|
|
|
|
this._updateInProgress = true;
|
|
|
|
this._changedCount = 0;
|
|
|
|
this._i = i;
|
|
|
|
if (i >= this._paths.length) {
|
|
|
|
this._valid = true;
|
|
|
|
this._updateInProgress = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let file = Gio.file_new_for_path(this._paths[i]);
|
|
|
|
this._childs[this._i] = [];
|
2010-03-19 11:13:31 +00:00
|
|
|
file.enumerate_children_async(Gio.FILE_ATTRIBUTE_STANDARD_NAME, Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_LOW, null, Lang.bind(this, this._onGetEnumerateComplete));
|
2009-12-17 22:12:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onChanged : function(m, f, of, type) {
|
|
|
|
if (!this._valid)
|
|
|
|
return;
|
|
|
|
let path = f.get_parent().get_path();
|
|
|
|
let k = undefined;
|
|
|
|
for (let i = 0; i < this._paths.length; i++) {
|
|
|
|
if (this._paths[i] == path)
|
|
|
|
k = i;
|
|
|
|
}
|
|
|
|
if (k === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (type == Gio.FileMonitorEvent.CREATED) {
|
|
|
|
this._childs[k].push(f.get_basename());
|
|
|
|
}
|
|
|
|
if (type == Gio.FileMonitorEvent.DELETED) {
|
|
|
|
this._changedCount++;
|
|
|
|
if (this._changedCount > MAX_FILE_DELETED_BEFORE_INVALID) {
|
|
|
|
this._valid = false;
|
|
|
|
}
|
|
|
|
let name = f.get_basename();
|
|
|
|
this._childs[k] = this._childs[k].filter(function(e) {
|
|
|
|
return e != name;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (type == Gio.FileMonitorEvent.UNMOUNTED) {
|
|
|
|
this._childs[k] = [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getCompletion: function(text) {
|
2010-05-13 19:46:04 +00:00
|
|
|
let common = '';
|
2009-12-17 22:12:46 +00:00
|
|
|
let notInit = true;
|
|
|
|
if (!this._valid) {
|
|
|
|
this._update(0);
|
|
|
|
return common;
|
|
|
|
}
|
|
|
|
function _getCommon(s1, s2) {
|
|
|
|
let k = 0;
|
|
|
|
for (; k < s1.length && k < s2.length; k++) {
|
|
|
|
if (s1[k] != s2[k])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (k == 0)
|
2010-05-13 19:46:04 +00:00
|
|
|
return '';
|
2009-12-17 22:12:46 +00:00
|
|
|
return s1.substr(0, k);
|
|
|
|
}
|
|
|
|
function _hasPrefix(s1, prefix) {
|
|
|
|
return s1.indexOf(prefix) == 0;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < this._childs.length; i++) {
|
|
|
|
for (let k = 0; k < this._childs[i].length; k++) {
|
|
|
|
if (!_hasPrefix(this._childs[i][k], text))
|
|
|
|
continue;
|
|
|
|
if (notInit) {
|
|
|
|
common = this._childs[i][k];
|
|
|
|
notInit = false;
|
|
|
|
}
|
|
|
|
common = _getCommon(common, this._childs[i][k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (common.length)
|
|
|
|
return common.substr(text.length);
|
|
|
|
return common;
|
|
|
|
}
|
|
|
|
};
|
2008-11-19 23:21:42 +00:00
|
|
|
|
|
|
|
function RunDialog() {
|
|
|
|
this._init();
|
2010-03-15 13:50:05 +00:00
|
|
|
}
|
2008-11-19 23:21:42 +00:00
|
|
|
|
|
|
|
RunDialog.prototype = {
|
2008-12-01 19:51:43 +00:00
|
|
|
_init : function() {
|
2009-08-03 21:52:45 +00:00
|
|
|
this._isOpen = false;
|
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.connect('changed::development-tools', Lang.bind(this, function () {
|
|
|
|
this._enableInternalCommands = global.settings.get_boolean('development-tools');
|
2010-03-17 15:22:27 +00:00
|
|
|
}));
|
2010-05-05 21:05:42 +00:00
|
|
|
this._enableInternalCommands = global.settings.get_boolean('development-tools');
|
2010-03-17 15:22:27 +00:00
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
this._history = global.settings.get_strv(HISTORY_KEY);
|
2010-03-17 15:22:27 +00:00
|
|
|
this._historyIndex = -1;
|
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.connect('changed::' + HISTORY_KEY, Lang.bind(this, function() {
|
|
|
|
this._history = global.settings.get_strv(HISTORY_KEY);
|
2010-03-17 15:22:27 +00:00
|
|
|
this._historyIndex = this._history.length;
|
2009-09-14 17:45:49 +00:00
|
|
|
}));
|
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
this._internalCommands = { 'lg':
|
|
|
|
Lang.bind(this, function() {
|
2009-09-15 19:53:07 +00:00
|
|
|
Main.createLookingGlass().open();
|
2009-08-02 07:46:01 +00:00
|
|
|
}),
|
2009-08-26 22:43:44 +00:00
|
|
|
|
|
|
|
'r': Lang.bind(this, function() {
|
|
|
|
global.reexec_self();
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Developer brain backwards compatibility
|
2009-08-02 07:46:01 +00:00
|
|
|
'restart': Lang.bind(this, function() {
|
2009-08-03 21:52:45 +00:00
|
|
|
global.reexec_self();
|
2009-09-15 21:40:26 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
'debugexit': Lang.bind(this, function() {
|
|
|
|
Meta.exit(Meta.ExitCode.ERROR);
|
2009-08-03 21:52:45 +00:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// All actors are inside _group. We create it initially
|
|
|
|
// hidden then show it in show()
|
2009-08-25 19:23:53 +00:00
|
|
|
this._group = new Clutter.Group({ visible: false,
|
2010-02-26 16:32:38 +00:00
|
|
|
x: 0, y: 0 });
|
2010-05-06 21:18:10 +00:00
|
|
|
Main.uiGroup.add_actor(this._group);
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2010-03-17 14:36:57 +00:00
|
|
|
this._lightbox = new Lightbox.Lightbox(this._group,
|
|
|
|
{ inhibitEvents: true });
|
2010-02-26 20:13:11 +00:00
|
|
|
|
|
|
|
this._box = new St.Bin({ x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._group.add_actor(this._box);
|
2010-03-17 14:36:57 +00:00
|
|
|
this._lightbox.highlight(this._box);
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
let dialogBox = new St.BoxLayout({ style_class: 'run-dialog', vertical: true });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._box.set_child(dialogBox);
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
let label = new St.Label({ style_class: 'run-dialog-label',
|
|
|
|
text: _("Please enter a command:") });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
dialogBox.add(label, { expand: true, y_fill: false });
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
let entry = new St.Entry({ style_class: 'run-dialog-entry' });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._entryText = entry.clutter_text;
|
|
|
|
dialogBox.add(entry, { expand: true });
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._errorBox = new St.BoxLayout();
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
dialogBox.add(this._errorBox, { expand: true });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
let errorIcon = new St.Button({ style_class: 'run-dialog-error-icon' });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._errorBox.add(errorIcon);
|
2009-09-08 18:04:18 +00:00
|
|
|
|
|
|
|
this._commandError = false;
|
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._errorMessage = new St.Label({ style_class: 'run-dialog-error-label' });
|
|
|
|
this._errorMessage.clutter_text.line_wrap = true;
|
2009-09-08 18:04:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._errorBox.add(this._errorMessage, { expand: true });
|
2009-09-08 18:04:18 +00:00
|
|
|
|
|
|
|
this._errorBox.hide();
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2009-12-17 22:12:46 +00:00
|
|
|
this._pathCompleter = new Gio.FilenameCompleter();
|
|
|
|
this._commandCompleter = new CommandCompleter();
|
|
|
|
this._group.connect('notify::visible', Lang.bind(this._commandCompleter, this._commandCompleter.update));
|
2010-02-26 16:32:38 +00:00
|
|
|
this._entryText.connect('key-press-event', Lang.bind(this, function(o, e) {
|
2009-09-08 20:58:57 +00:00
|
|
|
let symbol = e.get_key_symbol();
|
2010-03-17 15:22:27 +00:00
|
|
|
if (symbol == Clutter.Down) {
|
|
|
|
this._setCommandFromHistory(this._historyIndex++);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (symbol == Clutter.Up) {
|
|
|
|
this._setCommandFromHistory(this._historyIndex--);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-31 13:29:11 +00:00
|
|
|
if (symbol == Clutter.Return || symbol == Clutter.KP_Enter) {
|
2010-03-24 17:15:50 +00:00
|
|
|
if (Shell.get_event_state(e) & Clutter.ModifierType.CONTROL_MASK)
|
2010-02-26 16:32:38 +00:00
|
|
|
this._run(o.get_text(), true);
|
|
|
|
else
|
|
|
|
this._run(o.get_text(), false);
|
|
|
|
if (!this._commandError)
|
|
|
|
this.close();
|
|
|
|
}
|
2009-08-03 21:52:45 +00:00
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-17 22:12:46 +00:00
|
|
|
if (symbol == Clutter.slash) {
|
|
|
|
// Need preload data before get completion. GFilenameCompleter load content of parent directory.
|
|
|
|
// Parent directory for /usr/include/ is /usr/. So need to add fake name('a').
|
|
|
|
let text = o.get_text().concat('/a');
|
|
|
|
let prefix;
|
|
|
|
if (text.lastIndexOf(' ') == -1)
|
|
|
|
prefix = text;
|
|
|
|
else
|
|
|
|
prefix = text.substr(text.lastIndexOf(' ') + 1);
|
|
|
|
this._getCompletion(prefix);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (symbol == Clutter.Tab) {
|
|
|
|
let text = o.get_text();
|
|
|
|
let prefix;
|
|
|
|
if (text.lastIndexOf(' ') == -1)
|
|
|
|
prefix = text;
|
|
|
|
else
|
|
|
|
prefix = text.substr(text.lastIndexOf(' ') + 1);
|
|
|
|
let postfix = this._getCompletion(prefix);
|
|
|
|
if (postfix != null && postfix.length > 0) {
|
|
|
|
o.insert_text(postfix, -1);
|
|
|
|
o.set_cursor_position(text.length + postfix.length);
|
|
|
|
if (postfix[postfix.length - 1] == '/')
|
|
|
|
this._getCompletion(text + postfix + 'a');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-03 21:52:45 +00:00
|
|
|
return false;
|
|
|
|
}));
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
|
|
|
|
2009-12-17 22:12:46 +00:00
|
|
|
_getCompletion : function(text) {
|
|
|
|
if (text.indexOf('/') != -1) {
|
|
|
|
return this._pathCompleter.get_completion_suffix(text);
|
|
|
|
} else {
|
|
|
|
return this._commandCompleter.getCompletion(text);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-03-17 15:22:27 +00:00
|
|
|
_saveHistory : function() {
|
|
|
|
if (this._history.length > HISTORY_LIMIT) {
|
|
|
|
this._history.splice(0, this._history.length - HISTORY_LIMIT);
|
|
|
|
}
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.set_strv(HISTORY_KEY, this._history);
|
2010-03-17 15:22:27 +00:00
|
|
|
},
|
|
|
|
|
2010-02-26 19:07:44 +00:00
|
|
|
_run : function(input, inTerminal) {
|
|
|
|
let command = input;
|
2010-03-17 15:22:27 +00:00
|
|
|
|
2010-06-09 13:30:40 +00:00
|
|
|
if (this._history.length == 0 ||
|
|
|
|
this._history[this._history.length - 1] != input) {
|
2010-03-23 19:22:46 +00:00
|
|
|
this._history.push(input);
|
|
|
|
this._saveHistory();
|
|
|
|
}
|
2010-03-17 15:22:27 +00:00
|
|
|
|
2009-10-01 21:44:16 +00:00
|
|
|
this._commandError = false;
|
2009-09-14 17:45:49 +00:00
|
|
|
let f;
|
|
|
|
if (this._enableInternalCommands)
|
2010-02-26 19:07:44 +00:00
|
|
|
f = this._internalCommands[input];
|
2009-09-14 17:45:49 +00:00
|
|
|
else
|
|
|
|
f = null;
|
2009-08-03 21:52:45 +00:00
|
|
|
if (f) {
|
|
|
|
f();
|
2010-02-26 19:07:44 +00:00
|
|
|
} else if (input) {
|
2008-12-01 19:51:43 +00:00
|
|
|
try {
|
2010-02-26 16:32:38 +00:00
|
|
|
if (inTerminal)
|
2010-02-26 19:07:44 +00:00
|
|
|
command = 'gnome-terminal -x ' + input;
|
2009-08-10 19:49:25 +00:00
|
|
|
let [ok, len, args] = GLib.shell_parse_argv(command);
|
2010-02-26 16:32:38 +00:00
|
|
|
let p = new Shell.Process({ 'args' : args });
|
2008-12-01 19:51:43 +00:00
|
|
|
p.run();
|
|
|
|
} catch (e) {
|
2010-02-26 19:07:44 +00:00
|
|
|
// Mmmh, that failed - see if @input matches an existing file
|
|
|
|
let path = null;
|
|
|
|
if (input.charAt(0) == '/') {
|
|
|
|
path = input;
|
|
|
|
} else {
|
|
|
|
if (input.charAt(0) == '~')
|
|
|
|
input = input.slice(1);
|
|
|
|
path = GLib.get_home_dir() + '/' + input;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLib.file_test(path, GLib.FileTest.EXISTS)) {
|
|
|
|
let file = Gio.file_new_for_path(path);
|
|
|
|
Gio.app_info_launch_default_for_uri(file.get_uri(),
|
|
|
|
global.create_app_launch_context());
|
|
|
|
} else {
|
|
|
|
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);
|
2010-05-13 19:46:04 +00:00
|
|
|
let errorStr = _("Execution of '%s' failed:").format(command) + '\n' + m[1];
|
2010-02-26 19:07:44 +00:00
|
|
|
this._errorMessage.set_text(errorStr);
|
|
|
|
|
|
|
|
this._errorBox.show();
|
|
|
|
}
|
2008-12-01 19:51:43 +00:00
|
|
|
}
|
2008-11-19 23:21:42 +00:00
|
|
|
}
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2010-03-17 15:22:27 +00:00
|
|
|
_setCommandFromHistory: function(lastI) {
|
|
|
|
if (this._historyIndex < 0)
|
|
|
|
this._historyIndex = 0;
|
|
|
|
if (this._historyIndex > this._history.length)
|
|
|
|
this._historyIndex = this._history.length;
|
|
|
|
|
|
|
|
let text = this._entryText.get_text();
|
|
|
|
if (text) {
|
|
|
|
this._history[lastI] = text;
|
|
|
|
}
|
|
|
|
if (this._history[this._historyIndex]) {
|
|
|
|
this._entryText.set_text(this._history[this._historyIndex]);
|
|
|
|
} else
|
|
|
|
this._entryText.set_text('');
|
|
|
|
},
|
|
|
|
|
2009-08-03 21:52:45 +00:00
|
|
|
open : function() {
|
|
|
|
if (this._isOpen) // Already shown
|
|
|
|
return;
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2009-09-16 15:37:51 +00:00
|
|
|
if (!Main.pushModal(this._group))
|
|
|
|
return;
|
|
|
|
|
2009-08-25 19:23:53 +00:00
|
|
|
// Position the dialog on the current monitor
|
|
|
|
let monitor = global.get_focus_monitor();
|
|
|
|
|
2010-03-17 15:22:27 +00:00
|
|
|
this._historyIndex = this._history.length;
|
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
this._box.set_position(monitor.x, monitor.y);
|
|
|
|
this._box.set_size(monitor.width, monitor.height);
|
2009-08-25 19:23:53 +00:00
|
|
|
|
2009-08-03 21:52:45 +00:00
|
|
|
this._isOpen = true;
|
2010-03-17 14:36:57 +00:00
|
|
|
this._lightbox.show();
|
|
|
|
this._group.opacity = 0;
|
2009-08-03 21:52:45 +00:00
|
|
|
this._group.show();
|
2010-03-17 14:36:57 +00:00
|
|
|
Tweener.addTween(this._group,
|
|
|
|
{ opacity: 255,
|
|
|
|
time: DIALOG_FADE_TIME,
|
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2010-02-26 16:32:38 +00:00
|
|
|
global.stage.set_key_focus(this._entryText);
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2009-08-03 21:52:45 +00:00
|
|
|
close : function() {
|
|
|
|
if (!this._isOpen)
|
2008-12-01 19:51:43 +00:00
|
|
|
return;
|
2008-11-19 23:21:42 +00:00
|
|
|
|
2009-08-03 21:52:45 +00:00
|
|
|
this._isOpen = false;
|
2009-09-08 18:04:18 +00:00
|
|
|
this._commandError = false;
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
Main.popModal(this._group);
|
2010-03-17 14:36:57 +00:00
|
|
|
|
|
|
|
Tweener.addTween(this._group,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: DIALOG_FADE_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
this._errorBox.hide();
|
|
|
|
this._group.hide();
|
|
|
|
this._entryText.set_text('');
|
|
|
|
})
|
|
|
|
});
|
2008-12-01 19:51:43 +00:00
|
|
|
}
|
2008-11-19 23:21:42 +00:00
|
|
|
};
|
2008-11-20 15:40:44 +00:00
|
|
|
Signals.addSignalMethods(RunDialog.prototype);
|