[ANN] penTool 0.3.2h [with scalable gradients]

Mark Wieder mwieder at ahsoftware.net
Wed Aug 1 16:35:50 EDT 2012


Alejandro Tejada <capellan2000 at ...> writes:

> (Anyone have Undo code to spare?)

Here's a framework for unlimited undos. It's set to archive the script of
objects, but is easily modifiable for other properties.

--> 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
*/
command Undo.Push pObject
   local tCount

   put Undo.Pointer(pObject)+1 into tCount
   Undo.Store pObject, tCount, the htmltext of field kCodeField of stack self
   Undo.SetPointer pObject, tCount -- bump the index pointer
end Undo.Push

/**
* Undo.Pop
*
* undo the last command
*/
command Undo.Pop pObject
   local tCount
   local tObject
   local tSavedUndo
   local tSuccess
   
   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
         set the htmltext of field kCodeField of stack self to tSavedUndo
         -- 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