Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26913
Modified Files: Tag: desiredata desire.tk Log Message: added class History to unify the handling of history
Index: desire.tk =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/desire.tk,v retrieving revision 1.1.2.600.2.279 retrieving revision 1.1.2.600.2.280 diff -C2 -d -r1.1.2.600.2.279 -r1.1.2.600.2.280 *** desire.tk 4 Aug 2007 05:30:11 -0000 1.1.2.600.2.279 --- desire.tk 4 Aug 2007 07:04:47 -0000 1.1.2.600.2.280 *************** *** 453,456 **** --- 453,490 ----
#-----------------------------------------------------------------------------------# + class_new History {Thing} + + def History init {size} { + set @size $size + set @hist {} + set @histi -1 + set @hist_on 0 + set @tmp_text {} + } + + def History hist_on= {val} {set @hist_on $val} + def History histi= {val} {set @histi $val} + + def History prepend {stuff} { + set @hist [linsert $@hist 0 $stuff] + if {[llength $@hist] >= $@size} {set @hist [lrange $@hist 0 [expr $@size-1]]} + } + + def History traverse {incr tmp_text} { + if {![llength $@hist]} {return} + set find [lsearch $@hist $@tmp_text] + #what if the tmp_text is well formed?? + if {$find >= 0 && !$@hist_on} {set @hist [lreplace $@hist $find $find]} + set @tmp_text $tmp_text + if {$tmp_text != "" && !$@hist_on} {lappend @hist $tmp_text; set @hist_on 1} + set @histi [expr $@histi + $incr] + set mod [expr ([llength $@hist]<[expr $@size+1]) ?[llength $@hist]:[expr $@size+1]] + if {$@histi >=$mod} {set @histi [expr $@histi%$mod]} + if {$@histi < 0} {set @histi [expr ($@histi+$mod)%$mod]} + return [lindex $@hist $@histi] + } + + History new_as obj_hist 5 + #-----------------------------------------------------------------------------------# # this is the beginning of the more application-dependent part.
*************** *** 2006,2016 **** }
- set obj_history {} - set obj_history_num 5 def Canvas add_to_obj_history {obj} { - set i $::obj_history_num if {![[$obj class] <= ObjectBox]} {return} ! set ::obj_history [linsert $::obj_history 0 [$obj text]] ! if {[llength $::obj_history] >= $i} {set ::obj_history [lrange $::obj_history 0 [expr $i-1]]} }
--- 2040,2046 ---- }
def Canvas add_to_obj_history {obj} { if {![[$obj class] <= ObjectBox]} {return} ! obj_hist prepend [$obj text] }
*************** *** 2082,2086 **** } def Canvas new_object_chain_wire {obj} { ! $self add_to_obj_history $obj set obj1_idx [$self children_idx [lindex [$self selection] 0]] $self deselect_all --- 2112,2116 ---- } def Canvas new_object_chain_wire {obj} { ! obj_hist prepend [$obj text] set obj1_idx [$self children_idx [lindex [$self selection] 0]] $self deselect_all *************** *** 2257,2264 **** set @edit 1 set @tab_repeats 0 - set @histi -1 - set @hist $::obj_history set @tmp_text {} ! set @hist_on 0 # stores which line is the longest if multiple line set @longline 1 --- 2287,2293 ---- set @edit 1 set @tab_repeats 0 set @tmp_text {} ! obj_hist hist_on= 0 ! obj_hist histi= -1 # stores which line is the longest if multiple line set @longline 1 *************** *** 2330,2334 **** set t $c.${self}text if {[[$self class] <= AtomBox]} {if {$@clear} {$t delete 1.0 1.end; set @clear 0}} ! set @tmp_text [$t get 1.0 1.end]$key switch -- $key { Tab { --- 2359,2363 ---- set t $c.${self}text if {[[$self class] <= AtomBox]} {if {$@clear} {$t delete 1.0 1.end; set @clear 0}} ! if {[regexp {^[a-zA-Z0-9]$} $key k]} {set @tmp_text [$t get 1.0 1.end]$key} switch -- $key { Tab { *************** *** 2348,2366 ****
def TextBox scroll_history {incr} { - set i $::obj_history_num - if {![llength $::obj_history]} {return} - if {$@tmp_text != "" && !$@hist_on} {lappend @hist $@tmp_text; set @hist_on 1} - set @histi [expr $@histi + $incr] - set mod [expr ([llength $@hist]<[expr $i+1]) ?[llength $@hist]:[expr $i+1]] - if {$@histi >=$mod} {set @histi [expr $@histi%$mod]} - if {$@histi < 0} {set @histi [expr ($@histi+$mod)%$mod]} set c [$self cwidget] set t $c.${self}text $t delete 1.0 1.end ! set text [lindex $@hist $@histi] $t insert 1.0 $text $t configure -width [string length $text] $self update_size after 0 $self changed }
--- 2377,2389 ----
def TextBox scroll_history {incr} { set c [$self cwidget] set t $c.${self}text $t delete 1.0 1.end ! set text [obj_hist traverse $incr $@tmp_text] $t insert 1.0 $text $t configure -width [string length $text] $self update_size after 0 $self changed + }
*************** *** 6279,6283 **** pack [frame $serf.1.1] -side bottom pack [button $serf.1.1.expander -image icon_plus -command "$self toggle_expand"] -side left ! pack [label $serf.1.1.label -width 11 -text "$name: " -font $::look(View:font)] -side left pack [entry $serf.entry -width 40 -font $::look(View:font)] -side left -fill x -expand yes pack $serf -fill x -expand no --- 6302,6306 ---- pack [frame $serf.1.1] -side bottom pack [button $serf.1.1.expander -image icon_plus -command "$self toggle_expand"] -side left ! pack [label $serf.1.1.label -width 11 -text "$name: " -font {Courier 10}] -side left pack [entry $serf.entry -width 40 -font $::look(View:font)] -side left -fill x -expand yes pack $serf -fill x -expand no