Bug 307774 - Capture drag-drop and pasting of text and switch to multiline input if appropriate.

ChatZilla only.
r=silver
p=rdmsoft@bugs.rdmsoft.com (Robert Marshall)
This commit is contained in:
silver%warwickcompsoc.co.uk 2006-03-25 16:52:44 +00:00
Родитель dff59e32ae
Коммит 6b0072c283
2 изменённых файлов: 75 добавлений и 2 удалений

Просмотреть файл

@ -118,6 +118,10 @@ function initHandlers()
window.addEventListener("blur", onWindowBlue, true);
client.inputPopup = null;
// Should fail silently pre-moz1.4
doCommandWithParams("cmd_clipboardDragDropHook",
{addhook: CopyPasteHandler});
}
function onClose()
@ -2865,3 +2869,50 @@ function my_dccfiledisconnect(e)
this.display(msg, "DCC-FILE");
}
var CopyPasteHandler = new Object();
CopyPasteHandler.onPasteOrDrop =
function phand_onpaste(e, data)
{
// XXXbug 329487: The effect of onPasteOrDrop's return value is actually the
// exact opposite of the definition in the IDL.
// Don't mess with the multiline box at all.
if (client.prefs["multiline"])
return true;
var str = new Object();
var strlen = new Object();
data.getTransferData("text/unicode", str, strlen);
str.value.QueryInterface(Components.interfaces.nsISupportsString);
str.value.data = str.value.data.replace(/(^\s*[\r\n]+|[\r\n]+\s*$)/g, "");
if (str.value.data.indexOf("\n") == -1)
{
// If, after stripping leading/trailing empty lines, the string is a
// single line, put it back in the transferable and return.
data.setTransferData("text/unicode", str.value,
str.value.data.length * 2);
return true;
}
// If it's a drop, move the text cursor to the mouse position.
if (e && ("rangeOffset" in e))
client.input.setSelectionRange(e.rangeOffset, e.rangeOffset);
str = client.input.value.substr(0, client.input.selectionStart) +
str.value.data + client.input.value.substr(client.input.selectionEnd);
client.prefs["multiline"] = true;
client.input.value = str;
return false;
}
CopyPasteHandler.QueryInterface =
function phand_qi(iid)
{
if (iid.equals(Components.interfaces.nsISupports) ||
iid.equals(Components.interfaces.nsIClipboardDragDropHooks))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}

Просмотреть файл

@ -2005,7 +2005,7 @@ function addDynamicRule (rule)
function getCommandEnabled(command)
{
try {
var dispatcher = top.document.commandDispatcher;
var dispatcher = document.commandDispatcher;
var controller = dispatcher.getControllerForCommand(command);
return controller.isCommandEnabled(command);
@ -2019,7 +2019,7 @@ function getCommandEnabled(command)
function doCommand(command)
{
try {
var dispatcher = top.document.commandDispatcher;
var dispatcher = document.commandDispatcher;
var controller = dispatcher.getControllerForCommand(command);
if (controller && controller.isCommandEnabled(command))
controller.doCommand(command);
@ -2029,6 +2029,28 @@ function doCommand(command)
}
}
function doCommandWithParams(command, params)
{
try {
var dispatcher = document.commandDispatcher;
var controller = dispatcher.getControllerForCommand(command);
controller.QueryInterface(Components.interfaces.nsICommandController);
if (!controller || !controller.isCommandEnabled(command))
return;
var cmdparams = newObject("@mozilla.org/embedcomp/command-params;1",
"nsICommandParams");
for (var i in params)
cmdparams.setISupportsValue(i, params[i]);
controller.doCommandWithParams(command, cmdparams);
}
catch (e)
{
}
}
var testURLs =
["irc:", "irc://", "irc:///", "irc:///help", "irc:///help,needkey",
"irc://irc.foo.org", "irc://foo:6666",