Android Question undo button

DPaul

Active Member
Licensed User
Longtime User
Hi,

I'm in the process of implementing an undo function, boring....
What i found in the archives is:
[B4X] [class] UndoManager

When i try to analyse the undo manager class,i see a variable "ud as undodata" ; it seems that it accepts states of different objects (text from one, color from another..)

But i have many objects with text, many with different colors, most text and color... that change all the time.
Questions:
1. Do i need a Getstate sub for every object-property combination individually?
Can't i backup a "button" and have all its properties implicitely included (text, color, position...)
2. What is the benefit over declaring a "backup" view/variable and do a copy at certain points
eg. Button1, and ud_button1, Button2 and ud_button2...
same with vars... (other than doing differential backups)

??
thx,
Paul

 

Erel

B4X founder
Staff member
Licensed User
Longtime User
UndoManager stores a stack of states and allows going back and forth in the stack.

1. You need to decide what you want to store as part of the state. You should have a single GetState sub that creates an UndoData object with all the data needed. You should modify UndoData type as needed.

2. What you describe will only allow the user to undo the last step (and it is not simpler).
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Hi,

Sorry, but i have been looking at this undo class, where 2 objects with each 1 property are tracked.
It eludes me what i must do to track 10 buttons with many properties (enabled/visible/text/color..)
not to mention many more int and string vars.
Can i find somewhere a more elaborate example eg. with 2 buttons with each 2 properties and some int or string var with a value?
i'm willing to implement this class, but i need a kick start :)

thx,
Paul
 
Upvote 0
Top