4 namespace eval textprops {
7 if {![winfo exists .entrymenu]} {
8 menu .entrymenu -tearoff 0
9 foreach {event shortcut} {Cut Ctrl-X Copy Ctrl-C Paste Ctrl-V} {
10 .entrymenu add command -label $event -command "event generate \$::textprops::currentEntry <<$event>>" -accelerator $shortcut
12 .entrymenu add command -label Delete -command "event generate \$::textprops::currentEntry <Key-Delete>" -accelerator Del
14 if {![winfo exists .textmenu]} {
15 menu .textmenu -tearoff 0
16 foreach {event shortcut} {Undo Ctrl-Z Redo Ctrl-Shift-Z Cut
17 Ctrl-X Copy Ctrl-C Paste Ctrl-V} {
18 .textmenu add command -label $event -command "event generate \$textprops::currentText <<$event>>" -accelerator $shortcut
20 .textmenu insert Redo separator
21 .textmenu add command -label Delete -command "event generate \$::textprops::currentText <Key-Delete>" -accelerator Del
22 .textmenu add separator
23 .textmenu add command -label "Insert file..." -command [namespace code insertFile ]
30 set filename [tk_getOpenFile -title "Insert a file" -filetypes\
31 {{"Text files" {txt}} {"All files" {*}}}]
32 if {![string length $filename]} return
33 set f [open $filename]
34 set oldSeparator [$w cget -autoseparators]
35 if { $oldSeparator } {
36 $w configure -autoseparators 0
39 $w insert insert [read $f]
40 if { $oldSeparator } {
42 $w configure -autoseparators 1
47 proc textRightButton {widget x y} {
49 set hasSelection [llength [$widget tag ranges sel]]
51 .textmenu entryconfigure Copy -state normal
53 .textmenu entryconfigure Copy -state disabled
55 if {[$widget cget -state] eq "disabled"} {
56 foreach entry {Undo Redo Paste "Insert file..." Cut Delte} {
57 .textmenu entryconfigure $entry -state disabled
60 .textmenu entryconfigure "Insert file..." -state normal
61 if {[catch {clipboard get}]} {
62 .textmenu entryconfigure Paste -state disabled
64 .textmenu entryconfigure Paste -state normal
67 .textmenu entryconfigure Cut -state normal
68 .textmenu entryconfigure Delete -state normal
70 .textmenu entryconfigure Cut -state disabled
71 .textmenu entryconfigure Delete -state disabled
73 if {[$widget cget -undo]} {
74 if {[$widget edit modified]} {
75 .textmenu entryconfigure Undo -state normal
77 .textmenu entryconfigure Undo -state disabled
79 .textmenu entryconfigure Redo -state normal
81 .textmenu entryconfigure Undo -state disabled
82 .textmenu entryconfigure Redo -state disabled
86 set currentText $widget
87 tk_popup .textmenu $x $y
89 proc entryRightButton {widget x y} {
91 if {[$widget cget -state] eq "disabled"||[catch {clipboard get}]} {
92 .entrymenu entryconfigure Paste -state disabled
94 .entrymenu entryconfigure Paste -state normal
96 if {[$widget selection present]} {
97 .entrymenu entryconfigure Copy -state normal
98 if {[$widget cget -state] ne "disabled"} {
99 .entrymenu entryconfigure Cut -state normal
100 .entrymenu entryconfigure Delete -state normal
102 .entrymenu entryconfigure Cut -state disabled
103 .entrymenu entryconfigure Delete -state disabled
106 .entrymenu entryconfigure Cut -state disabled
107 .entrymenu entryconfigure Delete -state disabled
108 .entrymenu entryconfigure Copy -state disabled
110 set currentEntry $widget
111 tk_popup .entrymenu $x $y
114 bind Entry <Button-3> [namespace code {entryRightButton %W %X %Y}]
115 bind Text <Button-3> [namespace code {textRightButton %W %X %Y}]
118 package provide textprops