Created
February 14, 2009 00:29
-
-
Save SamHasler/64187 to your computer and use it in GitHub Desktop.
Now compatible with Ubiquity 0.5 / Parser 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Components.utils.import("resource://ubiquity/modules/setup.js"); | |
CmdUtils.CreateCommand( | |
{names: ["copy-command"] | |
,icon: "chrome://ubiquity/skin/icons/favicon.ico" | |
,homepage: "http://gist.github.com/64187" | |
,author: { name: "Sam Hasler", email: "ubiquity at haslers.info"} | |
,license: "GPL" | |
,description: "Clone a ubiquity command feed by copying it to the Command Editor" | |
,help: "Select one of your installed commands from the suggestions and the code for it will be appended to the command editor" | |
,arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'}] | |
,preview: function( pblock, args) { | |
if (args.input.text) { | |
var html = ""; | |
//find the feed for the command | |
var feedMgr = UbiquitySetup.createServices().feedManager; | |
var subfeeds = feedMgr.getSubscribedFeeds(); | |
for ( var i = 0 ; i < subfeeds.length ; i++){ | |
var feed = subfeeds[i]; | |
for (var prop in feed.commands) { | |
if(prop == args.input.text) { | |
html += feed.getCode(); | |
break; | |
} | |
} | |
if (html) break; | |
} | |
pblock.innerHTML = "copy <b>" + args.input.text + "</b> command to command editor<br>" + | |
"<br>Code:<br><pre>" + html +"</pre>"; | |
} else { | |
pblock.innerHTML = "copy a command to command editor.<br>Please start typing the name of a command"; | |
} | |
} | |
,execute: function(args) { | |
cmdObj = args.input.data; | |
var code = '\n\n//Note: This command was automatically copied by the copy-command command.\n'; | |
//find the feed for the command | |
var feedMgr = UbiquitySetup.createServices().feedManager; | |
var subfeeds = feedMgr.getSubscribedFeeds(); | |
for ( var i = 0 ; i < subfeeds.length ; i++){ | |
var feed = subfeeds[i]; | |
for (var prop in feed.commands) { | |
if(prop == args.input.text) { | |
code += feed.getCode(); | |
} | |
} | |
} | |
//append the code to Ubiqity's command editor | |
CmdUtils.UserCode.appendCode(code); | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment