| 1 | # text.tcl -- |
| 2 | # |
| 3 | # This demonstration script creates a text widget that describes |
| 4 | # the basic editing functions. |
| 5 | # |
| 6 | # RCS: @(#) $Id: text.tcl,v 1.3 2001/11/15 11:55:26 dkf Exp $ |
| 7 | |
| 8 | if {![info exists widgetDemo]} { |
| 9 | error "This script should be run from the \"widget\" demo." |
| 10 | } |
| 11 | |
| 12 | set w .text |
| 13 | catch {destroy $w} |
| 14 | toplevel $w |
| 15 | wm title $w "Text Demonstration - Basic Facilities" |
| 16 | wm iconname $w "text" |
| 17 | positionWindow $w |
| 18 | |
| 19 | frame $w.buttons |
| 20 | pack $w.buttons -side bottom -fill x -pady 2m |
| 21 | button $w.buttons.dismiss -text Dismiss -command "destroy $w" |
| 22 | button $w.buttons.code -text "See Code" -command "showCode $w" |
| 23 | pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 |
| 24 | |
| 25 | text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" -setgrid 1 \ |
| 26 | -height 30 -undo 1 -autosep 1 |
| 27 | scrollbar $w.scroll -command "$w.text yview" |
| 28 | pack $w.scroll -side right -fill y |
| 29 | pack $w.text -expand yes -fill both |
| 30 | $w.text insert 0.0 \ |
| 31 | {This window is a text widget. It displays one or more lines of text |
| 32 | and allows you to edit the text. Here is a summary of the things you |
| 33 | can do to a text widget: |
| 34 | |
| 35 | 1. Scrolling. Use the scrollbar to adjust the view in the text window. |
| 36 | |
| 37 | 2. Scanning. Press mouse button 2 in the text window and drag up or down. |
| 38 | This will drag the text at high speed to allow you to scan its contents. |
| 39 | |
| 40 | 3. Insert text. Press mouse button 1 to set the insertion cursor, then |
| 41 | type text. What you type will be added to the widget. |
| 42 | |
| 43 | 4. Select. Press mouse button 1 and drag to select a range of characters. |
| 44 | Once you've released the button, you can adjust the selection by pressing |
| 45 | button 1 with the shift key down. This will reset the end of the |
| 46 | selection nearest the mouse cursor and you can drag that end of the |
| 47 | selection by dragging the mouse before releasing the mouse button. |
| 48 | You can double-click to select whole words or triple-click to select |
| 49 | whole lines. |
| 50 | |
| 51 | 5. Delete and replace. To delete text, select the characters you'd like |
| 52 | to delete and type Backspace or Delete. Alternatively, you can type new |
| 53 | text, in which case it will replace the selected text. |
| 54 | |
| 55 | 6. Copy the selection. To copy the selection into this window, select |
| 56 | what you want to copy (either here or in another application), then |
| 57 | click button 2 to copy the selection to the point of the mouse cursor. |
| 58 | |
| 59 | 7. Edit. Text widgets support the standard Motif editing characters |
| 60 | plus many Emacs editing characters. Backspace and Control-h erase the |
| 61 | character to the left of the insertion cursor. Delete and Control-d |
| 62 | erase the character to the right of the insertion cursor. Meta-backspace |
| 63 | deletes the word to the left of the insertion cursor, and Meta-d deletes |
| 64 | the word to the right of the insertion cursor. Control-k deletes from |
| 65 | the insertion cursor to the end of the line, or it deletes the newline |
| 66 | character if that is the only thing left on the line. Control-o opens |
| 67 | a new line by inserting a newline character to the right of the insertion |
| 68 | cursor. Control-t transposes the two characters on either side of the |
| 69 | insertion cursor. Control-z undoes the last editing action performed, |
| 70 | and } |
| 71 | |
| 72 | switch $tcl_platform(platform) { |
| 73 | "unix" - "macintosh" { |
| 74 | $w.text insert end "Control-Shift-z" |
| 75 | } |
| 76 | "windows" { |
| 77 | $w.text insert end "Control-y" |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | $w.text insert end { redoes undone edits. |
| 82 | |
| 83 | 7. Resize the window. This widget has been configured with the "setGrid" |
| 84 | option on, so that if you resize the window it will always resize to an |
| 85 | even number of characters high and wide. Also, if you make the window |
| 86 | narrow you can see that long lines automatically wrap around onto |
| 87 | additional lines so that all the information is always visible.} |
| 88 | $w.text mark set insert 0.0 |