|
#1
|
||||
|
||||
|
How to do Undo
Does anyone have a good suggestion on how to do Undos? I have an application where labels are clicked and other labels are enabled, disabled, made visable, text set in a label and information added to a SQLite database. Any suggestions on how to save this information so I can easily undo the actions.
My initial thoughts are to create a table when the page is displayed and when ever a label is clicked, store all the undo information in a function. Table.Insert(tbUndo, Table.Count(tbUndo)+1, function ()=Label.SetVisible(); Label.SetEnable(); SQLite.Query() And then when Ctrl+Z is pressed if there are items in the table then I can execute the last item and remove it from the table. Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#2
|
||||
|
||||
|
If I were to tackle such a thing I would probably use a 3 dimensional hash (table), so I could store the various pieces of relevant data about each event entry needed to "restore" it. For example:
Code:
undo={};
undo.a={"setCol", "Label1", "#0099FF", "#FF3333"}
undo.b={"setFont", "Label3", "Arial", "Verdana"}
undo.c={"setCol", "Label3", "#CCCCFF", "#330000"}
undo.d={"moveLbl", "Label5", "20,50", "150,40"}
undo.e={"setFont", "Label5", "Times New Roman", "Courier"}
|
|
#3
|
||||
|
||||
|
Hey Tigg, I just noticed that Brett's AutoPlay Pad application has an Undo feature. Maybe there's some insight to be gleaned by examining his code. I'd do it, but Brett's code is way over my head.
|
|
#4
|
||||
|
||||
|
Quote:
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#5
|
||||
|
||||
|
Quote:
Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#6
|
||||
|
||||
|
Ahhhh, I'll have to check that out. This would actually be a very cool feature suggestion for version 7.0, i.e. an "undo" property for other objects. In fact that's something I've never seen so it would be an original hook.
|
|
#7
|
||||
|
||||
|
I think it would be hard to do. Or maybe it is just hard to me. I think it would be a very cool action or global table to have. I am going on the principle that every action has an equal and opposite reaction, and am now trying to figure out how to do my Ctrl Z.
Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#8
|
||||
|
||||
|
I agree, it would defnitely be tricky. Seems like all the really cool stuff often is.
|
|
#9
|
||||
|
||||
|
Fundamentally, undo involves implementing a queue of some sort. You need some kind of indicator of what is being undone...e.g. the "type" of item in the undo queue. Then you need all of the information that you need to repeat whatever it is that you're undoing. Every undo adds an item to the queue, complete with all the information that is needed for its restoration.
Redo is basically just adding an item to another queue whenever you undo something. Only this item contains all the information about the item that is being restored. It is essentially another undo queue to undo the undo. It's essentially all just tracking information. You can use a numerically indexed table and a counter (or two) to implement a queue. All possible in Lua...in fact it's quite a bit easier because of the associative tables (you don't need to mess with structures and dynamic memory allocation issues). Undo/redo can be a bit tricky to wrap your head around at times.
__________________
--[[ Indigo Rose Software Developer ]] |
|
#10
|
||||
|
||||
|
Quote:
Thanks again for the pointers Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Undo Causes Crash | Jodie | AutoPlay Media Studio 4.0 | 1 | 10-30-2003 10:20 AM |
| How Do I Create an Undo File | YIRMASTER | Setup Factory 6.0 | 5 | 04-30-2002 12:45 AM |
| Undo Option Instead of Just Uninstall | YIRMASTER | Setup Factory 6.0 | 1 | 04-29-2002 02:23 AM |
All times are GMT -6. The time now is 01:52 AM.








Linear Mode

