10 Replies Latest reply on Mar 6, 2016 4:06 AM by LeoTaro

    Before Close notifier - get the document which is closed?

    OP_Prepress Level 1

      Hello everybody,

       

      I am struggeling with following problem.

       

      I need to know when a document is closed and in some cases I need to suppress the "Save changes...before closing?" dialogue, an modify the document before closing.

      Therefor I use the "AI Command Notifier: Before Close" (kAICloseCommandPreNotifierStr) cause this one is sent before the dialogue. Then I set SetDocumentModified(false) and the dialogue is suppressed.

      BUT:

      When multiple documents are opened and I close another document than the active one. All actions are applied to the current document (of course), which is not the one going to be closed.

      So the big question is: Is it possible to get to know which document is closed (were the is clicked in the document tabs) and how?

       

      I am also using the kAIDocumentAboutToCloseNotifier and I think here I can get the AIDocumentHandle out of the notifyData - unfortunately this is sent to late for my need.And the kAICloseCommandPreNotifierStr has NULL as notifyData.

       

      Any ideas?

       

      Thanks in advance,

      Patrick

        • 1. Re: Before Close notifier - get the document which is closed?
          A. Patterson Level 4

          I haven't used that notifier so I can't say if this will work, but the kAIDocumentClosedNotifier notifier includes the AIDocumentHandle in the notifyData member; you just have to cast it. It's possible that handle is sent along with the 'before close' notifier.

           

          Failing that, you can try and get the current document; I guess it will depend on if clicking on the X on the tab makes the document the active document before it sends that message or not.

          • 2. Re: Before Close notifier - get the document which is closed?
            OP_Prepress Level 1

            Unfortunately the kAIDocumentClosedNotifier is sent to late and worse, when clicking X the current document is not the one beeing closed when "before close" is sent.

            But I found the SetInteractionAllowed function of the ASUserInteractionSuite - with this one I can suppress the "Save ... before close" dialogue. Unfortunately when suppressing the dialogue with this, the document is saved automatically - what i actually wanted to prevent.

            But this could be the right direction...

            • 3. Re: Before Close notifier - get the document which is closed?
              A. Patterson Level 4

              No, sorry, I guess I wasn't clear

               

              I know the kAIDocumentClosedNotifier is too late; I was just saying that it includes the document handle in its notifyData member (of the notifier message data struct). Maybe the 'Before Close' notifier you're using includes the document handle in the same place? It's bit of a long shot, but worth looking at. If notifyData is empty, that'll clinch that it's not, but by looking at it in the debugger you may be able to tell if it's a document handle or not; and if so, you can cast & use it.

              • 4. Re: Before Close notifier - get the document which is closed?
                LeoTaro Level 4

                As you say the kAICloseCommandPreNotifierStr notifier has NULL as notifyData so you can't get the doc from that.

                 

                If I understand it correctly when a document is closed you want to look at the document data and in certain cases suppress the "Save Changes" dialog and allow the document to be closed without being saved by calling SetDocumentModified(false).

                 

                As there doesn't seem to be a way to get the document being closed when you click on the close button of a document that isn't the current document, I think you will have to implement a hacky workaround.

                 

                One solution might be when you get the kAICloseCommandPreNotifierStr notifier, go through all the open documents using the DocumentListSuite. For any documents that are modified and you want to suppress the "Save Changes" dialog, call SetDocumentModified(false). You probably want to restore the modified state of any documents that don't get closed after the close. I would set a flag and then look for that in the kAIDocumentChangedNotifier notifier as the kAIDocumentClosedNotifier notifier won't get called if the user cancels.

                 

                • 5. Re: Before Close notifier - get the document which is closed?
                  LeoTaro Level 4

                  Just reread your question and see that you also need to modify the doc. You may be able to do that in the kAIDocumentAboutToCloseNotifier. Otherwise you would have to modify all the relevant docs in the kAICloseCommandPreNotifierStr notifier and then undo the changes for docs that aren't closed.

                  • 6. Re: Before Close notifier - get the document which is closed?
                    OP_Prepress Level 1

                    Iterating through all open docuements seems to be an good workaround! Due to the fact, that all modifications I have to apply, are related to the document name the modifications done with docs not beeing closed can easyle be reset.

                    I will have a closer look after my holiday

                     

                    Yet I suppress the save dialog with ASUserInteractionSuite during kAICloseCommandPreNotifierStr which actually works well. And i apply all my changes in the kAIDocumentAboutToCloseNotifier when I know the doc beeing closed.

                    The only problem is, when closing a doc where no modifications are needed and the sace dialog should show up - it doesn't.

                     

                    Thanks for all the answers!

                    • 7. Re: Before Close notifier - get the document which is closed?
                      LeoTaro Level 4

                      When you iterate through the documents, you will need to make each document the current document in order to get and set the document information. Not sure if the user will see the current document changing.

                       

                      You have to be very careful when changing the interaction level using ASUserInteractionSuite. The interaction level is saved in the user preferences, so if you turn it off and don't turn it back on again, the user will not see any popup dialogs even if they restart Illustrator. Also you need to get the current state and restore this afterwards, as interaction is often turned off in scripts.

                      • 8. Re: Before Close notifier - get the document which is closed?
                        A. Patterson Level 4

                        LeoTaro wrote:

                         

                        When you iterate through the documents, you will need to make each document the current document in order to get and set the document information. Not sure if the user will see the current document changing.

                        They won't; I use the activate document functionality in MAPublisher and you can't tell when I do.

                        • 9. Re: Before Close notifier - get the document which is closed?
                          Toto RoToTO Level 3

                          Hi,

                          you should try something like this:

                          ASErr Pugin:Notify(AINotifierMessage* message)

                          {

                               if(message->notifier == fPlugPlugDocumentClosedNotifier)

                               {

                                    AIDocumentHandle document = (AIDocumentHandle)message->notifyData;

                                    //TODO: whatever you need here!

                               }

                          }

                           

                          Thomas.

                          • 10. Re: Before Close notifier - get the document which is closed?
                            LeoTaro Level 4

                            He needs to get the document in the before close notifier because he wants to sometimes suppress the save changes dialog, which has already been shown when you get fPlugPlugDocumentClosedNotifier.