Skip to main content
OP_Prepress
Inspiring
September 28, 2015
Question

Before Close notifier - get the document which is closed?

  • September 28, 2015
  • 4 replies
  • 1502 views

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

4 replies

Participant
June 16, 2025

Same question,i want to get the document name which is closed

Toto RoToTO
Inspiring
February 29, 2016

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.

Inspiring
March 6, 2016

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.

Inspiring
September 29, 2015

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.

Inspiring
September 29, 2015

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.

A. Patterson
Inspiring
September 28, 2015

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.

OP_Prepress
Inspiring
September 29, 2015

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...

A. Patterson
Inspiring
September 29, 2015

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.