Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 10 of 10

Thread: How to do Undo

  1. #1
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160

    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. #2
    Corey is offline Indigo Rose Staff Alumni
    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.

  3. #3
    Corey is offline Indigo Rose Staff Alumni
    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.

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

  5. #5
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

  6. #6
    Corey is offline Indigo Rose Staff Alumni
    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.

  7. #7
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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. #8
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    I agree, it would defnitely be tricky. Seems like all the really cool stuff often is.

  9. #9
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    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. #10
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

Similar Threads

  1. Undo Causes Crash
    By Jodie in forum AutoPlay Media Studio 4.0
    Replies: 1
    Last Post: 10-30-2003, 09:20 AM
  2. How Do I Create an Undo File
    By YIRMASTER in forum Setup Factory 6.0
    Replies: 5
    Last Post: 04-29-2002, 11:45 PM
  3. Undo Option Instead of Just Uninstall
    By YIRMASTER in forum Setup Factory 6.0
    Replies: 1
    Last Post: 04-29-2002, 01:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts