22 Replies Latest reply on Jun 1, 2012 5:53 AM by TᴀW

    Menu Actions: eventType question. JS

    TᴀW Adobe Community Professional & MVP

      Hi,

       

      (1) How would I add an eventListener for a given menu action that kicks

      in when the menu is dismissed?

       

      Eg

       

      myMenuAction.addListener("onInvoke", function(){alert("Hello");});

       

      adds a listener when it is invoked. But what would be the eventType for

      "dismiss"?

       

      (2) Where are the list of eventTypes documented?

       

      Thanks,

      Ariel

       

        • 1. Re: Menu Actions: eventType question. JS
          John Hawkinson Level 5

          Menus don't get dismissed. They get invoked.

          Do you mean a panel or a dialog or a window?

          There's afterInvoke and of course you can queue an idle event handler and ON_IDLE.

          I guess that means my answer to your List of Eventtypes question is a bad one:

           

          >> Event.reflect.properties.sort().join("\n")

          AFTER_ACTIVATE

          AFTER_CLOSE

          AFTER_CONTEXT_CHANGED

          AFTER_DELETE

          AFTER_EMBED

          AFTER_INVOKE

          AFTER_LINKS_CHANGED

          AFTER_MOVE

          AFTER_NEW

          AFTER_OPEN

          AFTER_PLACE

          AFTER_QUIT

          AFTER_SELECTION_ATTRIBUTE_CHANGED

          AFTER_SELECTION_CHANGED

          AFTER_UNEMBED

          AFTER_UPDATE

          AT_TARGET

          BEFORE_CLOSE

          BEFORE_DEACTIVATE

          BEFORE_DELETE

          BEFORE_DISPLAY

          BEFORE_EMBED

          BEFORE_INVOKE

          BEFORE_MOVE

          BEFORE_PLACE

          BEFORE_QUIT

          BEFORE_UNEMBED

          BEFORE_UPDATE

          BUBBLING_PHASE

          CAPTURING_PHASE

          NOT_DISPATCHING

          ON_INVOKE

          __proto__

          arguments

          arity

          length

          name

          prototype

          prototype

          since it doesn't include many kinds of events. Like IdleEvent.ON_IDLE.

          So I guess you have to look at all the types that end in Event, like Event, IdleEvent, MutationEvent, etc., and enumerate them.

           

          Bah.

          • 2. Re: Menu Actions: eventType question. JS
            TᴀW Adobe Community Professional & MVP

            Thank you John, that's very helpful.

             

            Still, not managing to get anything to work except "onInvoke".

             

            For instance, thinking about the quick apply menu, I'd like to add a

            listener after it is closed/hidden/dismissed or whatever the term would be.

             

            But

             

            app.menuActions.itemByID(18771).addEventListener("AFTER_CLOSE",

            function(){alert("hello")});

             

            ...does nothing.

             

            Ariel

            • 3. Re: Menu Actions: eventType question. JS
              John Hawkinson Level 5

              Still, not managing to get anything to work except "onInvoke".

              For instance, thinking about the quick apply menu, I'd like to add a

              listener after it is closed/hidden/dismissed or whatever the term would be.

              Again, that's because menus don't get dismissed.

              They merely get invoked.

              The Quick Apply panel is not a menu.

               

              I don't think there is anywhere you can attach an event for this.

              What is your actual goal?

              • 4. Re: Menu Actions: eventType question. JS
                [Jongware] Most Valuable Participant

                Arïel, according to my vsn of the Object Model, not every object responds to the same message. AFTER_CLOSE, for example, only applies to Window, StoryWindow, LayoutWindow, Event, DocumentEvent and Application.

                 

                (Huh--that last one ... So you can make a script do something after InDesign closed down.)

                 

                For menuActions, it only lists BEFORE_INVOKE and AFTER_INVOKE.

                 

                OT: Can anyone explain in simple terms what the "bubbleability" of events is all about?

                • 5. Re: Menu Actions: eventType question. JS
                  TᴀW Adobe Community Professional & MVP

                  John,

                   

                  My goal is simple. Quick Apply fails to provide a convenient way to

                  apply a paragraph style and then next style (and so on) in a case where

                  a user has selected multiple paragraphs.

                   

                  My idea was do catch the QuickApply palette when it opens, store the

                  current paragraph styles applied to any selected paragraphs, and catch

                  it again when it closes. Then I would compare the current paragraph

                  styles with the stored values, and if they have changed (meaning that

                  the use has applied a paragraph style via Quick Apply) apply the

                  appropriate nextStyles.

                   

                  So to do that I would need to create an eventListener when the palette

                  or panel or whatever it is is dismissed or closed.

                   

                  Failing that, I have writte a QuickApply lookalike which applies next

                  style. I'll post it soon.

                   

                  Thanks,

                  Ariel

                  • 6. Re: Menu Actions: eventType question. JS
                    TᴀW Adobe Community Professional & MVP

                    Jongware,

                     

                    If your browser provides that information, then I really must figure out

                    how to use it. The ESTK browser has nothing to say about event types.

                     

                    What I understand about event propagation is probably no more than you.

                    I think that it begins with the fact that say you have a Window with a

                    button. If you click the button, then the button generates an onClick

                    event -- but after that, the Window does too (because in fact every

                    click on the button is a click on the Window as well). So that event

                    bubbles up from the button to the Window.

                     

                    So if you have 2 event listeners -- one an onClick for the button, and

                    another an onClick for the window -- it could be that if the button is

                    clicked, you don't want the Window listener to be triggered as well --

                    so then you can stop the propagation of the event.

                     

                    But the details: like which way it goes first (whether from the general

                    to the particular or from particular to general) and other things, I

                    don't know.

                     

                    Ariel

                    • 7. Re: Menu Actions: eventType question. JS
                      Marijan Tompa [tomaxxi] Level 4

                      Ariel,

                       

                      I think you should take a look at "AFTER_SELECTION_ATTRIBUTE_CHANGED" event.

                      This event detects all style changes to selected text/object.

                       

                      Hope that helps.

                       

                      --

                      Marijan (tomaxxi)

                      http://tomaxxi.com

                      • 8. Re: Menu Actions: eventType question. JS
                        Harbs. Level 6

                        [Jongware] wrote:

                         

                        OT: Can anyone explain in simple terms what the "bubbleability" of events is all about?

                        Here's a 30 second crash course in events:

                         

                        The basic concept to grock is the "box model".

                         

                        Basically an app can be looked at as nested boxes -- boxes within boxes. In InDesign terms, the outermost box is the application, inside that is a document, inside that are layout windows. Inside that are all the objects.

                         

                        UI Events generally have two phases. There's the capture phase and the bubbling phase.

                         

                        When you click on something (for example), the click is "captured" from the outermost box inward. So it's first captured by the application, then the document, then the layout window, etc.

                         

                        Once the click (or what-have-you) hit the target (i.e. a button or InDesign object), the event then bubbles back out. It starts at the innermost object and bubbles out to the outermost box (i.e. the application).

                         

                        Theoretically, events can be attached to any box from the innermost one and outwards. If the event is recieved in the capture phase, the outer boxes will catch it first. If it's recieved in the bubbling phase, the inner boxes come first.

                         

                        Let's say we have a "move" event on page items (which does not exist). We could theoretically add event listeners to the object itself (not possible because that level was never implemented), the page (also not possible), the window which holds the object, the document, or the application. If we attach listener to all the boxes, the innermost ones will be executed first. If bubbling can be canceled, the inner boxes can prevent the event from bubbling out to the outer boxes.

                         

                        AFTER_CLOSE refers to windows or documents. The event can be attached to the app because it bubbles out to the app. Not that you can listen for an AFTER_CLOSE event for the app itself...

                        • 9. Re: Menu Actions: eventType question. JS
                          TᴀW Adobe Community Professional & MVP

                          Thanks Harbs. So is there any intrinsic difference between the so-called

                          "capturing" phase and bubbling phase? Or is it just that capturing goes

                          down/into/from general to particular, and bubbling goes the other way?

                          • 10. Re: Menu Actions: eventType question. JS
                            [Jongware] Most Valuable Participant

                            Arïel wrote:

                             

                            Jongware,

                             

                            If your browser provides that information, then I really must figure out

                            how to use it. The ESTK browser has nothing to say about event types.

                             

                            See http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_MenuAction.html -- events of these kind appear under a section of their own in the ESTK (actually, I couldn't say -- they do in its data file) as "class" properties.

                             

                            The online version is good if you know in advance what you are looking for, but when in doubt I always use the CHM version, since you can use "search any text" -- with the provision that your CHM viewer software must support it. For your particular case I only had to check the index, though:

                             

                            omv.PNG

                             

                            (This index is not from the OMV data; it's All Mine™, and I took my time thinking about what and how items should be included. Time well spent, so it appears!)

                            • 11. Re: Menu Actions: eventType question. JS
                              TᴀW Adobe Community Professional & MVP

                              Downloaded the CS4 version i CHM but still can't find anything like the

                              list that John generated.

                              • 12. Re: Menu Actions: eventType question. JS
                                Harbs. Level 6

                                I believe events are generally cancelable in the capturing phase, but less so in the bubbling phase.

                                 

                                Harbs

                                • 13. Re: Menu Actions: eventType question. JS
                                  John Hawkinson Level 5

                                  Downloaded the CS4 version i CHM but still can't find anything like the

                                  list that John generated.

                                  was it not clear how I generated my list? You do it interactively.

                                  • 14. Re: Menu Actions: eventType question. JS
                                    TᴀW Adobe Community Professional & MVP

                                    Yes, I know. But I though it was also in Jongware's reference.

                                     

                                    Thanks,

                                    Ariel

                                    • 15. Re: Menu Actions: eventType question. JS
                                      absqua Level 4

                                      Using the Event Watcher extension linked in this thread will take some of the guesswork out of figuring out which events are actually implemented where and which events are firing. Totally essential in my opinion.

                                       

                                      Jeff

                                      • 16. Re: Menu Actions: eventType question. JS
                                        TᴀW Adobe Community Professional & MVP

                                        Marijan, thank you very much, I'll try it.

                                         

                                        Ariel

                                        • 17. Re: Menu Actions: eventType question. JS
                                          TᴀW Adobe Community Professional & MVP

                                          Marijan,

                                           

                                          What object would I attach that to? I'm trying:

                                           

                                          #targetengine "session"

                                          app.activeDocument.addEventListener("AFTER_SELECTION_ATTRIBUTE_CHANGED",

                                          function(){alert("hello")});

                                           

                                          but not getting any results.

                                           

                                          Thanks,

                                          Ariel

                                          • 18. Re: Menu Actions: eventType question. JS
                                            Marijan Tompa [tomaxxi] Level 4

                                            You have to use it like this:

                                             

                                            app.activeDocument.addEventListener(Event.AFTER_SELECTION_ATTRIBUTE_CHANGED, function(){alert("hello")});

                                             

                                            or this:

                                             

                                            app.activeDocument.addEventListener("afterSelectionAttributeChanged", function(){alert("hello")});

                                             

                                            Hope that helps.

                                             

                                            --

                                            Marijan (tomaxxi)

                                            • 19. Re: Menu Actions: eventType question. JS
                                              TᴀW Adobe Community Professional & MVP

                                              Thanks Marijan,

                                               

                                              The first method throws an error about expecting a string.

                                              The second is okay, but it doesn't work as I understand it should.

                                               

                                              that is, if I set an eventListener as per your example, and then select

                                              some text in a doc, and apply a different style, nothing happens!

                                               

                                              Thanks,

                                              Ariel

                                              • 20. Re: Menu Actions: eventType question. JS
                                                Marijan Tompa [tomaxxi] Level 4

                                                Unfortunately, if you are using preCS5, it's not going to work.

                                                I didn't knew which version do you use.

                                                • 22. Re: Menu Actions: eventType question. JS
                                                  TᴀW Adobe Community Professional & MVP

                                                  Jeff, thanks for the link. I think it's only for CS5+ though.

                                                   

                                                  Anyway, here's my attempt at a simplified quick-apply clone that respects the Next Style settings:

                                                   

                                                  http://www.freelancebookdesign.com/?page_id=461

                                                   

                                                  If I could get evenListening to work (maybe when I upgrade), I'll try the more the sophisticated method detailed above....

                                                   

                                                  Ariel