lookingGlass: use new history manager implementation
This starts saving lookingGlass history in gsettings, and also adds the ability to clear the text field by pressing 'down' on the last entry, like the run dialog and readline allow. https://bugzilla.gnome.org/show_bug.cgi?id=642237
This commit is contained in:
parent
30da70a09e
commit
4bedbca66f
@ -45,6 +45,10 @@
|
|||||||
<default>[]</default>
|
<default>[]</default>
|
||||||
<_summary>History for command (Alt-F2) dialog</_summary>
|
<_summary>History for command (Alt-F2) dialog</_summary>
|
||||||
</key>
|
</key>
|
||||||
|
<key name="looking-glass-history" type="as">
|
||||||
|
<default>[]</default>
|
||||||
|
<_summary>History for the looking glass dialog</_summary>
|
||||||
|
</key>
|
||||||
<child name="clock" schema="org.gnome.shell.clock"/>
|
<child name="clock" schema="org.gnome.shell.clock"/>
|
||||||
<child name="calendar" schema="org.gnome.shell.calendar"/>
|
<child name="calendar" schema="org.gnome.shell.calendar"/>
|
||||||
<child name="recorder" schema="org.gnome.shell.recorder"/>
|
<child name="recorder" schema="org.gnome.shell.recorder"/>
|
||||||
|
@ -14,6 +14,7 @@ const Mainloop = imports.mainloop;
|
|||||||
const Gettext = imports.gettext.domain('gnome-shell');
|
const Gettext = imports.gettext.domain('gnome-shell');
|
||||||
const _ = Gettext.gettext;
|
const _ = Gettext.gettext;
|
||||||
|
|
||||||
|
const History = imports.misc.history;
|
||||||
const ExtensionSystem = imports.ui.extensionSystem;
|
const ExtensionSystem = imports.ui.extensionSystem;
|
||||||
const Link = imports.ui.link;
|
const Link = imports.ui.link;
|
||||||
const Tweener = imports.ui.tweener;
|
const Tweener = imports.ui.tweener;
|
||||||
@ -37,6 +38,8 @@ var commandHeader = 'const Clutter = imports.gi.Clutter; ' +
|
|||||||
'const it = Main.lookingGlass.getIt(); ' +
|
'const it = Main.lookingGlass.getIt(); ' +
|
||||||
'const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); ';
|
'const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); ';
|
||||||
|
|
||||||
|
const HISTORY_KEY = 'looking-glass-history';
|
||||||
|
|
||||||
function Notebook() {
|
function Notebook() {
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
@ -671,18 +674,10 @@ function LookingGlass() {
|
|||||||
|
|
||||||
LookingGlass.prototype = {
|
LookingGlass.prototype = {
|
||||||
_init : function() {
|
_init : function() {
|
||||||
this._idleHistorySaveId = 0;
|
|
||||||
let historyPath = global.userdatadir + '/lookingglass-history.txt';
|
|
||||||
this._historyFile = Gio.file_new_for_path(historyPath);
|
|
||||||
this._savedText = null;
|
|
||||||
this._historyNavIndex = -1;
|
|
||||||
this._history = [];
|
|
||||||
this._borderPaintTarget = null;
|
this._borderPaintTarget = null;
|
||||||
this._borderPaintId = 0;
|
this._borderPaintId = 0;
|
||||||
this._borderDestroyId = 0;
|
this._borderDestroyId = 0;
|
||||||
|
|
||||||
this._readHistory();
|
|
||||||
|
|
||||||
this._open = false;
|
this._open = false;
|
||||||
|
|
||||||
this._offset = 0;
|
this._offset = 0;
|
||||||
@ -779,31 +774,23 @@ LookingGlass.prototype = {
|
|||||||
if (text == '')
|
if (text == '')
|
||||||
return true;
|
return true;
|
||||||
this._evaluate(text);
|
this._evaluate(text);
|
||||||
this._historyNavIndex = -1;
|
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this._history = new History.HistoryManager(HISTORY_KEY);
|
||||||
|
this._history.connect('changed', Lang.bind(this, function(history, text) {
|
||||||
|
this._entry.text = text;
|
||||||
|
}));
|
||||||
|
|
||||||
this._entry.clutter_text.connect('key-press-event', Lang.bind(this, function(o, e) {
|
this._entry.clutter_text.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.Up) {
|
if (symbol == Clutter.Up) {
|
||||||
if (this._historyNavIndex >= this._history.length - 1)
|
this._history.prevItem(o.get_text());
|
||||||
return true;
|
|
||||||
this._historyNavIndex++;
|
|
||||||
if (this._historyNavIndex == 0)
|
|
||||||
this._savedText = this._entry.text;
|
|
||||||
this._entry.text = this._history[this._history.length - this._historyNavIndex - 1];
|
|
||||||
return true;
|
return true;
|
||||||
} else if (symbol == Clutter.Down) {
|
} else if (symbol == Clutter.Down) {
|
||||||
if (this._historyNavIndex <= 0)
|
this._history.nextItem(o.get_text());
|
||||||
return true;
|
|
||||||
this._historyNavIndex--;
|
|
||||||
if (this._historyNavIndex < 0)
|
|
||||||
this._entry.text = this._savedText;
|
|
||||||
else
|
|
||||||
this._entry.text = this._history[this._history.length - this._historyNavIndex - 1];
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this._historyNavIndex = -1;
|
|
||||||
this._savedText = null;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -821,29 +808,6 @@ LookingGlass.prototype = {
|
|||||||
+ 'font-family: "' + fontDesc.get_family() + '";';
|
+ 'font-family: "' + fontDesc.get_family() + '";';
|
||||||
},
|
},
|
||||||
|
|
||||||
_readHistory: function () {
|
|
||||||
if (!this._historyFile.query_exists(null))
|
|
||||||
return;
|
|
||||||
let [result, contents, length, etag] = this._historyFile.load_contents(null);
|
|
||||||
this._history = contents.split('\n').filter(function (e) { return e != ''; });
|
|
||||||
},
|
|
||||||
|
|
||||||
_queueHistorySave: function() {
|
|
||||||
if (this._idleHistorySaveId > 0)
|
|
||||||
return;
|
|
||||||
this._idleHistorySaveId = Mainloop.timeout_add_seconds(5, Lang.bind(this, this._doSaveHistory));
|
|
||||||
},
|
|
||||||
|
|
||||||
_doSaveHistory: function () {
|
|
||||||
this._idleHistorySaveId = false;
|
|
||||||
let output = this._historyFile.replace(null, true, Gio.FileCreateFlags.NONE, null);
|
|
||||||
let dataOut = new Gio.DataOutputStream({ base_stream: output });
|
|
||||||
dataOut.put_string(this._history.join('\n'), null);
|
|
||||||
dataOut.put_string('\n', null);
|
|
||||||
dataOut.close(null);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
_pushResult: function(command, obj) {
|
_pushResult: function(command, obj) {
|
||||||
let index = this._results.length + this._offset;
|
let index = this._results.length + this._offset;
|
||||||
let result = new Result('>>> ' + command, obj, index);
|
let result = new Result('>>> ' + command, obj, index);
|
||||||
@ -874,8 +838,7 @@ LookingGlass.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_evaluate : function(command) {
|
_evaluate : function(command) {
|
||||||
this._history.push(command);
|
this._history.addItem(command);
|
||||||
this._queueHistorySave();
|
|
||||||
|
|
||||||
let fullCmd = commandHeader + command;
|
let fullCmd = commandHeader + command;
|
||||||
|
|
||||||
@ -962,6 +925,7 @@ LookingGlass.prototype = {
|
|||||||
this.actor.show();
|
this.actor.show();
|
||||||
this.actor.lower(Main.chrome.actor);
|
this.actor.lower(Main.chrome.actor);
|
||||||
this._open = true;
|
this._open = true;
|
||||||
|
this._history.lastItem();
|
||||||
|
|
||||||
Tweener.removeTweens(this.actor);
|
Tweener.removeTweens(this.actor);
|
||||||
|
|
||||||
@ -979,7 +943,6 @@ LookingGlass.prototype = {
|
|||||||
|
|
||||||
this._objInspector.actor.hide();
|
this._objInspector.actor.hide();
|
||||||
|
|
||||||
this._historyNavIndex = -1;
|
|
||||||
this._open = false;
|
this._open = false;
|
||||||
Tweener.removeTweens(this.actor);
|
Tweener.removeTweens(this.actor);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user