Labs/Ubiquity/Ubiquity 0.5 Author Tutorial: Difference between revisions

Jump to navigation Jump to search
Made the code modern (and actually work), part 2.
(Made the code modern (and actually work).)
(Made the code modern (and actually work), part 2.)
Line 743: Line 743:
The input objects that our <code>suggest()</code> method generates are the same objects that will eventually get passed in to the <code>execute()</code> and <code>preview()</code> methods of any commands that use this noun type.
The input objects that our <code>suggest()</code> method generates are the same objects that will eventually get passed in to the <code>execute()</code> and <code>preview()</code> methods of any commands that use this noun type.


== Switching Tabs: The Command ==
=== Switching Tabs: The Command ===


Now that we are armed with the tab noun-type, it is easy to make the tab-switching command. Again, we use FUEL to focus the selected tab.
Now that we are armed with the tab noun-type, it is easy to make the tab-switching command. Again, we use FUEL to focus the selected tab.
Line 749: Line 749:
<pre>
<pre>
CmdUtils.CreateCommand({
CmdUtils.CreateCommand({
   names: ["tab"],
   names: ["switch tab"],
   arguments: {object: noun_type_tab},
   arguments: {object: noun_type_tab},


   execute: function( arguments ) {
   execute: function tab_execute(args) {
     var tabName = arguments.object.text;
     // must be delayed because Ubiquity restores the focus on close
    var tabs = noun_type_tab.getTabs();
    Utils.setTimeout(function delayedFocus() {
    tabs[tabName]._window.focus();
      var tab = args.object.data;
     tabs[tabName].focus();
      tab._window._window.focus();
      tab.focus();
     }, 99);
   },
   },


   preview: function( pblock, arguments ) {
   preview: function tab_preview(pblock, args) {
     var tabName = arguments.object.text;
     var tabName = args.object.text;
     if( tabName.length > 1 ){
     if (tabName) {
        var msg = "Changes to <b style=\"color:yellow\">${tab}</b> tab.";
      var msg = "Changes to <strong>${tab}</strong> tab.";
        pblock.innerHTML = _(msg, {tab: tabName});
      pblock.innerHTML = _(msg, {tab: tabName});
    }
    }
     else
     else pblock.innerHTML = _("Switch to a tab by name.");
      pblock.innerHTML = _("Switch to a tab by name.");
   }
   }
})
});
</pre>
</pre>


73

edits

Navigation menu