support arrow-up to recall previous commands
runDialog store history in gconf. https://bugzilla.gnome.org/show_bug.cgi?id=612635
This commit is contained in:
parent
e21aea6e13
commit
908b0fb727
@ -45,6 +45,18 @@
|
|||||||
</locale>
|
</locale>
|
||||||
</schema>
|
</schema>
|
||||||
|
|
||||||
|
<schema>
|
||||||
|
<key>/schemas/desktop/gnome/shell/run_dialog/history</key>
|
||||||
|
<applyto>/desktop/gnome/shell/run_dialog/history</applyto>
|
||||||
|
<owner>gnome-shell</owner>
|
||||||
|
<type>list</type>
|
||||||
|
<list_type>string</list_type>
|
||||||
|
<default>[]</default>
|
||||||
|
<locale name="C">
|
||||||
|
<short>History for command (Alt-F2) dialog</short>
|
||||||
|
</locale>
|
||||||
|
</schema>
|
||||||
|
|
||||||
<schema>
|
<schema>
|
||||||
<key>/schemas/desktop/gnome/shell/sidebar/visible</key>
|
<key>/schemas/desktop/gnome/shell/sidebar/visible</key>
|
||||||
<applyto>/desktop/gnome/shell/sidebar/visible</applyto>
|
<applyto>/desktop/gnome/shell/sidebar/visible</applyto>
|
||||||
|
@ -18,6 +18,9 @@ const Main = imports.ui.main;
|
|||||||
|
|
||||||
const MAX_FILE_DELETED_BEFORE_INVALID = 10;
|
const MAX_FILE_DELETED_BEFORE_INVALID = 10;
|
||||||
|
|
||||||
|
const HISTORY_KEY = 'run_dialog/history';
|
||||||
|
const HISTORY_LIMIT = 512;
|
||||||
|
|
||||||
function CommandCompleter() {
|
function CommandCompleter() {
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
@ -174,11 +177,19 @@ RunDialog.prototype = {
|
|||||||
_init : function() {
|
_init : function() {
|
||||||
this._isOpen = false;
|
this._isOpen = false;
|
||||||
|
|
||||||
let gconf = Shell.GConf.get_default();
|
this._gconf = Shell.GConf.get_default();
|
||||||
gconf.connect('changed::development_tools', Lang.bind(this, function () {
|
this._gconf.connect('changed::development_tools', Lang.bind(this, function () {
|
||||||
this._enableInternalCommands = gconf.get_boolean('development_tools');
|
this._enableInternalCommands = this._gconf.get_boolean('development_tools');
|
||||||
|
}));
|
||||||
|
this._enableInternalCommands = this._gconf.get_boolean('development_tools');
|
||||||
|
|
||||||
|
this._history = this._gconf.get_string_list(HISTORY_KEY);
|
||||||
|
this._historyIndex = -1;
|
||||||
|
|
||||||
|
this._gconf.connect('changed::' + HISTORY_KEY, Lang.bind(this, function() {
|
||||||
|
this._history = this._gconf.get_string_list(HISTORY_KEY);
|
||||||
|
this._historyIndex = this._history.length;
|
||||||
}));
|
}));
|
||||||
this._enableInternalCommands = gconf.get_boolean('development_tools');
|
|
||||||
|
|
||||||
this._internalCommands = { 'lg':
|
this._internalCommands = { 'lg':
|
||||||
Lang.bind(this, function() {
|
Lang.bind(this, function() {
|
||||||
@ -249,6 +260,14 @@ RunDialog.prototype = {
|
|||||||
this._group.connect('notify::visible', Lang.bind(this._commandCompleter, this._commandCompleter.update));
|
this._group.connect('notify::visible', Lang.bind(this._commandCompleter, this._commandCompleter.update));
|
||||||
this._entryText.connect('key-press-event', Lang.bind(this, function(o, e) {
|
this._entryText.connect('key-press-event', Lang.bind(this, function(o, e) {
|
||||||
let symbol = e.get_key_symbol();
|
let symbol = e.get_key_symbol();
|
||||||
|
if (symbol == Clutter.Down) {
|
||||||
|
this._setCommandFromHistory(this._historyIndex++);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (symbol == Clutter.Up) {
|
||||||
|
this._setCommandFromHistory(this._historyIndex--);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (symbol == Clutter.Return) {
|
if (symbol == Clutter.Return) {
|
||||||
if (e.get_state() & Clutter.ModifierType.CONTROL_MASK)
|
if (e.get_state() & Clutter.ModifierType.CONTROL_MASK)
|
||||||
this._run(o.get_text(), true);
|
this._run(o.get_text(), true);
|
||||||
@ -301,8 +320,19 @@ RunDialog.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_saveHistory : function() {
|
||||||
|
if (this._history.length > HISTORY_LIMIT) {
|
||||||
|
this._history.splice(0, this._history.length - HISTORY_LIMIT);
|
||||||
|
}
|
||||||
|
this._gconf.set_string_list(HISTORY_KEY, this._history);
|
||||||
|
},
|
||||||
|
|
||||||
_run : function(input, inTerminal) {
|
_run : function(input, inTerminal) {
|
||||||
let command = input;
|
let command = input;
|
||||||
|
|
||||||
|
this._history.push(input);
|
||||||
|
this._saveHistory();
|
||||||
|
|
||||||
this._commandError = false;
|
this._commandError = false;
|
||||||
let f;
|
let f;
|
||||||
if (this._enableInternalCommands)
|
if (this._enableInternalCommands)
|
||||||
@ -350,6 +380,22 @@ RunDialog.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_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('');
|
||||||
|
},
|
||||||
|
|
||||||
open : function() {
|
open : function() {
|
||||||
if (this._isOpen) // Already shown
|
if (this._isOpen) // Already shown
|
||||||
return;
|
return;
|
||||||
@ -360,6 +406,8 @@ RunDialog.prototype = {
|
|||||||
// Position the dialog on the current monitor
|
// Position the dialog on the current monitor
|
||||||
let monitor = global.get_focus_monitor();
|
let monitor = global.get_focus_monitor();
|
||||||
|
|
||||||
|
this._historyIndex = this._history.length;
|
||||||
|
|
||||||
this._box.set_position(monitor.x, monitor.y);
|
this._box.set_position(monitor.x, monitor.y);
|
||||||
this._box.set_size(monitor.width, monitor.height);
|
this._box.set_size(monitor.width, monitor.height);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user