Skip to main content
Participant
June 4, 2007
Question

Prevent document close by close icon (X)

  • June 4, 2007
  • 4 replies
  • 1478 views
Does anyone know how to prevent a document from being closed if the user clicks on the close icon ("X") on the upper right corner of the document window?

I've established a document signal responder and am receiving the "kBeforeCloseDocSignalResponderService" signal when the close icon is clicked but I've been unable to stop or cancel the close process at this point.

My plug-in manages the opening and closing of certain documents automatically for the user and I don't want the user to prematurely close a document this way. I'm able to disable the close menu item for these documents so they can't be closed that way but I haven't been able to prevent the close icon from closing them.

Any suggestions?
This topic has been closed for replies.

4 replies

Participant
June 8, 2007
That was the piece that I was missing. I got it working now.

Thanks for your help, Mike.

Bob
Participating Frequently
November 16, 2009

Hi

I try to implement the thing described inthis discussion, but it doesn't work.

I implement my own DocFileHandler and my own DocUtils like in the sample incopyfileactions. But my method CanClose is never called.

In my fr-file I do the following:

...

    Class
    {
        kTabFlowDocFileHandlerBoss,
        kInvalidClass,
        {   
            IID_IDOCFILEHANDLER, kTabFlowDocFileHandlerImpl,
        }
   
    }
   
    AddIn
    {
        kUtilsBoss,
        kInvalidClass,
        {
            IID_IDOCUMENTUTILS, kTabFlowDocUtilsImpl,
        }
    };

...

But the AddIn doesn't work. There is a message Plug-in conflict: 2 plug-ins installing same interface!".

What is wrong??? Any ideas?

Thanks

Hans

Legend
November 16, 2009

As a rule of thumb, never AddIn an InDesign IID to an InDesign Boss.

Use your own IID instead of IID_IDOCUMENTUTILS.

Dirk

Inspiring
June 6, 2007
Hi Bob,

The bit you are missing is the following

ErrorUtils::PMSetGlobalErrorCode( kCancel );

Use this to prevent the close from happening.

Mike.
Participant
June 5, 2007
Thanks for the suggestion Mike. I tried it and it looks like a better solution for enabling/disabling the various file menu items (Close in my case).

But it didn't solve the problem with the Close icon (X) on the upper right corner of the document window. When this is clicked there is not a call to the IDocFileHandler.CanClose() command. It goes straight to the IDocFileHandler.Close() command. Since I implemented it using a shadow interface so I could still call the default functions when I didn't want to override them I thought I would try commenting out the Close() call for the default interface as a test. The document still closed.

Thus I am still unable to prevent the close via the Close icon (X) button.

Bob
Inspiring
June 5, 2007
Hi Bob,

What you need to do is implement your own IDocFileHandler implementation to handle the close.

A good example of this exists in the CS2 SDK here {SDKROOT}/source/sdksamples/incopyfileactions/

The example is for InCopy, but the techniques lend them self to InDesign too.

With this you should be able to achieve a slicker solution which doesn't involve disabling menus etc..

HTH

Mike.