@PeterJones said in How dynamic-ID menu commands are executed and relation to macros:
There is no “universally constant value” necessary for Notepad++ to store for it to be working the way it is.
And creating a new identifier rather than using menuCmdID is not likely to happen (nor should it, IMO)
That scheme (even if hypothetical) seems to work very well as long as it’s not a problem that the IDs change when you remove menu entries.
But we do know that it is in fact a problem for recording macros.
Here are 2 approaches I can think of (besides the “shut up and hack the XML files” one :) ) :
A. Constant IDs version
Still have a linked list to represent the structure of the (dynamic) menus, but whose contents are just the IDs of those commands. Can still be in same range as current IDs, if needed.
Add a dictionary (hashmap) to map from those IDs to the respective actual commands, or in case of macros - list of actions , as you describe in your post above.
Npp getting command 20001 for ex, involves looking up in the dictionary - most often a constant time operation.
Deleting an menu entry involves deleting the respective entry in the linked list and also the ID-value pair in the dictionary.
In addition to that, to ensure that generated IDs stay within a given range: Several schemes are possible, one of the simplest can be just generate a key in range and test that it is not present in the dictionary.
B. Dynamic IDs, but synchronized in every saved macro
Basically, keep the scheme as it is at present, but add a way to update, for each macro, every stored referenced menu command ID in an Action record:
at every removal of a menu entry, compute how the rest of entries’ IDs would change (if located After those removed, the ID would decrease by one) and traverse the linked list of all macros and update that ID in every action that refers to a menu-command in the range of the dynamic-IDs types (Run, Plugin and Macro commands).
Thus on Npp closing, the macros written in XML will also contain updated IDs.
But don’t pretend the niche [for a more powerful macro system ] doesn’t already have a plethora of entries.
I think there is plenty of room for a macro system to grow in power and STILL be much easier to do a lot of common tasks, than the same tasks in any scripting language.
Because with macros you don’t have to learn and remember syntax.