Add a script to clean up after Tcl/Tk installation
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / textpeer.tcl
bloba93f1278a99c64efd219aa4234ef6839ebef0d93
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 # RCS: @(#) $Id: textpeer.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp $
9 if {![info exists widgetDemo]} {
10 error "This script should be run from the \"widget\" demo."
13 package require Tk
15 set w .textpeer
16 catch {destroy $w}
17 toplevel $w
18 wm title $w "Text Widget Peering Demonstration"
19 wm iconname $w "textpeer"
20 positionWindow $w
22 set count 0
24 ## Define a widget that we peer from; it won't ever actually be shown though
25 set 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."
35 ## Procedures to make and kill clones; most of this is just so that the demo
36 ## looks nice...
37 proc 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
52 proc killClone {w count} {
53 destroy $w.text$count $w.sb$count
54 destroy $w.clone$count $w.kill$count
57 ## Now set up the GUI
58 makeClone $w $first
59 makeClone $w $first
60 destroy $first
62 ## See Code / Dismiss buttons
63 grid [addSeeDismiss $w.buttons $w] - - -sticky ew -row 5000
64 grid columnconfigure $w 0 -weight 1