Skip navigation
thinkink_es
Currently Being Moderated

eventListener. Copy/Paste detection. POSIBLE???

Jun 21, 2012 3:18 AM

It's posible a custom eventListener to detect copy and paste.

 

myDocument.eventListeners.add("beforePaste", myBeforePasteFunction);

 
Replies
  • Currently Being Moderated
    Jun 21, 2012 4:52 AM   in reply to thinkink_es

    "beforePaste" is not listed anywhere in the Help as a supported event. The current list is beforeClose, beforeDeactivate, beforeDelete, beforeDisplay, beforeEmbed, beforeExport, beforeImport, beforeInvoke, beforeMove, beforeNew, beforeOpen, beforePlace, beforePrint, beforeQuit, beforeRevert, beforeSave, beforeSaveACopy, beforeSaveAs, befureUnembed, and beforeUpdate.

     

    See http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_Event.html for the complete list of events (CS5.5, but it seems CS6 has changed nothing). Note that not all events are applicable to all objects. Select one of the objects in the "parent" list to see which ones are supported for that. If an object supports events, these are listed under the sub-heading "Class", below "Properties".

     

    See for example http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_Link.html. This one contains "AFTER_DELETE" and "BEFORE_DELETE", but that only applies to links, and not to any other object such as text or pages.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 5:49 AM   in reply to thinkink_es

    You can monitor copy/paste by attaching event listeners to menu items of "Copy" and "Paste" commands.

     

    Something like this:

     

    #targetengine "tomaxxiTEST"
     
    ( function () {
        
        main ();
        
        function main () {
            var
                beforeCopy = app.menuActions.itemByID ( 270 ).addEventListener ( "beforeInvoke", eventHandler ), // COPY
                afterCopy = app.menuActions.itemByID ( 270 ).addEventListener ( "afterInvoke", eventHandler ), // COPY
     
                beforeCut = app.menuActions.itemByID ( 269 ).addEventListener ( "beforeInvoke", eventHandler ), // CUT
                afterCut = app.menuActions.itemByID ( 269 ).addEventListener ( "afterInvoke", eventHandler ), // CUT
     
                beforeClear = app.menuActions.itemByID ( 272 ).addEventListener ( "beforeInvoke", eventHandler ), // CLEAR
                afterClear = app.menuActions.itemByID ( 272 ).addEventListener ( "afterInvoke", eventHandler ), // CLEAR
     
                beforePaste = app.menuActions.itemByID ( 271 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE
                afterPaste = app.menuActions.itemByID ( 271 ).addEventListener ( "afterInvoke", eventHandler ), // PASTE
     
                beforePasteInPlace = app.menuActions.itemByID ( 273 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE IN PLACE
                afterPasteInPlace = app.menuActions.itemByID ( 273 ).addEventListener ( "afterInvoke", eventHandler ), // PASTE IN PLACE
     
                beforePasteInto = app.menuActions.itemByID ( 274 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE INTO
                afterPasteInto = app.menuActions.itemByID ( 274 ).addEventListener ( "afterInvoke", eventHandler ); // PASTE INTO
        }
        
        function eventHandler ( evt ) {
            alert ( evt.eventType + " | " + evt.currentTarget.name );
        }
     
    } ) ();
    

     

    Hope that helps.

     

    --

    Marijan (tomaxxi)

    http://tomaxxi.com

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 12:17 PM   in reply to thinkink_es

    See also the 2nd snippet at:

     

    http://www.indiscripts.com/post/2010/02/how-to-create-your-own-indesig n-menus

     

    which illustrates how to 'spy' the Paste action. The same approach can be used for Copy/Cut/etc. as Marijan showed.

     

    @+

    Marc

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 11:57 AM   in reply to Marijan Tompa

    I know this is an older post, but where can I find the id's of the menu actions? Is there a list of them somewhere?

     

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 12:31 PM   in reply to bduffy323

    This will do the job:

     

    var
        menuActions = app.menuActions,
        menuActionsLength = menuActions.length,
        menuActionsList = [],
        newDoc = app.documents.add (),
        docPage = newDoc.pages [ 0 ],
        docMargins = docPage.marginPreferences,
        actionsTextFrameBounds = [
            docPage.bounds [ 0 ] + docMargins.top,
            docPage.bounds [ 1 ] + docMargins.left,
            docPage.bounds [ 2 ] - docMargins.bottom,
            docPage.bounds [ 3 ] - docMargins.right, ],
        actionsTextFrame = newDoc.pages [ 0 ].textFrames.add ( { geometricBounds : actionsTextFrameBounds } ),
        actionsTable = actionsTextFrame.insertionPoints [ 0 ].tables.add ( { columnCount : 3, bodyRowCount : menuActionsLength } ),
        i = 0;
     
    for ( i ; i < menuActionsLength ; i++ )
        menuActionsList.push ( menuActions [ i ].name.toString () ),
        menuActionsList.push ( menuActions [ i ].area.toString () ),
        menuActionsList.push ( menuActions [ i ].id.toString () );
     
    actionsTable.contents = menuActionsList;
    

     

    HTH.

     

    --

    Marijan (tomaxxi)

    http://tomaxxi.com

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 12:43 PM   in reply to Marijan Tompa

    Thank you! that did indeed get the job done.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points