mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 11:58:00 +01:00
Generate file completions asynchronously
This commit is contained in:
@@ -187,7 +187,6 @@ CompletionContext.prototype = {
|
|||||||
},
|
},
|
||||||
set generate(arg)
|
set generate(arg)
|
||||||
{
|
{
|
||||||
let self = this;
|
|
||||||
this.hasItems = true;
|
this.hasItems = true;
|
||||||
this._generate = arg;
|
this._generate = arg;
|
||||||
if (this.background && this.regenerate)
|
if (this.background && this.regenerate)
|
||||||
@@ -195,12 +194,14 @@ CompletionContext.prototype = {
|
|||||||
let lock = {};
|
let lock = {};
|
||||||
this.cache.backgroundLock = lock;
|
this.cache.backgroundLock = lock;
|
||||||
this.incomplete = true;
|
this.incomplete = true;
|
||||||
liberator.callFunctionInThread(null, function () {
|
liberator.dump({name: this.name, length: this.items.length});
|
||||||
let items = self.generate();
|
let now = Date.now();
|
||||||
if (self.cache.backgroundLock != lock)
|
liberator.callAsync(this, function () {
|
||||||
|
let items = this.generate();
|
||||||
|
if (this.cache.backgroundLock != lock)
|
||||||
return;
|
return;
|
||||||
self.incomplete = false;
|
this.incomplete = false;
|
||||||
self.completions = items;
|
this.completions = items;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -231,7 +232,7 @@ CompletionContext.prototype = {
|
|||||||
return this.cache.filtered;
|
return this.cache.filtered;
|
||||||
this.cache.rows = [];
|
this.cache.rows = [];
|
||||||
let items = this.completions;
|
let items = this.completions;
|
||||||
if (this.generate)
|
if (this.generate && !this.background)
|
||||||
{
|
{
|
||||||
// XXX
|
// XXX
|
||||||
let updateAsync = this.updateAsync;
|
let updateAsync = this.updateAsync;
|
||||||
@@ -1230,6 +1231,7 @@ function Completion() //{{{
|
|||||||
context.advance(dir.length);
|
context.advance(dir.length);
|
||||||
context.keys = { text: 0, description: 1, icon: 2 };
|
context.keys = { text: 0, description: 1, icon: 2 };
|
||||||
context.anchored = true;
|
context.anchored = true;
|
||||||
|
context.background = true;
|
||||||
context.key = dir;
|
context.key = dir;
|
||||||
context.generate = function generate_file()
|
context.generate = function generate_file()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
|
|||||||
the terms of any one of the MPL, the GPL or the LGPL.
|
the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
}}} ***** END LICENSE BLOCK *****/
|
}}} ***** END LICENSE BLOCK *****/
|
||||||
|
|
||||||
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
const plugins = {};
|
const plugins = {};
|
||||||
plugins.__proto__ = modules;
|
plugins.__proto__ = modules;
|
||||||
|
|
||||||
@@ -37,6 +39,16 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
const threadManager = Components.classes["@mozilla.org/thread-manager;1"]
|
const threadManager = Components.classes["@mozilla.org/thread-manager;1"]
|
||||||
.getService(Components.interfaces.nsIThreadManager);
|
.getService(Components.interfaces.nsIThreadManager);
|
||||||
|
function Runnable(self, func, args)
|
||||||
|
{
|
||||||
|
this.self = self;
|
||||||
|
this.func = func;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
Runnable.prototype = {
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIRunnable]),
|
||||||
|
run: function () { this.func.apply(this.self, this.args); }
|
||||||
|
};
|
||||||
|
|
||||||
var callbacks = [];
|
var callbacks = [];
|
||||||
var observers = [];
|
var observers = [];
|
||||||
@@ -628,32 +640,20 @@ const liberator = (function () //{{{
|
|||||||
return false; // so you can do: if (...) return liberator.beep();
|
return false; // so you can do: if (...) return liberator.beep();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
callAsync: function (self, func)
|
||||||
|
{
|
||||||
|
let thread = threadManager.newThread(0);
|
||||||
|
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), thread.DISPATCH_NORMAL);
|
||||||
|
},
|
||||||
|
|
||||||
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
||||||
callFunctionInThread: function (thread, func)
|
callFunctionInThread: function (thread, func)
|
||||||
{
|
{
|
||||||
function CallbackEvent(func, args)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
QueryInterface: function (iid)
|
|
||||||
{
|
|
||||||
if (iid.equals(Components.interfaces.nsIRunnable) ||
|
|
||||||
iid.equals(Components.interfaces.nsISupports))
|
|
||||||
return this;
|
|
||||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
||||||
},
|
|
||||||
|
|
||||||
run: function ()
|
|
||||||
{
|
|
||||||
func.apply(window, args);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!thread)
|
if (!thread)
|
||||||
thread = threadManager.newThread(0);
|
thread = threadManager.newThread(0);
|
||||||
|
|
||||||
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
||||||
thread.dispatch(new CallbackEvent(func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
||||||
},
|
},
|
||||||
|
|
||||||
// NOTE: "browser.dom.window.dump.enabled" preference needs to be set
|
// NOTE: "browser.dom.window.dump.enabled" preference needs to be set
|
||||||
@@ -663,7 +663,7 @@ const liberator = (function () //{{{
|
|||||||
message = util.objectToString(message);
|
message = util.objectToString(message);
|
||||||
else
|
else
|
||||||
message += "\n";
|
message += "\n";
|
||||||
dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
|
window.dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
|
||||||
},
|
},
|
||||||
|
|
||||||
dumpStack: function (msg)
|
dumpStack: function (msg)
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
it under any or all of those licenseses.
|
it under any or all of those licenseses.
|
||||||
}}} ***** END LICENSE BLOCK *****/
|
}}} ***** END LICENSE BLOCK *****/
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
||||||
|
|
||||||
function Highlights(name, store, serial)
|
function Highlights(name, store, serial)
|
||||||
{
|
{
|
||||||
const highlightCSS = <![CDATA[
|
const highlightCSS = <![CDATA[
|
||||||
|
|||||||
Reference in New Issue
Block a user