Add comment/uncomment selected text
This commit is contained in:
parent
24581a98d4
commit
4f62fcbff4
|
@ -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 <Control-ucircumflex> {FileDialog save}
|
||||
bind $text <Control-s> {FileDialog save}
|
||||
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-w> {FileDialog close}
|
||||
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-v> "tk_textPaste $w.text;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-l> "auto_completition $text"
|
||||
bind $text <Control-icircumflex> "auto_completition_proc $text"
|
||||
bind $text <Control-j> "auto_completition_proc $text"
|
||||
bind $text <Control-q> Find
|
||||
bind $text <Control-slash> {TextOperation comment}
|
||||
bind $text <Control-backslash> {TextOperation uncomment}
|
||||
bind $text <Control-eacute> Find
|
||||
#bind . <Control-m> PageTab
|
||||
#bind . <Control-udiaeresis> 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
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -211,3 +211,4 @@ proc HighLightTCL {text line lineNumber node} {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1435,3 +1435,4 @@ proc HM::cgiMap {data} {
|
|||
#}
|
||||
|
||||
|
||||
|
||||
|
|
13
lib/main.tcl
13
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
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1085,3 +1085,5 @@ proc GetExtention {node} {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -912,3 +912,4 @@ proc InsertTitle {newFile type} {
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -119,3 +119,4 @@ option add *Scrollbar.background $editor(bg) startupFile
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user