-
1. Re: Can beforeInvoke event listener cancel the Paste event?
Mac_rk Jul 25, 2013 1:57 AM (in response to RobertKyle)see below thread
-
2. Re: Can beforeInvoke event listener cancel the Paste event?
RobertKyle Jul 26, 2013 12:05 PM (in response to Mac_rk)I saw that thread (and borrowed heavily from it) before I posted. I've got no problem detecting the Paste event; I'm puzzled about the handler that fires after Paste is detected.
Here's what I have so far:
#targetengine "session"
var beforePaste = app.menuActions.itemByID ( 271 ).addEventListener ( "beforeInvoke", eventHandler );// PASTE
var afterPaste = app.menuActions.itemByID ( 271 ).addEventListener ( "afterInvoke", eventHandler ); // PASTE
var redoPaste = false;
function eventHandler ( evt ) {
if (evt.eventType == "beforeInvoke") {
redoPaste = false;
var elementType = app.selection[0].parentStory.storyTitle;
if (elementType !="Body") {
var theAnswer = confirm ("You're pasting into a " + elementType + " element and may wipe out the styles applied to that element. Do you want to use Paste without formatting instead?",false,"Think about it")
if (theAnswer == true){
redoPaste = true;
}
} // element == "Body"
} else { // afterInvoke
if (redoPaste == true) {
app.activeDocument.undo();
app.pasteWithoutFormatting();
}
}
}
Note: This script actually runs in InCopy where storyTitle might be a string like "Caption", "Headline" or "Body." The point is that the Caption and Headline fields already have styles assigned to them, and we don't want users to Paste in the wrong style.So the beforePaste event sets a flag based on the current selection.When the flag is up, the afterPaste event unDoes the Paste and calls app.pasteWithoutFormatting().
Seems to me that this process might be more robust if I could cancel the Paste event rather than unDoing it.

