Add comment/uncomment selected text

This commit is contained in:
Sergey Kalinin 2018-02-07 15:49:20 +03:00
parent 24581a98d4
commit 4f62fcbff4
7 changed files with 61 additions and 6 deletions

View File

@ -221,16 +221,13 @@ proc FindNext {text {incr 1}} {
## FIND FUNCTION PROCEDURE ## ## FIND FUNCTION PROCEDURE ##
proc FindProc {text findString node} { proc FindProc {text findString node} {
global noteBook global noteBook
set pos "0.0" set pos "0.0"
$text see $pos $text see $pos
set line [lindex [split $pos "."] 0] set line [lindex [split $pos "."] 0]
set x [lindex [split $pos "."] 1] set x [lindex [split $pos "."] 1]
set pos [$text search -nocase $findString $line.$x end] set pos [$text search -nocase $findString $line.$x end]
$text mark set insert $pos $text mark set insert $pos
$text see $pos $text see $pos
# highlight the found word # highlight the found word
set line [lindex [split $pos "."] 0] set line [lindex [split $pos "."] 0]
set x [lindex [split $pos "."] 1] set x [lindex [split $pos "."] 1]
@ -955,7 +952,7 @@ proc EditFile {node fileName} {
bind $text <Control-ucircumflex> {FileDialog save} bind $text <Control-ucircumflex> {FileDialog save}
bind $text <Control-s> {FileDialog save} bind $text <Control-s> {FileDialog save}
bind $text <Control-ocircumflex> {FileDialog save_as} bind $text <Control-ocircumflex> {FileDialog save_as}
bind $text <Control-a> {FileDialog save_as} bind $text <Shift-Control-s> {FileDialog save_as}
bind $text <Control-odiaeresis> {FileDialog close} bind $text <Control-odiaeresis> {FileDialog close}
bind $text <Control-w> {FileDialog close} bind $text <Control-w> {FileDialog close}
bind $text <Control-division> "tk_textCut $w.text;break" bind $text <Control-division> "tk_textCut $w.text;break"
@ -965,12 +962,23 @@ proc EditFile {node fileName} {
bind $text <Control-igrave> "tk_textPaste $w.text;break" bind $text <Control-igrave> "tk_textPaste $w.text;break"
#bind $text <Control-v> "tk_textPaste $w.text;break" #bind $text <Control-v> "tk_textPaste $w.text;break"
bind $text <Control-v> {TextOperation paste; break} bind $text <Control-v> {TextOperation paste; break}
bind $text <Control-a> {
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 <Control-adiaeresis> "auto_completition $text" bind $text <Control-adiaeresis> "auto_completition $text"
bind $text <Control-l> "auto_completition $text" bind $text <Control-l> "auto_completition $text"
bind $text <Control-icircumflex> "auto_completition_proc $text" bind $text <Control-icircumflex> "auto_completition_proc $text"
bind $text <Control-j> "auto_completition_proc $text" bind $text <Control-j> "auto_completition_proc $text"
bind $text <Control-q> Find bind $text <Control-q> Find
bind $text <Control-slash> {TextOperation comment}
bind $text <Control-backslash> {TextOperation uncomment}
bind $text <Control-eacute> Find bind $text <Control-eacute> Find
#bind . <Control-m> PageTab #bind . <Control-m> PageTab
#bind . <Control-udiaeresis> PageTab #bind . <Control-udiaeresis> PageTab
@ -1167,6 +1175,37 @@ proc TextOperation {oper} {
"cut" {tk_textCut $nb.text} "cut" {tk_textCut $nb.text}
"redo" {$nb.text edit redo} "redo" {$nb.text edit redo}
"undo" {$nb.text edit undo} "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 unset nb
} }
@ -1174,3 +1213,4 @@ proc TextOperation {oper} {
GetOp GetOp

View File

@ -211,3 +211,4 @@ proc HighLightTCL {text line lineNumber node} {
} }
} }

View File

@ -1435,3 +1435,4 @@ proc HM::cgiMap {data} {
#} #}

View File

@ -40,7 +40,7 @@ $m add command -label [::msgcat::mc "Open"] -command {FileDialog open}\
$m add command -label [::msgcat::mc "Save"] -command {FileDialog save}\ $m add command -label [::msgcat::mc "Save"] -command {FileDialog save}\
-font $fontNormal -accelerator "Ctrl+S" -font $fontNormal -accelerator "Ctrl+S"
$m add command -label [::msgcat::mc "Save as"] -command {FileDialog save_as}\ $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}\ $m add command -label [::msgcat::mc "Save all"] -command {FileDialog save_all}\
-font $fontNormal -font $fontNormal
$m add command -label [::msgcat::mc "Close"] -command {FileDialog close}\ $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"\ $m add command -label [::msgcat::mc "Cut"] -font $fontNormal -accelerator "Ctrl+X"\
-command {TextOperation cut} -command {TextOperation cut}
$m add separator $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 { -command {
set nb [$noteBook raise] set nb [$noteBook raise]
if {$nb == "" || $nb == "newproj" || $nb == "about" || $nb == "debug"} { if {$nb == "" || $nb == "newproj" || $nb == "about" || $nb == "debug"} {
@ -120,6 +120,11 @@ proc GetMenu {m} {
SelectAll $nb.text SelectAll $nb.text
unset nb 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 separator
$m add command -label [::msgcat::mc "Goto line"] -command GoToLine -font $fontNormal\ $m add command -label [::msgcat::mc "Goto line"] -command GoToLine -font $fontNormal\
-accelerator "Ctrl+G" -accelerator "Ctrl+G"
@ -371,3 +376,7 @@ focus -force $tree

View File

@ -1085,3 +1085,5 @@ proc GetExtention {node} {

View File

@ -912,3 +912,4 @@ proc InsertTitle {newFile type} {

View File

@ -119,3 +119,4 @@ option add *Scrollbar.background $editor(bg) startupFile