Update tk to version 8.5.11
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / textpeer.tcl
blobe94284ee2872f1277d645061bd1bf4ea2b8c0650
1 # textpeer.tcl --
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."
11 package require Tk
13 set w .textpeer
14 catch {destroy $w}
15 toplevel $w
16 wm title $w "Text Widget Peering Demonstration"
17 wm iconname $w "textpeer"
18 positionWindow $w
20 set count 0
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
34 ## looks nice...
35 proc makeClone {w parent} {
36 global count
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" \
41 -text "Make Peer"]
42 set b2 [button $w.kill$count -command "killClone $w $count" \
43 -text "Delete Peer"]
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
55 ## Now set up the GUI
56 makeClone $w $first
57 makeClone $w $first
58 destroy $first
60 ## See Code / Dismiss buttons
61 grid [addSeeDismiss $w.buttons $w] - - -sticky ew -row 5000
62 grid columnconfigure $w 0 -weight 1