[MEd] 2006-02-13: Another feature taken from [MetPad] (will be available in version 0.7). It adds block-selection capabilities to text widgets. The ''normal'' text widget selection is line-based, block selection allows you to select text ''square-based'' (well, not easy to explain, just try it out :) ########################################################## # Name: blocksel.tcl # Author: Martin Eder, snofix@users.sourceforge.net # Description: Enables block selection for text widgets ########################################################## variable spos proc block_sel {wid x y} { $wid tag remove sel 0.0 end set fpos [split [$wid index "@$x,$y"] "."] for {set sl [lindex $::spos 0]} {$sl <= [lindex $fpos 0]} {incr sl} { $wid tag add sel "$sl.[lindex $::spos 1]" "$sl.[lindex $fpos 1]" } } proc mouse_down {wid x y} { $wid mark set insert "@$x,$y" $wid tag remove sel 0.0 end set ::spos [split [$wid index insert] "."] } proc copy_blocksel {txt {cutit 0}} { set starttag [$txt index end] set mseltxt "" while {[set curmtag [$txt tag prevrange sel $starttag]] != ""} { set msta [lindex $curmtag 0] set msto [lindex $curmtag 1] set mseltxt "[$txt get $msta $msto]\n$mseltxt" if {$cutit == 1} {$txt delete $msta $msto} set starttag [lindex $curmtag 0] } if {$mseltxt != ""} { clipboard clear clipboard append -- $mseltxt } } bind Text [list mouse_down %W %x %y] bind Text [list block_sel %W %x %y] bind Text [list copy_blocksel .txt 1] bind Text [list copy_blocksel .txt 0] # Testing the code: pack [text .txt -font "Courier 10"] .txt insert end "To activate block-selection press Ctrl + left mouse button and keep pressed. Move the mouse to increase/decrease the block. Press Ctrl+c to copy the selection to the clipboard. Press Ctrl+x to cut the selection. Known Issues: -Difficulties with -Selection just works just from top-left to bottom-right" ### End Of Script