dgw::txmixins - functionality extensions for the tk::text widget such as folding, auto-indenting and abbreviations.
dgw::txmixins - The package dgw::txmixins implements several snit::widgetadaptors which extend the standard *tk::text* widget with different functionalities. Different adaptors can be chained together to add the required functionalities. Please note that most of the functionalities are not coded mainly by the author of the package DDG but just wrappers of the functionalities into snit::widgetadaptors for easy usage and combining the different properties and functionalities.
The following adaptors are currently available:
There is further a convenience function which simplifies addition of adaptors without a lot of nesting calls:
dgw::txfold
Let's create a folding text editor for Markdown files:
# demo: txfold dgw::txfold [tk::text .txt] foreach col [list A B C] { .txt insert end "# Header $col\n\nSome text\n\n" } .txt insert end "Place the cursor on the header lines and press F2\n" .txt insert end "or press F3 to fold or unfold the complete text.\n" .txt tag configure fold -background #cceeff .txt configure -borderwidth 10 -relief flat pack .txt -side top -fill both -expand yes # next line would fold by double click (although I like F2 more ...) # .txt configure -foldkey Double-1 bind .txt <Enter> { focus -force .txt }
Walking to the second section and pressing F2:
Global overview after two times pressing F3 (first unfold, then fold all):
You can navigate fast with the cursor into a section and unfold this section using F2. After editing here you can fold this section again and go to the next section.
Now an example for a Tcl or C folding editor: This will fold all lines starting with a letter and ending with a opening curly brace up to lines beginning with a closing curly brace.
set tcltxt [tk::text .tcl -borderwidth 5 -relief flat] dgw::txmixin $tcltxt dgw::txfold -foldstart "^\[A-Za-z\].+\{" -foldend "^\}" $tcltxt tag configure fold -background #aaccff $tcltxt insert end "package require Tk\nproc test {} {\n puts Hi\n}\n\nsnit::widget wid {\n\n}\n" pack $tcltxt -side left -fill both -expand true
dgw::txpopup
An example for a simple editor popup menu which can be installed easily with:
dgw::txpopup [tk::text pathname].
Here the example:
package require dgw::txmixins # demo: txpopup dgw::txpopup [tk::text .txt -undo true] ;# it is installed!! .txt insert end "\nHint\n\nPress right mouse click\n and see the" .txt insert end "popup menu with context dependent active or inactive entries!\n\n" foreach col [list A B C] { .txt insert end "# Header $col\n\nSome text\n\n" .txt insert end [dgw::txlipsum 2] .txt insert end "\n\n" } .txt configure -borderwidth 10 -relief flat dgw::txmixin .txt dgw::txblocksel ;# just another mixin can be easily installed pack .txt -side top -fill both -expand yes -padx 5 -pady 5 bind .txt <Enter> { focus -force .txt }
More examples are at the manual page .
Please discuss here.
DDG 2021-08-21 - the principal idea of mixins or snit widgetdaptors is to avoid huge megawidget constructions but just extend on the fly existing widgets with new functionalities.