Changeset 0e07e12 in tol for tolbase/lib/toltk/bystext.tcl
- Timestamp:
- Feb 15, 2012, 11:55:07 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 878425e
- Parents:
- 1efd6f9
- File:
-
- 1 edited
-
tolbase/lib/toltk/bystext.tcl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tolbase/lib/toltk/bystext.tcl
r1efd6f9 r0e07e12 8 8 #///////////////////////////////////////////////////////////////////////////// 9 9 # Put if {1} for testing this file. 10 11 package require snit 12 10 13 if {0} { 11 14 package require Tk … … 19 22 } 20 23 24 ::snit::widgetadaptor rotext { 25 26 constructor {args} { 27 # Turn off the insert cursor 28 #installhull using text $self -insertwidth 0 29 # DDG the $self gaves an error at least with 0.97 onwards 30 installhull using text -insertwidth 0 31 32 # Apply an options passed at creation time. 33 $self configurelist $args 34 } 35 36 # Disable the insert and delete methods, to make this readonly. 37 method insert {args} {} 38 method delete {args} {} 39 40 # Enable ins and del as synonyms, so the program can insert and 41 # delete. 42 delegate method ins to hull as insert 43 delegate method del to hull as delete 44 45 # Pass all other methods and options to the real text widget, so 46 # that the remaining behavior is as expected. 47 delegate method * to hull 48 delegate option * to hull 49 } 21 50 22 51 #///////////////////////////////////////////////////////////////////////////// … … 793 822 } 794 823 824 proc ::BayesText::TolEscape { buffer } { 825 return [ string map [ list \n \\n \t \\t \" \\\" \\ \\\\ ] $buffer ] 826 } 827 828 proc ::BayesText::DlgEscapeTextApply { editor } { 829 set w .dlgescape 830 831 set idxs [ $editor tag ranges sel ] 832 if { [ llength $idxs ] } { 833 foreach {i0 i1} $idxs break 834 $editor configure -undo 0 835 $editor delete $i0 $i1 836 $editor configure -undo 1 837 set f [ $w getframe ] 838 set buffer [ $f.t get 1.0 "end -1 char" ] 839 set len [ string length $buffer ] 840 $editor insert $i0 $buffer 841 $editor tag add sel $i0 "$i0 + $len char" 842 } 843 } 844 845 proc ::BayesText::DlgEscapeText { editor } { 846 set w .dlgescape 847 if { [ winfo exists $w ] } { 848 set f [ $w getframe ] 849 raise $w 850 focus $f.o 851 } else { 852 Dialog $w -title [ mc "Escape text" ] \ 853 -default 2 -modal none -parent $editor -separator 1 854 $w add -text [ mc "Close" ] -command "destroy $w" 855 $w add -text [ mc "Apply" ] 856 set f [ $w getframe ] 857 label $f.lo -text [ mc "Original:" ] 858 text $f.o -width 40 -height 4 859 label $f.lt -text [ mc "Transformed:" ] 860 rotext $f.t -width 40 -height 4 861 bind $f.o <<Modified>> { 862 if { [ %W edit modified ] == 1 } { 863 set f [ winfo parent %W ] 864 set tt $f.t 865 set buffer [ %W get 1.0 "end -1 char" ] 866 $tt del 1.0 end 867 $tt ins end [ ::BayesText::TolEscape $buffer ] 868 %W edit modified 0 869 } 870 } 871 grid $f.lo -row 0 -column 0 -sticky w 872 grid $f.o -row 1 -column 0 -sticky snew 873 grid $f.lt -row 0 -column 1 -sticky w 874 grid $f.t -row 1 -column 1 -sticky snew 875 foreach c {0 1} { 876 grid columnconfigure $f $c -weight 1 877 } 878 grid rowconfigure $f 1 -weight 1 879 $w draw 880 } 881 $f.o delete 1.0 end 882 set idxs [ $editor tag ranges sel ] 883 if { [ llength $idxs ] } { 884 $f.o insert end [ $editor get [ lindex $idxs 0 ] [ lindex $idxs 1 ] ] 885 } 886 $w itemconfigure 1 -command [ list ::BayesText::DlgEscapeTextApply $editor ] 887 } 795 888 796 889 #/////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.
