initUndoRedo

$canvaseditor initUndoRedo
cuts private undoStack and redoStack to length – private undonePtr.
$canvaseditor initUndoRedo undoStr redoStr
cuts private undoStack and redoStack to length – private undonePtr, then pushes undoStr to undoStack and redoStr to redoStack, but only if different from previous undo/redo sitation.
$canvaseditor initUndoRedo reset
resets internal undo data

Limits number of undo steps.


obj method canvaseditor initUndoRedo args {
  #
  # Stack initialisieren
  #
  if {[lindex $args 0] eq "reset"} then {
    my undoStack {}
    my redoStack {}
    my undonePtr 0
  } else {
    if {[my undonePtr] > 0} then {
      my undoStack [lrange [my undoStack] 0 end-[my undonePtr]]
      my redoStack [lrange [my redoStack] 0 end-[my undonePtr]]
      my undonePtr 0
    }
    if {[llength $args] == 2} then {
      lassign $args undoStr redoStr
      #
      set undoStr [regsub -all {(^|\n) *} $undoStr {\1}]
      set redoStr [regsub -all {(^|\n) *} $redoStr {\1}]
      set undoStr [regsub -all {\n{2,}} $undoStr \n]
      set redoStr [regsub -all {\n{2,}} $redoStr \n]
      set undoStr \n[string trim $undoStr]\n
      set redoStr \n[string trim $redoStr]\n
      #
      set undoStack [my undoStack]
      set redoStack [my redoStack]
      if {
        $undoStr ne $redoStr &&
        ( $undoStr ne [lindex $undoStack end] ||
          $redoStr ne [lindex $redoStack end] )
      } then {
        lappend undoStack $undoStr
        lappend redoStack $redoStr
        my undoStack $undoStack
        my redoStack $redoStack
      }
    }
    # Stacklänge begrenzen
    set maxLen 99
    my undoStack [lreverse [lrange [lreverse [my undoStack]] 0 $maxLen]]
    my redoStack [lreverse [lrange [lreverse [my redoStack]] 0 $maxLen]]
  }
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z