1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 12:22:27 +01:00

Generate file completions asynchronously

This commit is contained in:
Kris Maglione
2008-11-27 11:58:50 +00:00
parent bfc1031534
commit 4c8e5ac3b0
3 changed files with 29 additions and 29 deletions

View File

@@ -187,7 +187,6 @@ CompletionContext.prototype = {
},
set generate(arg)
{
let self = this;
this.hasItems = true;
this._generate = arg;
if (this.background && this.regenerate)
@@ -195,12 +194,14 @@ CompletionContext.prototype = {
let lock = {};
this.cache.backgroundLock = lock;
this.incomplete = true;
liberator.callFunctionInThread(null, function () {
let items = self.generate();
if (self.cache.backgroundLock != lock)
liberator.dump({name: this.name, length: this.items.length});
let now = Date.now();
liberator.callAsync(this, function () {
let items = this.generate();
if (this.cache.backgroundLock != lock)
return;
self.incomplete = false;
self.completions = items;
this.incomplete = false;
this.completions = items;
});
}
},
@@ -231,7 +232,7 @@ CompletionContext.prototype = {
return this.cache.filtered;
this.cache.rows = [];
let items = this.completions;
if (this.generate)
if (this.generate && !this.background)
{
// XXX
let updateAsync = this.updateAsync;
@@ -1230,6 +1231,7 @@ function Completion() //{{{
context.advance(dir.length);
context.keys = { text: 0, description: 1, icon: 2 };
context.anchored = true;
context.background = true;
context.key = dir;
context.generate = function generate_file()
{

View 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.
}}} ***** END LICENSE BLOCK *****/
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const plugins = {};
plugins.__proto__ = modules;
@@ -37,6 +39,16 @@ const liberator = (function () //{{{
const threadManager = Components.classes["@mozilla.org/thread-manager;1"]
.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 observers = [];
@@ -628,32 +640,20 @@ const liberator = (function () //{{{
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
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)
thread = threadManager.newThread(0);
// 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
@@ -663,7 +663,7 @@ const liberator = (function () //{{{
message = util.objectToString(message);
else
message += "\n";
dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
window.dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
},
dumpStack: function (msg)

View File

@@ -6,8 +6,6 @@
it under any or all of those licenseses.
}}} ***** END LICENSE BLOCK *****/
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function Highlights(name, store, serial)
{
const highlightCSS = <![CDATA[