MindManager cannot find event api

liuxiansheng shared this question 10 months ago
Answered

I am currently developing a MindManager plugin, and my current requirement is that when opening a file, if the file name includes 'xxx', I want to automatically display a message box. However, I'm facing difficulties as I can't find the event for opening a file in the API. Please help me, and I am immensely grateful.

Replies (1)

photo
1

Hello

Events are described in the API documentation at https://www.mindmanager.com/en/pages/developers/api/22/#Welcome.html

There are three steps for handling an event in an Add-in.

  1. Allocate an event object
  2. Configure the event object to listen for certain events
  3. Handle its "fire" event

The examples below are in VB but can be converted to another syntax.

1. Allocate an event object

Private WithEvents m__EventDocAdd As MM.Event = Nothing

It is important to use the "WithEvents" keyword to ensure that this object can raise events, otherwise nothing happens.

2. Configure the event object

If m__EventDocAdd Is Nothing Then

Try

i_Mask = MM.MmDocumentEventFlags.mmEventFlagDocumentAdded + MM.MmDocumentEventFlags.mmEventFlagDocumentOpened

m__EventDocAdd = m__MindManager.Events.AddDocumentEvent(i_Mask, False, True, Nothing) ' notify after adding

Catch o_Ex As Exception

ErrorFormShow(System.Reflection.MethodInfo.GetCurrentMethod.Name, String.Format("Mask {0}", i_Mask.ToString), o_Ex)

m__EventDocAdd = Nothing

End Try

End If

In the above code, "MM" is the MindManager Interop interface. i_Mask is a long integer. You can combine event flags. The event object configured above will fire when a new document is created, or when an existing document is opened.

3. Handle the event

Friend Sub p_EventDocAdd_Fire(ByVal eventFlag As Integer, ByVal time As MM.MmEventTime, ByVal pSource As Object, ByRef pExtra As Object) Handles m__EventDocAdd.Fire

The signature of the event handler must match otherwise a syntax error is thrown. The handler receives a flag to indicate whether the callback is occurring before or after the event, which applies to some of the events such as Save. It passes the relevant object as "pSource", which will need to be translated to the correct object type depending on the event. In this case, the object type is a Document.

If your requirements are fairly simple and could be handled with a macro instead of an Add-in, you could use App Studio for MindManager instead This allows you to connect a macro to an event without needing to access the MindManager API or writing an Add-in. Not all events are supported, but new document and document open events are.

photo
1

Thank you for your reply, which one is document open events, I didn't find it, this problem has been bothering me for a long time!

photo
1

The document open event is received by setting MmDocumentEventFlags.mmEventFlagDocumentOpened in the event object, as shown in the example.

photo
1

The above example is written in vb, can you give an example in c#, I'm not very good at programming and I didn't write the code correctly with the help of GPT, thanks a lot

photo
1

Unfortunately I don't have these examples in C#.

It will be a significant challenge to write a reliable Add-in using ChatGPT.

---