global findmsg set findmsg {} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Initialize the .find window. proc FindInit {w} { global V me findpat findndx findlst set findpat {} set findndx 1 set findlst {} $w tag config Find -background black $w tag config Found -foreground white $w tag raise Find Lname $w tag raise Found Lname } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This searches the text widget $w for instances of the pattern in # # findpat, and tags them all with the Find tag. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc FindPat {w} { global V me findpat findndx findlst if {$V>1} {puts "$me/FindPat: {$findpat}"} set findlst {} $w tag remove Find 1.0 end $w tag remove Found 1.0 end forAllMatches $w $findpat { $w tag add Find first last lappend findlst "[$w index first] [$w index last]" if {$V>4} {puts "$me/FindPat: lst={$findlst}"} } set findndx 0.0 NextPat $w } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This only works after FindPat has marked text that matched findpat. # # We skip to the next matching chunk of text, and bring it into view. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc NextPat {w} { global V me findmsg findndx findlst if {$V>4} {puts "$me/NextPat: ndx=$findndx"} foreach pair $findlst { set ndx [lindex $pair 0] set ndy [lindex $pair 1] if {$V>4} {puts "$me/NextPat: {$ndx,$ndy}"} if {$ndx > $findndx} { if {$V>1} {puts "$me/NextPat: {$ndx,$ndy} is next."} $w tag remove Found 1.0 end $w see [set findndx $ndx] $w tag add Found $ndx $ndy set findmsg {Press Next to find another match} return } } set findmsg {No more matches.} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the little "Find" window. One kludge: The %X %X mechanism # # doesn't seem to work properly for this menu entry; we get "%X" and # # "%Y" as args rather than the screen coords. So we do it the hard # # way instead. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc FindWin {w} { global B C V R me findmsg findpat if ![winfo exists .find] { toplevel .find set X [winfo pointerx .] set Y [winfo pointery .] wm geometry .find +$X+$Y wm title .find {Find} entry .find.pat -textvariable findpat -width 0 -fg $C(E) bind .find.pat "FindPat $w" frame .find.b button .find.b.f -bd 5 -relief raised -text First -command "FindPat $w" button .find.b.n -bd 5 -relief raised -text Next -command "NextPat $w" button .find.b.q -bd 5 -relief raised -text Cancel -command {destroy .find} entry .find.msg -bd 1 -relief ridge -textvariable findmsg -bg black -fg orange -width 0 pack .find.b.f .find.b.n .find.b.q -in .find.b -side left -expand 1 -fill x pack .find.pat .find.b -in .find -side top -expand 1 -fill x pack .find.msg -in .find -side bottom -expand 1 -fill x set findmsg {Enter tcl regexp and press First} } wm deiconify .find raise .find }