Determine closing a document via MindManager API

Tom R. shared this question 2 months ago
Answered

In my AddIn, I use document events and I have the following question:
The mmEventFlagDocumentClosed is only been issued on-before. Is there a way to determine that the document is closed? Like an ActiveDocumentChanged event or even a document tab close event?

Replies (1)

photo
1

Hello Tom

I guess there is no DocumentClosed event issued on-after because the event handler cannot pass a document pointer. The document pointer will be invalid when the document is closed.

If your add-in still has a document pointer, you could iterate over the documents collection, looking for your pointer. In WWB script this would look like:


Function DocumentIsClosed(ByVal m_Doc as Document) as Boolean
  Dim m_This as Document

  For Each m_This in AllDocuments
    if m_This Is m_Doc Then Return False
  Next
  Return True

End Function

photo
1

Hi Nick,

Thanks for the information. I thought so too. I hoped there would be an activedocumentchanged event or an tabclose event that I could use instead.

With tabs I mean open documents (see Image below)

957652dcde27bed09e40fbbfe9ac1d0c

photo
1

There is a Document Activated event which fires when a document receives focus. This would fire if a document is closed, but only if it is not the last document to close. It does not indicate that the previous document has been closed, only that it has lost focus.

photo
1

Also, you could use the Idle event to monitor the documents count in the AllDocuments collection. If it goes down, then you would know that a document tab had been closed and could verify the remaining documents to find out which one.

photo
1

Thanks, Nick. This should help. I will try to use the idle event.

photo
Leave a Comment
 
Attach a file