05-31-2009, 08:08 PM
i made some progress.
here is an example firefox content menu script
the lines
this.mItem.setAttribute("label", "Tweet! this");
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec], selection, "context"];
are very important.
1. set context menu label
2. everything after "A", will be passed to a qm function.
replace "+ff2qm+" with your own function.
your function has to be enclosed with + !!!
you also need to replace LaunchQM to something else.
here is an example firefox content menu script
var LaunchQM = {
mSchemes: ["file", "ftp", "http", "https"],
init: function()
{
this.mItem = document.createElement("menuitem");
this.mItem.setAttribute("label", "Tweet! this");
this.mItem.setAttribute("accesskey", "q");
document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { LaunchQM.onPopupShowing(this); }, false);
},
onPopupShowing: function(aPopup)
{
aPopup.insertBefore(this.mItem, document.getElementById("context-sep-" + ((gContextMenu.onLink)?"open":"stop")));
this.mItem.setAttribute("oncommand", "LaunchQM.launch(" + ((gContextMenu.onLink)?"gContextMenu.linkURI":"gBrowser.currentURI") + ");");
//this.mItem.hidden = !gContextMenu.onLink && (gContextMenu.isTextSelected || gContextMenu.onImage || gContextMenu.onTextInput);
this.mItem.setAttribute("disabled", this.mItem.hidden || !this.isSupported((gContextMenu.onLink)?gContextMenu.linkURI:gBrowser.currentURI));
},
launch: function(aURI, aApp)
{
if (!this.isSupported(aURI))
{
throw new Error("LaunchQM: unsupported URI scheme '" + aURI.scheme + "'!");
}
var qm = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
try
{
var regkey = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
regkey.open(Components.interfaces.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + (aApp || "QM.EXE"), Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
iexplore.initWithPath(regkey.readStringValue(""));
regkey.close();
}
catch (ex)
{
qm.initWithPath((Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get("PROGRAMFILES") || "C:\\Program Files") + "\\Quick Macros 2\\qm.exe");
}
var focusedWindow = document.commandDispatcher.focusedWindow;
var winWrapper = new XPCNativeWrapper(focusedWindow, "document", "getSelection()");
var selection = winWrapper.getSelection().toString();
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(qm);
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec], selection, "context"];
//var args = ["Q","+","M","+ff2qm+","A",str,"context"];
process.run(false, args, args.length);
},
isSupported: function(aURI)
{
return this.mSchemes.indexOf(aURI.scheme) > -1;
}
};
LaunchQM.init();
the lines
this.mItem.setAttribute("label", "Tweet! this");
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec], selection, "context"];
are very important.
1. set context menu label
2. everything after "A", will be passed to a qm function.
replace "+ff2qm+" with your own function.
your function has to be enclosed with + !!!
you also need to replace LaunchQM to something else.