summaryrefslogtreecommitdiffstats
path: root/library/demos/textpeer.tcl
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-10-15 21:06:16 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-10-15 21:06:16 (GMT)
commitabcf21eecbc0627f16250c70fc56ff58348c68a8 (patch)
tree316082a042e1ef2c5c60073e8be3a90025095d61 /library/demos/textpeer.tcl
parentb2f828793e2d7f586496d46cdbad418983a474dc (diff)
downloadtk-abcf21eecbc0627f16250c70fc56ff58348c68a8.zip
tk-abcf21eecbc0627f16250c70fc56ff58348c68a8.tar.gz
tk-abcf21eecbc0627f16250c70fc56ff58348c68a8.tar.bz2
GOOBE work on the widget demo, plus a new demo of text widget peering.
Diffstat (limited to 'library/demos/textpeer.tcl')
-rw-r--r--library/demos/textpeer.tcl60
1 files changed, 60 insertions, 0 deletions
diff --git a/library/demos/textpeer.tcl b/library/demos/textpeer.tcl
new file mode 100644
index 0000000..0dd23f3
--- /dev/null
+++ b/library/demos/textpeer.tcl
@@ -0,0 +1,60 @@
+# textpeer.tcl --
+#
+# This demonstration script creates a pair of text widgets that can edit a
+# single logical buffer. This is particularly useful when editing related text
+# in two (or more) parts of the same file.
+#
+# RCS: @(#) $Id: textpeer.tcl,v 1.1 2007/10/15 21:06:17 dkf Exp $
+
+if {![info exists widgetDemo]} {
+ error "This script should be run from the \"widget\" demo."
+}
+
+package require Tk
+
+set w .textpeer
+catch {destroy $w}
+toplevel $w
+wm title $w "Text Widget Peering Demonstration"
+wm iconname $w "textpeer"
+positionWindow $w
+
+set count 0
+
+set first [text $w.text[incr count]]
+$first insert end "This is a coupled pair of text widgets; they are peers to "
+$first insert end "each other. They have the same underlying data model, but "
+$first insert end "can show different locations, have different current edit "
+$first insert end "locations, and have different selections. You can also "
+$first insert end "create additional peers of any of these text widgets using "
+$first insert end "the Make Peer button beside the text widget to clone, and "
+$first insert end "delete a particular peer widget using the Delete Peer "
+$first insert end "button."
+grid $first
+
+proc makeClone {w parent} {
+ global count
+ set t [$parent peer create $w.text[incr count] -yscroll "$w.sb$count set"\
+ -height 10 -wrap word]
+ set sb [scrollbar $w.sb$count -command "$t yview" -orient vertical]
+ set b1 [button $w.clone$count -command "makeClone $w $t" \
+ -text "Make Peer"]
+ set b2 [button $w.kill$count -command "killClone $w $count" \
+ -text "Delete Peer"]
+ set row [expr {$count * 2}]
+ grid $t $sb $b1 -sticky nsew -row $row
+ grid ^ ^ $b2 -row [incr row]
+ grid configure $b1 $b2 -sticky new
+ grid rowconfigure $w $b2 -weight 1
+}
+proc killClone {w count} {
+ destroy $w.text$count $w.sb$count
+ destroy $w.clone$count $w.kill$count
+}
+
+makeClone $w $first
+makeClone $w $first
+destroy $first
+
+## See Code / Dismiss buttons
+grid [addSeeDismiss $w.buttons $w] - - -sticky ew -row 5000