73
edits
(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( | execute: function tab_execute(args) { | ||
var | // must be delayed because Ubiquity restores the focus on close | ||
Utils.setTimeout(function delayedFocus() { | |||
var tab = args.object.data; | |||
tab._window._window.focus(); | |||
tab.focus(); | |||
}, 99); | |||
}, | }, | ||
preview: function( pblock, | preview: function tab_preview(pblock, args) { | ||
var tabName = | var tabName = args.object.text; | ||
if( tabName | if (tabName) { | ||
var msg = "Changes to <strong>${tab}</strong> tab."; | |||
pblock.innerHTML = _(msg, {tab: tabName}); | |||
} | |||
else | else pblock.innerHTML = _("Switch to a tab by name."); | ||
} | } | ||
}) | }); | ||
</pre> | </pre> | ||
edits