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.
7 if {![info exists widgetDemo
]} {
8 error "This script should be run from the \"widget\" demo."
16 wm title
$w "Text Widget Peering Demonstration"
17 wm iconname
$w "textpeer"
22 ## Define a widget that we peer from; it won't ever actually be shown though
23 set first
[text $w.
text[incr count
]]
24 $first insert end
"This is a coupled pair of text widgets; they are peers to "
25 $first insert end
"each other. They have the same underlying data model, but "
26 $first insert end
"can show different locations, have different current edit "
27 $first insert end
"locations, and have different selections. You can also "
28 $first insert end
"create additional peers of any of these text widgets using "
29 $first insert end
"the Make Peer button beside the text widget to clone, and "
30 $first insert end
"delete a particular peer widget using the Delete Peer "
31 $first insert end
"button."
33 ## Procedures to make and kill clones; most of this is just so that the demo
35 proc makeClone
{w parent
} {
37 set t
[$parent peer create
$w.
text[incr count
] -yscroll "$w.sb$count set"\
38 -height 10 -wrap word
]
39 set sb
[scrollbar $w.sb
$count -command "$t yview" -orient vertical
]
40 set b1
[button $w.clone
$count -command "makeClone $w $t" \
42 set b2
[button $w.kill
$count -command "killClone $w $count" \
44 set row
[expr {$count * 2}]
45 grid $t $sb $b1 -sticky nsew
-row $row
46 grid ^ ^
$b2 -row [incr row
]
47 grid configure
$b1 $b2 -sticky new
48 grid rowconfigure
$w $b2 -weight 1
50 proc killClone
{w count
} {
51 destroy $w.
text$count $w.sb
$count
52 destroy $w.clone
$count $w.kill
$count
60 ## See Code / Dismiss buttons
61 grid [addSeeDismiss
$w.buttons
$w] - - -sticky ew
-row 5000
62 grid columnconfigure
$w 0 -weight 1