Pages: 1
Author Topic: Event to trigger after macro/command clicked  (Read 1795 times)

Posts: 17

« on: August 02, 2016, 06:42:46 AM »

Using XMetaL version:

I am using a custom toolbar inside XMetaL. I would like to have some code execute whenever any of these macros are clicked/executed, so that I can then check the type of element inserted and mark the "audience" attribute appropriately (for conditional content).

I did think about simply calling a custom function in the mcr file, but then I'd have to write the code to do so in every macro section, for new macros, etc. - I would prefer inserting code at a common execution point.

Any ideas how I could do this?

« Last Edit: August 02, 2016, 06:45:16 AM by ChrisTMH » Logged
Derek Read
Program Manager (XMetaL)

Posts: 2621

« Reply #1 on: August 03, 2016, 07:03:18 PM »

There is no specific event designed for what you want to do.

What you suggest is probably the simplest and most reliable way to do this. Putting the code in a separate function or macro and calling that (as you suggest) would mean you only need to add one line to each of your others.

One alternative would be to add something to the On_Update_UI event to make the additional change, but you would need additional logic in there to make sure that when this event fires and one of your macros wasn't the trigger that it doesn't do something you don't want to happen. This event isn't really meant for this purpose however. I think this would be messy. It is also recommended that this event contain the smallest amount of code possible as it runs frequently.

Another option would be to run through all the nodes in your document before saving, in On_Document_Before_Save, and set any values there. This of course means that you can figure out what needs to be added at that time. If that can't be done easily out of context of running the initial macro then you might need to use the ChangedNodes and related APIs to figure out what has been changed (that might not even give you enough context). I don't think that would save you much coding and it would introduce more complexity.
Pages: 1
Jump to: