Indigo Rose Software
  #1  
Old 09-20-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Reply With Quote
  #2  
Old 09-20-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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"}
It's an idea anyhow, not very well thought out though, there's probably a better way.
Reply With Quote
  #3  
Old 09-20-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #4  
Old 09-20-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Quote:
Originally Posted by Corey
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.
thanks I will take a look.
__________________
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
Reply With Quote
  #5  
Old 09-20-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Quote:
Originally Posted by Corey
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.
Brett's code uses the Input.Undo built in action to undo any changes in the Input object. Not quite what I was looking for.

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
Reply With Quote
  #6  
Old 09-20-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #7  
Old 09-20-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Reply With Quote
  #8  
Old 09-20-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
I agree, it would defnitely be tricky. Seems like all the really cool stuff often is.
Reply With Quote
  #9  
Old 09-21-2005
Lorne's Avatar
Lorne Lorne is offline
Indigo Rose Staff Member
 
Join Date: Feb 2001
Location: Indigo Rose Software
Posts: 2,588
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 ]]
Reply With Quote
  #10  
Old 09-21-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Quote:
Originally Posted by Lorne
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.
Thanks Lorne. I think I have the basic idea now. It is just a matter of how to store the undo redo information. I started on the Undo part last night and have most of it working. I need to squash some bugs but should be able to do that today.

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software