73
edits
Changes
Made the code modern (and actually work).
// Returns all tabs from all windows.
getTabs: functionnt_tab_getTabs(){ var tabs = {};return [tab foreach ( var j=0; j < win in Application.windows.length; j++ ) { var window = Application.windows[j]; for each (var i = 0; i < windowtab in win.tabs.length; i++) { var tab = window.tabs[i]; tabs[tab.document.title] = tab; } } return tabs;
},
suggest: functionnt_tab_suggest( text, html, callback , selectionIndices) { var suggestions textLC = []text.toLowerCase(); var tabs = noun_type_tabreturn [CmdUtils.getTabsmakeSugg(tab.document.title, null, tab); //TODO: implement a better match algorithm for each ( var tabName tab in tabs this.getTabs()) { if (tabName~tab.match(text, "i")) suggestionsdocument.push( CmdUtilstitle.makeSuggtoLowerCase(tabName) ); } // Return a list of input objects, limited to at most five: return suggestions.spliceindexOf(0, 5textLC))];
}
};
</pre>
We use the convenience function <code>CmdUtils.makeSugg()</code> to generate an
input object of the type that the Ubiquity parser expects. The full signature of this function is:
<pre>
CmdUtils.makeSugg( text, html, data , score, selectionIndices);
</pre>
If the text or html input is very long, <code>makeSugg()</code> generates a summary for us, and puts it in the <code>.summary</code> attribute of the input object.
We could have accomplished mostly the same thing without calling <code>makeSugg()</code> by returning a list of anonymous objects like these:
<pre>
{ text: tabName,
html: Utils.escapeHtml(tabName), data: nulltab, summary: Utils.escapeHtml(tabName ) };
</pre>
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 ==