dgw::txmixins

NAME

dgw::txmixins - functionality extensions for the tk::text widget such as folding, auto-indenting and abbreviations.

DESCRIPTION

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:

  • dgw::txautorep - short abbreviations snippets invoked after closing parenthesis
  • dgw::txblocksel - adaptor for rectangular text selection in the text widget
  • dgw::txfileproc - adaptor which implements the typical file commands for the text widget, fileOpen, fileSave etc.
  • dgw::txhighlight - adaptor for text widget supporting syntax highlighting
  • dgw::txfold - provide fold marks to hide and show certain parts of the text, for instance to navigate fast a large markdown file by just showing the section headers
  • dgw::txindent - keep indentation of previous line
  • dgw::txpopup - adaptor for typical right click popup implementation
  • dgw::txrotext - read only text widget

There is further a convenience function which simplifies addition of adaptors without a lot of nesting calls:

  • dgw::txmixin - add widgets adaptors to existing widgets after widget creation

LINKS

EXAMPLES

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 }

txfold-image-01

Walking to the second section and pressing F2:

txfold-image-02

Global overview after two times pressing F3 (first unfold, then fold all):

txfold-image-03

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 }

txmixins-txpopup

More examples are at the manual page .


CHANGES

  • 2021-08-19: 0.1 first release
  • 2021-09-20: 0.2 second release added txhighlight, txpopup, txblocksel and txfileproc

SEE ALSO

DISCUSSION

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.