diff options
author | hobbs <hobbs> | 2001-11-13 00:19:05 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2001-11-13 00:19:05 (GMT) |
commit | e3690695eaccf83b8076fd877d17ed591c43065d (patch) | |
tree | 65c1489fbcc7a86e2140be2d55b1ffd0ccbd2577 /library | |
parent | 3027f28d1f2411602324f0964f7f1ad28742cf93 (diff) | |
download | tk-e3690695eaccf83b8076fd877d17ed591c43065d.zip tk-e3690695eaccf83b8076fd877d17ed591c43065d.tar.gz tk-e3690695eaccf83b8076fd877d17ed591c43065d.tar.bz2 |
added TIP#26 text widget undo/redo functionality
Diffstat (limited to 'library')
-rw-r--r-- | library/text.tcl | 53 | ||||
-rw-r--r-- | library/tk.tcl | 8 |
2 files changed, 56 insertions, 5 deletions
diff --git a/library/text.tcl b/library/text.tcl index 9abc9ae..c1a2b54 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # -# RCS: @(#) $Id: text.tcl,v 1.17 2001/08/27 01:44:48 dgp Exp $ +# RCS: @(#) $Id: text.tcl,v 1.18 2001/11/13 00:19:05 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -204,6 +204,7 @@ bind Text <Control-i> { } bind Text <Return> { tk::TextInsert %W \n + if {[%W cget -autoseparators]} {%W edit separator} } bind Text <Delete> { if {[string compare [%W tag nextrange sel 1.0 end] ""]} { @@ -338,6 +339,18 @@ bind Text <Control-t> { } } +bind Text <<Undo>> { + if { ! [ catch { %W edit undo } ] } { + %W see insert + } +} + +bind Text <<Redo>> { + if { ! [ catch { %W edit redo } ] } { + %W see insert + } +} + if {[string compare $tcl_platform(platform) "windows"]} { bind Text <Control-v> { if {!$tk_strictMotif} { @@ -518,6 +531,7 @@ proc ::tk::TextButton1 {w x y} { $w mark set insert [TextClosestGap $w $x $y] $w mark set anchor insert if {[string equal [$w cget -state] "normal"]} {focus $w} + if {[$w cget -autoseparators]} {$w edit separator} } # ::tk::TextSelectTo -- @@ -628,6 +642,18 @@ proc ::tk::TextKeyExtend {w index} { proc ::tk::TextPaste {w x y} { $w mark set insert [TextClosestGap $w $x $y] catch {$w insert insert [::tk::GetSelection $w PRIMARY]} + catch { + set oldSeparator [$w cget -autoseparators] + if {$oldSeparator} { + $w configure -autoseparators 0 + $w edit separator + } + $w insert insert [::tk::GetSelection $w PRIMARY] + if {$oldSeparator} { + $w edit separator + $w configure -autoseparators 1 + } + } if {[string equal [$w cget -state] "normal"]} {focus $w} } @@ -678,6 +704,7 @@ proc ::tk::TextSetCursor {w pos} { $w mark set insert $pos $w tag remove sel 1.0 end $w see insert + if {[$w cget -autoseparators]} {$w edit separator} } # ::tk::TextKeySelect @@ -785,14 +812,25 @@ proc ::tk::TextInsert {w s} { if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} { return } + set compound 0 catch { if {[$w compare sel.first <= insert] \ && [$w compare sel.last >= insert]} { + set oldSeparator [$w cget -autoseparators] + if { $oldSeparator } { + $w configure -autoseparators 0 + $w edit separator + set compound 1 + } $w delete sel.first sel.last } } $w insert insert $s $w see insert + if { $compound && $oldSeparator } { + $w edit separator + $w configure -autoseparators 1 + } } # ::tk::TextUpDownLine -- @@ -966,12 +1004,19 @@ proc ::tk_textCut w { proc ::tk_textPaste w { global tcl_platform catch { + set oldSeparator [$w cget -autoseparators] + if { $oldSeparator } { + $w configure -autoseparators 0 + $w edit separator + } if {[string compare $tcl_platform(platform) "unix"]} { - catch { - $w delete sel.first sel.last - } + catch { $w delete sel.first sel.last } } $w insert insert [::tk::GetSelection $w CLIPBOARD] + if { $oldSeparator } { + $w edit separator + $w configure -autoseparators 1 + } } } diff --git a/library/tk.tcl b/library/tk.tcl index 102ac4c..f62379b 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -3,7 +3,7 @@ # Initialization script normally executed in the interpreter for each # Tk-based application. Arranges class bindings for widgets. # -# RCS: @(#) $Id: tk.tcl,v 1.31 2001/08/01 16:21:11 dgp Exp $ +# RCS: @(#) $Id: tk.tcl,v 1.32 2001/11/13 00:19:05 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -313,6 +313,8 @@ switch $::tcl_platform(platform) { event add <<Copy>> <Control-Key-c> <Key-F16> event add <<Paste>> <Control-Key-v> <Key-F18> event add <<PasteSelection>> <ButtonRelease-2> + event add <<Undo>> <Control-Key-z> + event add <<Redo>> <Control-Key-Z> # Some OS's define a goofy (as in, not <Shift-Tab>) keysym # that is returned when the user presses <Shift-Tab>. In order for # tab traversal to work, we have to add these keysyms to the @@ -337,6 +339,8 @@ switch $::tcl_platform(platform) { event add <<Copy>> <Control-Key-c> <Control-Key-Insert> event add <<Paste>> <Control-Key-v> <Shift-Key-Insert> event add <<PasteSelection>> <ButtonRelease-2> + event add <<Undo>> <Control-Key-z> + event add <<Redo>> <Control-Key-y> } "macintosh" { event add <<Cut>> <Control-Key-x> <Key-F2> @@ -344,6 +348,8 @@ switch $::tcl_platform(platform) { event add <<Paste>> <Control-Key-v> <Key-F4> event add <<PasteSelection>> <ButtonRelease-2> event add <<Clear>> <Clear> + event add <<Undo>> <Control-Key-z> + event add <<Redo>> <Control-Key-Z> } } # ---------------------------------------------------------------------- |