Interface for MacroAction

SyntaxEditor for WPF Forum

Posted 4 years ago by Jorgen

I would like to expand the possibilities of the macro recording and macro playback.

One way to make it possible is to make SyntaxEditor use an interface (IMacroAction maybe) for a macro action. That interface should just enumerate the actions, making it possible to be a dynamic sequence of edit actions. That would make it possible to create any custom macro playback system.

One thing I would also need, to make my idea possible, is an event that always emits the last activated edit action (not during playback).

If this is already possible somehow, please advise me :-)

Comments (6)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Jorgen,

The MacroAction class is an IEnumerable<IEditAction>.  You can add any sequence of IEditActions to it.  You can make any custom IEditAction you want.

I'm not sure what you needed the event for.  Perhaps you can give some more information on the context of that request.  Thanks!

Actipro Software Support

Posted 4 years ago by Jorgen

Sure, the MacroAction is an IEnumerable<IEditAction>, but it is just a fixed list during playback.
I need a way to be able to add some logic to the sequence of actions (conditional execution and loops). I also need a way to be able to (conditionally) execute sub-macros (nested macros).

The reason I need it is because the macro playback is build into the editor, and it seems it cannot be customized. I would have to create a parallell macro playback system, if I don't have the flexibility within a custom action or the MacroAction class.

I guess the MacroAction class is handled as a fixed list of actions during playback, and that the playback cannot handle other MacroAction actions in the list.

If it is possible to create a custom IEditAction class that does much the same as MacroAction, with some custom logic for yielding actions, please advice me how.

I really like the fact that almost every action done by the user can be recorded in a macro, and that custom actions can be added.

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Jorgen,

That is correct, MacroAction is a flat list and doesn't support nesting, condition execution, or looping.  MacroAction is just a regular IEditAction, but has special meaning to the MacroRecording class, and also gets its Add method called when an IEditAction occurs in an EditorView.  From looking at the logic, there isn't a way to inject custom MacroRecording handling at this time.

Actipro Software Support

Posted 4 years ago by Jorgen

This is a suggestion for a feature  ;-)
I think the implementation of the macro feature is super nice as it is, but with a few very simple changes, the playback functionality can be customized, and that is very much in the spirit of the SyntaxEditor.

By implementing these changes, the macro playback possibilities will be wide open for me, and for others who also love automation.

From what you indicate and what I have found, I don't actually think my suggestion should be to create an interface for macro actions, but instead the following:

Change 1: Open the MacroAction class up for customizations

Most important thing here is to make SyntaxEditor not use the Count property and the Item property for the playback.

Making the GetEnumerator method virtual would make it possible to create a derived class that implements any kind of playback logic, and yield edit actions in any custom way.
This would also make it possible to implement nested macro playback.

Maybe the editor could make use of a replaceable factory to create MacroAction objects.

Change 2: Add an event to SyntaxEditor to notify edit actions

This would make it possible to monitor the user actions. I think this should not be active during macro playback. The listener(s) could then e.g. save the last action, if that's needed.
Maybe only actions where the CanRecordInMacro is true should be notified with this event.
The event arguments should have a Cancel property to enable the listener to make the editor skip the action execution. The listener could then execute other actions instead.
I have a very specific need for this that I don't wish to reveal right now...


That's my rough idea for this feature request. I have lots of ideas what to do with this. I think a good macro feature can be much easier and much more accessible than scripting for most users who wish to automate one-off or repetitive common editing jobs.

It seems to be quite easy for you to implement, it has a very low risk, and it will not break any current functionality.
I hope I can convince you that this is a good idea, and that it can open up for some very functional customizations.

[Modified 4 years ago]

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA


We can log a suggestion request for future macro system customization on our TODO list.  I know you've said you wanted to customize nesting, condition execution, and looping of macros.  Just so we have related information stored with this thread, could you walk through in detail a scenario where you want to be able to do this?  Such as explain exactly what the user is doing step-by-step and how and why you wanting to alter the results.  That would help us understand the request better.  Thanks!

Actipro Software Support

Posted 4 years ago by Jorgen

That sounds great! I can surely explain the general idea, but I will keep some ideas for my self for now.

Macro Recording

I would like much the same experience as the SyntaxEditor has already, and add a few things.

Imagine the user being able to save macro recordings and name them. The UI could list the macros in the command list and add keyboard shortcut just as with the other editor commands. I'm sure this can be done already.

During macro recording it would be very helpful if the activation of saved macros was possible, and that activation saved in the recording as "execute macro" commands, and not saved as a flat recording with the sub-macro commands added to the recording. This is the simplest macro nesting I would like to have.

Loop / Repeat

To be able to do things multiple times, the application should have a "repeat" action, where the user:

  1. Activate a "Repeat" button or menu entry,
    which pops up a dialog where the user can input an integer number as a repeat count. After confirming the number another small popup indicates "ready for command".
  2. Activate an editor action (press a key or activate a command in the UI),
    whereafter that command will be repeated the selected number of times. The user could e.g. press Ctrl+V to paste the text from the clipboard the specified number of times.

The repeat action could be enhanced by also supporting a boolean "condition" as loop input ('while' loop). If, instead of inputting a numeric value, the user selects a condition from a list (e.g. "NotAtEndOfDocument" or "NotAtLineEnd"), the repeat function would continue as long as the condition is 'true'. 

I think this requires one simple addition to the SyntaxEditor, the "Change 2" from my previous post. If the application could listen in on the activated editor commands, a dynamic macro could be created, where the selected command is repeated the specified number of times.

Alternatively, the repeat functionality could be a build-in command in SyntaxEditor. Support for nested playbacks would be required then. Of course this should be implemented in a flexible fashion to facilitate any kind of smart idea for repeated actions.

During macro recording, only the 'repeat' command (including the command to repeat) should be added, and not each repeated command done during the repeat execution.

Macro Playback

The user would expect to be able to activate either the last (unnamed) recording or any of the saved recordings, either through GUI or an attached keyboard shortcut.

The SyntaxEditor should just support playback of macros emitting actions through any kind of implemented playback implementation.

What I would expect of SyntaxEditor

I'm interested in the most simple implementation making it possible for me to create a nice and rich macro system. Of cause I would be happy with every little thing the SyntaxEditor can offer to do that, and it already has the most of it.

[Modified 4 years ago]

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.