ANN: GLX2 3.0.10

Mark Wieder mwieder at ahsoftware.net
Tue Aug 7 01:48:06 EDT 2012


Alejandro-

Monday, August 6, 2012, 3:58:56 PM, you wrote:

> I am sure that you are correct, but I could not create the script to
> demonstrate it. :-D
> Suppose that I have 10000 controls in the card (remember, it's a graphic
> application),
> and (if I understand correctly your advice) then I had to create 10000
> arrays in memory
> to hold the properties of each control. Could this be the correct
> interpretation of your
> idea for this task?

Ick! No, I would never suggest something as cumbersome as that!
It's as simple as adding another dimension to the undo array.
Here's a minor adjustment to the Undo.Push and Undo.Pop commands in
the code I posted earlier.

As an example, let's say you have ten controls, each named "graphicN",
where N is a number from 1 to 10. You might determine which properties
to store for each graphic, then (for this example I'm just storing the
height and width for each of the ten controls):

repeat with N=1 to 10
  put "graphic" & N into tObject
  -- set up an array with the properties you wish to archive
  put the width of control tObject into tArray["width"]
  put the height of control tObject into tArray["height"]
  -- push the array onto the undo stack
  Undo.Push tObject, tArray
end repeat

--> Undo support

local sUndoPointArray

/**
* Undo.Retrieve
*
* Retrive an element from the sUndoPointArray
*/
private function Undo.Retrieve pObject, pCount
   local tData

   put sUndoPointArray[pObject][pCount] into tData
   if pCount = "count" then
      return tData
   else
      return decompress(tData)
   end if
end Undo.Retrieve

/**
* Undo.Store
*
* Store an element into the sUndoPointArray
*/
private command Undo.Store pObject, pCount, pValue
   local tData

   put compress(pValue) into tData
   if pCount = "count" then
      put pValue into sUndoPointArray[pObject][pCount]
   else
      put tData into sUndoPointArray[pObject][pCount]
   end if
end Undo.Store

/**
* UndoPointer
*
* Return the undo stack index
*/
private function Undo.Pointer pObject
   local tCount

   put Undo.Retrieve(pObject, "count") into tCount
   if tCount is empty then
      put 0 into tCount
   end if
   return tCount
end Undo.Pointer

/**
* Undo.SetPointer
*
* @pNewCount : index value for this type of undo action
*/
private command Undo.SetPointer pObject, pNewCount
   Undo.Store pObject, "count", pNewCount
end Undo.SetPointer

/**
* Undo.Push
*
* Save the current script for undoing later on
* @pObject is the long id of the control
* @pPropertyArray is an array of property names and values
*/
command Undo.Push pObject, pPropertyArray
   local tCount

   put Undo.Pointer(pObject)+1 into tCount
   Undo.Store pObject, tCount, pPropertyArray
   Undo.SetPointer pObject, tCount -- bump the index pointer
end Undo.Push

/**
* Undo.Pop
*
* undo the last command
* @pObject is the long id of the control
*/
command Undo.Pop pObject
   local tCount
   local tObject
   local tSavedUndo
   local tSuccess
   local tKeys

   lock screen
   -- retrieve the current pointer for this object
   put Undo.Pointer(pObject) into tCount

   if tCount > 0 then
      -- retrieve the stored data
      put Undo.Retrieve(pObject, tCount) into tSavedUndo
      if tSavedUndo is not empty then
         -- now we have the property array
         put the keys of tSavedUndo into tKeys
         repeat for each line tProperty in tKeys
           try
           do "set the" && tProperty && "of" && pObject && "to" && \
           tSavedUndo[tProperty]
           catch e
           end try
         end repeat
         -- decrement the stack pointer
         Undo.SetPointer pObject, tCount-1
         put true into tSuccess
      end if
   end if
   unlock screen
   if not tSuccess then
      answer "nothing to undo @" && tCount
   end if
end Undo.Pop

-- 
-Mark Wieder
 mwieder at ahsoftware.net





More information about the use-livecode mailing list