Save Undolist?

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Save Undolist?

Post by standay »

Hi Sergey,

Is there a way (or a way you can think of) to save a richviewedit undolist temporarily, and then restore it later? I use the same rve to display different docs. I'd like to store the undolist of the current doc right before I load another, and then restore the undolist when I reload the original doc.

Any thoughts appreciated.

Stan
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Save Undolist?

Post by Sergey Tkachenko »

It is not implemented. It is possible but not simple.

The list of undo items is accessible as TRVEditRVData(RichViewEdit.RVData).UndoList.
Each item in this list has a type TRVUndoInfos. This is a list too, a list of items of classes inherited from TRVUndoInfo.
There are many of them. Most of them are easy to serialize. However, there are difficult types of items. For example, if a user deletes an object (for example, a picture), it is stored in an undo item. To store this item, you must be able to write and read any document item. Table-related undo items are difficult too.
So this is not an easy task.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save Undolist?

Post by standay »

Sergey Tkachenko wrote: Thu Feb 23, 2023 6:40 pm So this is not an easy task.
Yes, I played around with TRVEditRVData(RichViewEdit.RVData).UndoList some time ago and thought I'd try it again today, and that was what I was beginning to think too, not an easy task.

When I first looked at this, I did the following workaround which I'm still using:

When I'm ready to load a new doc I save that doc first, then I do a BeginUndoCustomGroup with a unique name. Then I do a SelectAll and then DeleteSelection. I use those rather than Clear in order to "keep" the current undolist intact. Then I use the rve for whatever temporary thing I'm doing. When I'm done with that, I can spin back through the rve undolist from newest to oldest deleting the items as I go until I get to the one I named and stop there. IF I haven't done something with the rve that blew out the whole undolist, I still have the old list from the named undo. If I did do something to clear the list, I just reload the original doc that I saved. It comes back as it was, there's just no undolist anymore. And that of course was why I thought I'd ask about it. Sounds complicated but it's not as bad as you might think and it works most of the time.

There are pros and cons to using one rve for all the docs, and pros and cons to using multiple rves for all the docs. In this particular app I preferred the one rve route.

Thanks Sergey

Stan
Post Reply