Labs/Ubiquity/Ubiquity Source Tip Author Tutorial: Difference between revisions

Jump to navigation Jump to search
Line 85: Line 85:
In the example above, we simply call <code>displayMessage()</code>, which displays the given message in whichever way the operating system can.
In the example above, we simply call <code>displayMessage()</code>, which displays the given message in whichever way the operating system can.


== Using CreateCommand ==


For commands that are more complicated than our simple "hello-world" command, you can use the helper function <code>CmdUtils.CreateCommand()</code>, which takes an options dictionary. To redo the "hello-world" command using the convenience function, we'd write:
There are a number of other useful functions in the <code>CmdUtils</code> namespace. We don't yet have full documentation for these commands, but you'll get a sense of the useful ones in this tutorial. For more detailed information, take a look at [http://hg.toolness.com/ubiquity-firefox/file/9a6c9935da9f/ubiquity/chrome/content/cmdutils.js cmdutils.js].
 
<pre>
CmdUtils.CreateCommand({
  name: "hello-world",
  execute: function() {
    displayMessage( "Hello, World!" );
  }
})
</pre>
 
This may not seem to be much of a win (and it isn't for simple commands) but as the commands become more complex, you'll see that it helps a lot. For one, you can name the command more freely with the method&mdash;unicode non-English characters are now fair game.
 
There are a number of other useful functions in the CmdUtils namespace. We don't yet have full documentation for these commands, but you'll get a sense of the useful ones in this tutorial. For more detailed information, take a look at [http://hg.toolness.com/ubiquity-firefox/file/9a6c9935da9f/ubiquity/chrome/content/cmdutils.js cmdutils.js].


== Adding a Preview ==
== Adding a Preview ==
1,007

edits

Navigation menu