?? editor.tcl
字號(hào):
#store current Spaces for restoring cursor position
set currentSpaces $spaces
# now setting the offset (spaces) for the next line
set spaces ""
for {set i 0} {$i < $level} {incr i} {
append spaces "$EditorData(indentString)"
}
if {$oldLine == $newLine} {
incr lineNum
continue
}
$TxtWidget delete "$lineNum.0" "$lineNum.0 lineend"
$TxtWidget insert "$lineNum.0" $newLine
incr lineNum
} ; #end of while
set startLine [lindex [split [$TxtWidget index $start] "."] 0]
set endLine [lindex [split [$TxtWidget index $end] "."] 0]
ColorizeLines $startLine $endLine
. configure -cursor $cursor
$TxtWidget configure -cursor $textCursor
update
#restore cursor position
incr lineNum -1
set cursorPos [expr $cursorPos + [string length $currentSpaces]]
$TxtWidget mark set insert $cursorLine.$cursorPos
if {$selection} {
$TxtWidget tag remove sel $start insert
}
$TxtWidget see insert
set Editor::prgindic -1
set Editor::status ""
}
# change tab to spaces
proc editorWindows::OnTabPress {} {
variable TxtWidget
global EditorData
if {$EditorData(options,changeTabs)} {
set spaces ""
for {set i 0} {$i < $EditorData(options,tabSize)} {incr i} {
append spaces " "
}
#insert spaces
$TxtWidget insert insert $spaces
} else {
#insert tab
$TxtWidget insert insert "\t"
}
Editor::selectObject 0
}
proc editorWindows::onKeyPressReturn {key} {
global EditorData
variable TxtWidget
set Editor::current(char) "\n"
if {!$EditorData(options,autoUpdate)} {
return list
}
if {[$TxtWidget tag ranges sel] != "" && $EditorData(options,autoUpdate)} {
set start [$TxtWidget index sel.first]
set end [$TxtWidget index sel.last]
set range [editorWindows::deleteMarks $start $end]
$TxtWidget mark set delStart [lindex $range 0]
$TxtWidget mark gravity delStart left
$TxtWidget mark set delEnd [lindex $range 1]
$TxtWidget delete sel.first sel.last
$TxtWidget insert insert $key
if {[$TxtWidget compare insert > delEnd]} {
$TxtWidget mark set delEnd insert
}
Editor::updateOnIdle [list [$TxtWidget index delStart] [$TxtWidget index delEnd]]
$TxtWidget mark unset delStart
$TxtWidget mark unset delEnd
return break
} else {
return list
}
}
# reaction on key releasing
proc editorWindows::OnKeyRelease {} {
global EditorData
variable TxtWidget
catch {
switch -regexp -- $Editor::current(char) {
"\n" {
# Return
set lineNum [lindex [split [$TxtWidget index insert] "."] 0]
set Editor::current(lastPos) [$Editor::current(text) index insert]
ReadCursor
ColorizeLine $lineNum
set Editor::current(procListHistoryPos) 0
}
{.} {
#printable chars
switch -- $Editor::current(char) {
"\{" {editorWindows::OnLeftBraceRelease}
"\}" {editorWindows::IndentCurLine}
"\[" {editorWindows::OnLeftBracketRelease}
}
if {$Editor::current(isNode) && $EditorData(options,autoUpdate)} {
#if there磗 a pending update only store new range
Editor::updateOnIdle [list [$TxtWidget index insert] [$TxtWidget index insert]]
} elseif {$EditorData(options,autoUpdate)} {
Editor::selectObject 1
} else {
Editor::selectObject 0
}
set lineNum [lindex [split [$TxtWidget index insert] "."] 0]
set Editor::current(lastPos) [$Editor::current(text) index insert]
ReadCursor
ColorizeLine $lineNum
set Editor::current(procListHistoryPos) 0
}
default {
#non printable chars
Editor::selectObject 0
set Editor::current(lastPos) [$Editor::current(text) index insert]
ReadCursor
}
}
}
set Editor::current(char) ""
}
#reaction on space release
proc editorWindows::OnSpaceRelease {} {
global EditorData
variable TxtWidget
if {!$EditorData(options,useTemplates) || !$EditorData(options,useTemplatesForKeywords)} {
return
}
set templateKeyword [GetTemplateKeyword [$TxtWidget get "insert linestart" "insert lineend"]]
set curPos [$TxtWidget index insert]
set lineNum [lindex [split $curPos "."] 0]
switch -- $templateKeyword {
"if" {
$TxtWidget insert insert " \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
"for" {
$TxtWidget insert insert " \{\} \{\} \{\} \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert "$curPos +1ch"
}
"foreach" {
$TxtWidget insert insert " \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
"while" {
$TxtWidget insert insert " \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
"switch" {
$TxtWidget insert insert " \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
"proc" {
$TxtWidget insert insert " \{\} \{\n\}"
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
"else" {
$TxtWidget insert insert " \{\n\n\}"
ColorizeLine $lineNum
incr lineNum
IndentLine $lineNum
incr lineNum
IndentLine $lineNum
incr lineNum -1
$TxtWidget mark set insert "$lineNum.0 lineend"
}
"elseif" {
$TxtWidget insert insert " \{\n\}"
ColorizeLine $lineNum
incr lineNum
IndentLine $lineNum
$TxtWidget mark set insert $curPos
}
}
return 0
}
proc editorWindows::OnLeftBraceRelease {} {
variable TxtWidget
global EditorData
if {!$EditorData(options,useTemplates) || !$EditorData(options,useTemplatesForBrace)} {
return
}
set curPos [$TxtWidget index insert]
$TxtWidget insert insert "\}"
$TxtWidget mark set insert $curPos
return
}
proc editorWindows::OnLeftParenRelease {} {
variable TxtWidget
global EditorData
if {!$EditorData(options,useTemplates) || !$EditorData(options,useTemplatesForParen)} {
return
}
set curPos [$TxtWidget index insert]
$TxtWidget insert insert "\)"
$TxtWidget mark set insert $curPos
Editor::selectObject 0
return
}
proc editorWindows::OnLeftBracketRelease {} {
variable TxtWidget
global EditorData
if {!$EditorData(options,useTemplates) || !$EditorData(options,useTemplatesForBracket)} {
return
}
set curPos [$TxtWidget index insert]
$TxtWidget insert insert "\]"
$TxtWidget mark set insert $curPos
return
}
proc editorWindows::OnQuoteDblRelease {} {
variable TxtWidget
global EditorData
if {!$EditorData(options,useTemplates) || !$EditorData(options,useTemplatesForQuoteDbl)} {
return
}
set curPos [$TxtWidget index insert]
$TxtWidget insert insert "\""
$TxtWidget mark set insert $curPos
Editor::selectObject 0
return
}
# reaction on mouse button release
proc editorWindows::OnMouseRelease {} {
variable TxtWidget
ReadCursor
ColorizePair
set oldNode $Editor::current(node)
set curNode [Editor::selectObject 0]
if {$oldNode != $curNode} {
Editor::procList_history_add $Editor::current(lastPos)
} else {
Editor::procList_history_update
}
set Editor::current(lastPos) [$TxtWidget index insert]
}
# read information about cursor and set it to the global variables
proc editorWindows::ReadCursor {{selectProc 1}} {
variable TxtWidget
global EditorData
set insertPos [split [$TxtWidget index insert] "."]
set EditorData(cursor,line) [lindex $insertPos 0]
set EditorData(cursor,pos) [expr {[lindex $insertPos 1] }]
set EditorData(cursorPos) "Line: $EditorData(cursor,line) Pos: $EditorData(cursor,pos)"
set Editor::lineNo $EditorData(cursor,line)
return
}
proc editorWindows::enableHL {} {
variable TxtWidget
if {$TxtWidget != ""} {
colorize
}
return
}
proc editorWindows::disableHL {} {
variable TxtWidget
if {$TxtWidget != ""} {
# delete all tags
$TxtWidget tag delete comment
$TxtWidget tag delete keyword
ConfigureTags
}
return
}
proc editorWindows::colorize {} {
variable TxtWidget
variable EditorData
# get number of lines
set lineEnd [lindex [split [$TxtWidget index end] "."] 0]
ColorizeLines 1 $lineEnd
}
proc editorWindows::ColorizeLines {StartLine EndLine} {
variable TxtWidget
# delete all tags
$TxtWidget tag remove comment "$StartLine.0" "$EndLine.0 lineend"
$TxtWidget tag remove keyword "$StartLine.0" "$EndLine.0 lineend"
for {set lineNum $StartLine} {$lineNum <= $EndLine} {incr lineNum} {
ColorizeLine $lineNum
}
return
}
proc editorWindows::ColorizeLine {lineNum} {
variable TxtWidget
global EditorData
if {!$EditorData(options,useHL)} {
return
}
# get line
set line [$TxtWidget get $lineNum.0 "$lineNum.0 lineend"]
set range [IsComment $line $lineNum]
if {$range != {}} {
# this is comment
# set comment font
eval $TxtWidget tag remove keyword $range
eval $TxtWidget tag add comment $range
} else {
$TxtWidget tag remove comment $lineNum.0 "$lineNum.0 lineend"
set range [GetKeywordCoord $line $lineNum]
if {$range != {} } {
eval $TxtWidget tag add keyword $range
} else {
$TxtWidget tag remove keyword $lineNum.0 "$lineNum.0 lineend"
}
}
return
}
proc editorWindows::ConfigureTags {} {
variable TxtWidget
global EditorData
# blue is specially for Lapshin
$TxtWidget tag configure comment -font $EditorData(options,fonts,commentFont) -foreground blue
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -