From 4f62fcbff4704a0ba24d6191d540f3f23955a3cf Mon Sep 17 00:00:00 2001 From: Sergey Kalinin Date: Wed, 7 Feb 2018 15:49:20 +0300 Subject: [PATCH] Add comment/uncomment selected text --- lib/editor.tcl | 48 +++++++++++++++++++++++++++++++++++++++---- lib/highlight/tcl.tcl | 1 + lib/html_lib.tcl | 1 + lib/main.tcl | 13 ++++++++++-- lib/procedure.tcl | 2 ++ lib/projects.tcl | 1 + projman.tcl | 1 + 7 files changed, 61 insertions(+), 6 deletions(-) diff --git a/lib/editor.tcl b/lib/editor.tcl index 9ab06ce..336ab2d 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -221,16 +221,13 @@ proc FindNext {text {incr 1}} { ## FIND FUNCTION PROCEDURE ## proc FindProc {text findString node} { global noteBook - set pos "0.0" $text see $pos set line [lindex [split $pos "."] 0] set x [lindex [split $pos "."] 1] - set pos [$text search -nocase $findString $line.$x end] $text mark set insert $pos $text see $pos - # highlight the found word set line [lindex [split $pos "."] 0] set x [lindex [split $pos "."] 1] @@ -955,7 +952,7 @@ proc EditFile {node fileName} { bind $text {FileDialog save} bind $text {FileDialog save} bind $text {FileDialog save_as} - bind $text {FileDialog save_as} + bind $text {FileDialog save_as} bind $text {FileDialog close} bind $text {FileDialog close} bind $text "tk_textCut $w.text;break" @@ -965,12 +962,23 @@ proc EditFile {node fileName} { bind $text "tk_textPaste $w.text;break" #bind $text "tk_textPaste $w.text;break" bind $text {TextOperation paste; break} + bind $text { + set nb [$noteBook raise] + if {$nb == "" || $nb == "newproj" || $nb == "about" || $nb == "debug"} { + return + } + set nb "$noteBook.f$nb" + SelectAll $nb.text + unset nb + } bind $text "auto_completition $text" bind $text "auto_completition $text" bind $text "auto_completition_proc $text" bind $text "auto_completition_proc $text" bind $text Find + bind $text {TextOperation comment} + bind $text {TextOperation uncomment} bind $text Find #bind . PageTab #bind . PageTab @@ -1167,6 +1175,37 @@ proc TextOperation {oper} { "cut" {tk_textCut $nb.text} "redo" {$nb.text edit redo} "undo" {$nb.text edit undo} + "comment" { + set selIndex [$nb.text tag ranges sel] + if {$selIndex != ""} { + set lineBegin [lindex [split [lindex $selIndex 0] "."] 0] + set lineEnd [lindex [split [lindex $selIndex 1] "."] 0] + for {set i $lineBegin} {$i <=$lineEnd} {incr i} { + $nb.text insert $i.0 "# " + } + $nb.text tag add comments $lineBegin.0 $lineEnd.end + $nb.text tag raise comments + } else { + return + } + } + "uncomment" { + set selIndex [$nb.text tag ranges sel] + if {$selIndex != ""} { + set lineBegin [lindex [split [lindex $selIndex 0] "."] 0] + set lineEnd [lindex [split [lindex $selIndex 1] "."] 0] + for {set i $lineBegin} {$i <=$lineEnd} {incr i} { + set str [$nb.text get $i.0 $i.end] + if {[regexp -nocase -all -line -- {(^| )(#+)(.+)} $str match v1 v2 v3]} { + $nb.text delete $i.0 $i.end + $nb.text insert $i.0 $v3 + } + } + $nb.text tag remove comments $lineBegin.0 $lineEnd.end + } else { + return + } + } } unset nb } @@ -1174,3 +1213,4 @@ proc TextOperation {oper} { GetOp + diff --git a/lib/highlight/tcl.tcl b/lib/highlight/tcl.tcl index e81ad15..63bbc8e 100644 --- a/lib/highlight/tcl.tcl +++ b/lib/highlight/tcl.tcl @@ -211,3 +211,4 @@ proc HighLightTCL {text line lineNumber node} { } } + diff --git a/lib/html_lib.tcl b/lib/html_lib.tcl index d9a6f44..acabb7e 100644 --- a/lib/html_lib.tcl +++ b/lib/html_lib.tcl @@ -1435,3 +1435,4 @@ proc HM::cgiMap {data} { #} + diff --git a/lib/main.tcl b/lib/main.tcl index 769fb77..6aa5803 100644 --- a/lib/main.tcl +++ b/lib/main.tcl @@ -40,7 +40,7 @@ $m add command -label [::msgcat::mc "Open"] -command {FileDialog open}\ $m add command -label [::msgcat::mc "Save"] -command {FileDialog save}\ -font $fontNormal -accelerator "Ctrl+S" $m add command -label [::msgcat::mc "Save as"] -command {FileDialog save_as}\ --font $fontNormal -accelerator "Ctrl+A" +-font $fontNormal $m add command -label [::msgcat::mc "Save all"] -command {FileDialog save_all}\ -font $fontNormal $m add command -label [::msgcat::mc "Close"] -command {FileDialog close}\ @@ -110,7 +110,7 @@ proc GetMenu {m} { $m add command -label [::msgcat::mc "Cut"] -font $fontNormal -accelerator "Ctrl+X"\ -command {TextOperation cut} $m add separator - $m add command -label [::msgcat::mc "Select all"] -font $fontNormal -accelerator "Ctrl+/"\ + $m add command -label [::msgcat::mc "Select all"] -font $fontNormal -accelerator "Ctrl+A"\ -command { set nb [$noteBook raise] if {$nb == "" || $nb == "newproj" || $nb == "about" || $nb == "debug"} { @@ -120,6 +120,11 @@ proc GetMenu {m} { SelectAll $nb.text unset nb } + $m add command -label [::msgcat::mc "Comment selected"] -font $fontNormal -accelerator "Ctrl+/"\ + -command {TextOperation comment} + $m add command -label [::msgcat::mc "Uncomment selected"] -font $fontNormal -accelerator "Ctrl+\\" \ + -command {TextOperation uncomment} + $m add separator $m add command -label [::msgcat::mc "Goto line"] -command GoToLine -font $fontNormal\ -accelerator "Ctrl+G" @@ -371,3 +376,7 @@ focus -force $tree + + + + diff --git a/lib/procedure.tcl b/lib/procedure.tcl index 9a097b4..7247fce 100644 --- a/lib/procedure.tcl +++ b/lib/procedure.tcl @@ -1085,3 +1085,5 @@ proc GetExtention {node} { + + diff --git a/lib/projects.tcl b/lib/projects.tcl index 9d50382..84bf5e4 100644 --- a/lib/projects.tcl +++ b/lib/projects.tcl @@ -912,3 +912,4 @@ proc InsertTitle {newFile type} { + diff --git a/projman.tcl b/projman.tcl index 14b1b44..366faed 100755 --- a/projman.tcl +++ b/projman.tcl @@ -119,3 +119,4 @@ option add *Scrollbar.background $editor(bg) startupFile +