1,007
edits
| Line 844: | Line 844: | ||
CmdUtils.CreateCommand( { | CmdUtils.CreateCommand( { | ||
names: ["lookup on freebase"], | |||
arguments: [{ role: "object", | |||
preview: function preview( | nountype: noun_type_freebase_topic, | ||
var text = | label: "topic" }, | ||
preview: function preview( pblock, arguments ) { | |||
var text = arguments.object.text || "any topic"; | |||
pblock.innerHTML = "Go to the Freebase topic page for " + text + "."; | |||
}, | }, | ||
execute: function goToFreebase( | execute: function goToFreebase( arguments ) { | ||
if ( | if ( arguments.object.text ) { | ||
Utils.openUrlInBrowser( "http://www.freebase.com/view" + | Utils.openUrlInBrowser( "http://www.freebase.com/view" + arguments.object.data.id ); | ||
} | } | ||
} | } | ||
| Line 861: | Line 863: | ||
* The parser's callback function expects only one suggestion (not an array of suggestions), so it must be called one time for each suggestion, even if the noun type has multiple suggestions available at the same time (as in the Freebase example above). This is a bit different from the synchronous case, in which the <code>suggest</code> function is expected to return an array. | * The parser's callback function expects only one suggestion (not an array of suggestions), so it must be called one time for each suggestion, even if the noun type has multiple suggestions available at the same time (as in the Freebase example above). This is a bit different from the synchronous case, in which the <code>suggest</code> function is expected to return an array. | ||
* A noun type's <code>suggest</code> function typically returns an empty array when it intends to make asynchronous suggestions, but it can return one or more suggestions synchronously if it has them available | * A noun type's <code>suggest</code> function typically returns an empty array when it intends to make asynchronous suggestions, but it can return one or more suggestions synchronously if it has them available. | ||
* Because the work being done to generate asynchronous suggestions is generally somewhat expensive, and because a noun type's <code>suggest</code> function may be called for every keystroke the user makes, you should probably consider implementing a delay before starting the work and/or caching the work at some level. Ubiquity currently leaves this up to each noun type individually. | * Because the work being done to generate asynchronous suggestions is generally somewhat expensive, and because a noun type's <code>suggest</code> function may be called for every keystroke the user makes, you should probably consider implementing a delay before starting the work and/or caching the work at some level. Ubiquity currently leaves this up to each noun type individually. | ||
* A much more robust implementation of Freebase-derived noun types can be found [http://graynorton.com/ubiquity/freebase-nouns.html here]. | * A much more robust implementation of Freebase-derived noun types can be found [http://graynorton.com/ubiquity/freebase-nouns.html here]. | ||
edits