runDialog: use new history manager implementation

https://bugzilla.gnome.org/show_bug.cgi?id=642237
This commit is contained in:
Jasper St. Pierre 2011-02-13 11:42:04 -05:00
parent cf3c631cde
commit 30da70a09e

View File

@ -16,11 +16,11 @@ const Main = imports.ui.main;
const ModalDialog = imports.ui.modalDialog; const ModalDialog = imports.ui.modalDialog;
const Tweener = imports.ui.tweener; const Tweener = imports.ui.tweener;
const Util = imports.misc.util; const Util = imports.misc.util;
const History = imports.misc.history;
const MAX_FILE_DELETED_BEFORE_INVALID = 10; const MAX_FILE_DELETED_BEFORE_INVALID = 10;
const HISTORY_KEY = 'command-history'; const HISTORY_KEY = 'command-history';
const HISTORY_LIMIT = 512;
const DIALOG_GROW_TIME = 0.1; const DIALOG_GROW_TIME = 0.1;
@ -172,14 +172,6 @@ __proto__: ModalDialog.ModalDialog.prototype,
})); }));
this._enableInternalCommands = global.settings.get_boolean('development-tools'); this._enableInternalCommands = global.settings.get_boolean('development-tools');
this._history = global.settings.get_strv(HISTORY_KEY);
this._historyIndex = -1;
global.settings.connect('changed::' + HISTORY_KEY, Lang.bind(this, function() {
this._history = global.settings.get_strv(HISTORY_KEY);
this._historyIndex = this._history.length;
}));
this._internalCommands = { 'lg': this._internalCommands = { 'lg':
Lang.bind(this, function() { Lang.bind(this, function() {
Main.createLookingGlass().open(); Main.createLookingGlass().open();
@ -241,14 +233,20 @@ __proto__: ModalDialog.ModalDialog.prototype,
this._pathCompleter = new Gio.FilenameCompleter(); this._pathCompleter = new Gio.FilenameCompleter();
this._commandCompleter = new CommandCompleter(); this._commandCompleter = new CommandCompleter();
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._history = new History.HistoryManager(HISTORY_KEY);
this._history.connect('changed', Lang.bind(this, function(history, text) {
this._entryText.set_text(text);
}));
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) { if (symbol == Clutter.Down) {
this._setCommandFromHistory(this._historyIndex++); this._history.nextItem(o.get_text());
return true; return true;
} }
if (symbol == Clutter.Up) { if (symbol == Clutter.Up) {
this._setCommandFromHistory(this._historyIndex--); this._history.prevItem(o.get_text());
return true; return true;
} }
if (symbol == Clutter.Return || symbol == Clutter.KP_Enter) { if (symbol == Clutter.Return || symbol == Clutter.KP_Enter) {
@ -303,22 +301,10 @@ __proto__: ModalDialog.ModalDialog.prototype,
} }
}, },
_saveHistory : function() {
if (this._history.length > HISTORY_LIMIT) {
this._history.splice(0, this._history.length - HISTORY_LIMIT);
}
global.settings.set_strv(HISTORY_KEY, this._history);
},
_run : function(input, inTerminal) { _run : function(input, inTerminal) {
let command = input; let command = input;
if (this._history.length == 0 || this._history.addItem(input);
this._history[this._history.length - 1] != input) {
this._history.push(input);
this._saveHistory();
}
this._commandError = false; this._commandError = false;
let f; let f;
if (this._enableInternalCommands) if (this._enableInternalCommands)
@ -372,24 +358,8 @@ __proto__: ModalDialog.ModalDialog.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() {
this._historyIndex = this._history.length; this._history.lastItem();
this._errorBox.hide(); this._errorBox.hide();
this._entryText.set_text(''); this._entryText.set_text('');
this._commandError = false; this._commandError = false;