[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: UnDo/ ReDo Buffer ?
[Thread Prev] | [Thread Next]
- Subject: Re: UnDo/ ReDo Buffer ?
- From: Claus Dietrich <claus.dietrich@xxxxxxxxxx>
- Date: Fri, 22 Aug 2025 17:02:09 +0200
- To: Gambas MailingList <user@xxxxxxxxxxxxxxxxxxxxxx>
Hi BenoítThanks for this giant input. I will need some time to digest it. Gianluigi provided me directly with a smaller sample-project which seems to apply this concept. This all should be a good basis to start with.
I will continue to use AI (preferably perplexity). In many cases it provides reasonable, compact, factual and useful answers within seconds which I wouldn't get in forums within hours/days. Sometimes I even didn't know where to ask and got immediate and brillant answers. And pretty often it helps me to avoid headache and plenty of time, i.e. when I need a complex regular expression. Its capabilities are amazing and rather scary than shitty.
Best regards Claus Am 22.08.25 um 15:17 schrieb Benoît Minisini:
Le 20/08/2025 à 14:17, Claus Dietrich a écrit :HiI developed an app for scanning documents. It depicts the scans in a ListView with a thumbnail preview. The order of the scans in the ListView can be changed and scans can also be deleted. What was missing so far is an UnDo function. So I asked an AI about a suitable concept and got a reasonable proposal based on a class for scanned document and a collection of these classes and a history stack. I tested it in a pilot project and it turned out to be feasible and efficient.In parallel I found this in the Gambas-wiki: https://gambaswiki.org/ edit/snippets/undoredobufferI don't understand this chapter. It seems to tell the reader, that there is a generic solution for any thinkable undo/redo action in an app. As this is beyond my imagination I kindly ask for some guidance resp. concepts for UnDo/ReDo functions und sample projects if available.Best regards ClausI will try to explain that concept the best I can.But please stop doing using this AI shit. Or only for questions you already know the answer. 🙂To implement undo/redo, you have to list all the actions in your program that are undoable. These actions must be reversible to be able to be redoable.Then you create a stack of "actions", each action being an object or a structure that includes all the needed information for undoing or redoing the action.Then you have the following methods: - Add a new action to the stack. - Undo the last action. - Redo the action. - Begin a group of action that will be undone or redone globally. - End a group of action that will be undone or redone globally.You have an example of that with the 'CUndo' class in the IDE source code. It is used for implementing undo/redo in the form editor.Now the question is: how an action can be executed (inverted or not) in a generic way?This way: in the 'CUndo' class, I put the name of the public method in the action data, and I use 'Object.Call()' to dynamically call the method in the object passed to the Undo() or the Redo() method.So everything is entirely generic! The 'CUndo' class can be used for almost anything.When a "undoable" method is called, it calls the Add() method of the 'CUndo' object, passing as argument the name of the method that will do the reverse action (with the arguments if needed).To see an example, look at the 'FForm.RaiseControl()' and 'FForm.LowerControl()' method. They indirectly call methods in the 'CControl' class that implement what I described above.The only real hard thing is being careful when describing the action, the reverse action, and implementing their respective methods. They must be the exact contrary!I hope it was clear enough. If you have any question, tell me. Regards, -- Benoît Minisini.
UnDo/ ReDo Buffer ? | Claus Dietrich <claus.dietrich@xxxxxxxxxx> |
Re: UnDo/ ReDo Buffer ? | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |