OnCapacityChanged not trigging.

SyntaxEditor for Windows Forms Forum

Posted 7 years ago by Nassim Farhat
Version: 4.0.0290
Avatar
Hello, I am making my own custom Command Manager which uses in some parts the command manager of syntax editor.

Now, I connected to the following event

Editor.Document.UndoRedo.UndoStack.CapacityChanged += ActiproUndoStack_CapacityChanged;
Q1-
But when items get added to my stack, I do not get triggered for this event. Am I missing something? Why isn't this event trigging?

Q2-
If I obtain my change notifications, how can I succeed in retrieving the command that was added to the undo or redo stack and add this command to my custom CommandManager? I asked this because I noticed that the UndoableModificationStack class does not offer it's list of commands to the public.
I also noticed another event: Document_UndoRedoStateChanged
That event gives me some information concerning my undoredo operation and I do get trigged for it, the member e.Modification gives me some good information but what it does not do give me is all the details of the modification, ex: the RangeInfo etc... How can I obtain all the details of my undoredo stack operation?

thank you
Nassim



[Modified at 02/07/2012 04:50 PM]

Comments (6)

Posted 7 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar
The CapacityChanged event will probably occur when the capacity changes and not when the count changes. The UndoStack is an arraylist and as such it has a capacity (size of the array). If the size is exceeded all items are copied into a larger arraylist.

The problem is that the interface nearly offers no information at all. You would have to cast the items to UndoableModification but you can't, because the class is internal.
If you have the source code, you could change that and build your own version. If you don't have the source code, I think there really is now way to get the range of the modification unless you track all changes by yourself with the TextChanged event. But well, that's like not using the built-in functionality at all.

I have to admit, that the Undo/Redo management should be improved. Things like that it is not possible to have a non-undoable operation because it would corrupt the offsets in the stack make me shudder.
I am currently evaluating how I can avoid all those limitations. I might rewrite the UndoRedo stacks or don't even use the built-in functionality and write an application framework that fits my requirements...


Best regards, Tobias Lingemann.

Posted 7 years ago by Nassim Farhat
Avatar
Thanks for your reply.

Considering the lack of visibility of the commands placed on the stack i decided to go with the simplest solution and simply wrap the syntax editor undoredo stack into a another command manager of my own and create commands that call the undo and the redo on Execute or Reverse calls. In any case, thanks for the heads up. I have moved forward to the WPF version of the syntaxEditor. Can you tell me if the undoredo is more transparent in the new WPF version, maybe I should ask this question on a different forum than this one?

Thanks
Nassim
Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nassim,

The CapacityChanged event only fires when the Capacity (max allowed undo items) property of the stack changes. It doesn't track how many items are actually on the stack.

You probably want to hook into the SyntaxEditor.DocumentUndoRedoStateChanged event instead since that fires whenever an undo/redo stack is changed. From there you can look at the stack's Count and update your command UI appropriately.


Actipro Software Support

Posted 7 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar
Sorry, I don't use or have the WPF version, so I really don't know.
I only can assume, that the UndoRedo stacks are also improved. I guess a moderator will answer that question soon, otherwise just ask in the WPF forum.


Best regards, Tobias Lingemann.

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes the WPF version's undo stack is more transparent. Each stack there inherits IEnumerable<IUndoableTextChange> and the IUndoableTextChange interface provides access to its description and a list of all operations in the text change, among other data.


Actipro Software Support

Posted 7 years ago by Nassim Farhat
Avatar
Thanks for all your replies.... I got what i wanted done by simply using the UndoRedoStateChanged.

Yes... I'm looking forward to upgrading to WPF... There's so many adornments layering possibilities to enhance and customize the look and feel for the end-user.

Regards
Nassim
The latest build of this product (v2018.1 build 0341) 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.