1# textpeer.tcl -- 2# 3# This demonstration script creates a pair of text widgets that can edit a 4# single logical buffer. This is particularly useful when editing related text 5# in two (or more) parts of the same file. 6# 7# RCS: @(#) $Id$ 8 9if {![info exists widgetDemo]} { 10 error "This script should be run from the \"widget\" demo." 11} 12 13package require Tk 14 15set w .textpeer 16catch {destroy $w} 17toplevel $w 18wm title $w "Text Widget Peering Demonstration" 19wm iconname $w "textpeer" 20positionWindow $w 21 22set count 0 23 24## Define a widget that we peer from; it won't ever actually be shown though 25set first [text $w.text[incr count]] 26$first insert end "This is a coupled pair of text widgets; they are peers to " 27$first insert end "each other. They have the same underlying data model, but " 28$first insert end "can show different locations, have different current edit " 29$first insert end "locations, and have different selections. You can also " 30$first insert end "create additional peers of any of these text widgets using " 31$first insert end "the Make Peer button beside the text widget to clone, and " 32$first insert end "delete a particular peer widget using the Delete Peer " 33$first insert end "button." 34 35## Procedures to make and kill clones; most of this is just so that the demo 36## looks nice... 37proc makeClone {w parent} { 38 global count 39 set t [$parent peer create $w.text[incr count] -yscroll "$w.sb$count set"\ 40 -height 10 -wrap word] 41 set sb [scrollbar $w.sb$count -command "$t yview" -orient vertical] 42 set b1 [button $w.clone$count -command "makeClone $w $t" \ 43 -text "Make Peer"] 44 set b2 [button $w.kill$count -command "killClone $w $count" \ 45 -text "Delete Peer"] 46 set row [expr {$count * 2}] 47 grid $t $sb $b1 -sticky nsew -row $row 48 grid ^ ^ $b2 -row [incr row] 49 grid configure $b1 $b2 -sticky new 50 grid rowconfigure $w $b2 -weight 1 51} 52proc killClone {w count} { 53 destroy $w.text$count $w.sb$count 54 destroy $w.clone$count $w.kill$count 55} 56 57## Now set up the GUI 58makeClone $w $first 59makeClone $w $first 60destroy $first 61 62## See Code / Dismiss buttons 63grid [addSeeDismiss $w.buttons $w] - - -sticky ew -row 5000 64grid columnconfigure $w 0 -weight 1 65