⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editorpane.tcl

📁 This Source-Navigator, an IDE for C/C++/Fortran/Java/Tcl/PHP/Python and a host of other languages.
💻 TCL
📖 第 1 页 / 共 5 页
字号:
	    set edit_SearchString ${string}	} else {	    set string ${edit_SearchString}	}	# Insert the string into the search history!	sn_add_to_histroy_stack sn_options(search) ${string}	sn_log "Editor::SearchForNext resetting combo text to \"$string\""		$itk_option(-findcombo) configure \	    -contents $sn_options(search) \	    -entrytext ${string}# FIXME: Why would we check edit_SearchString again?	# Make sure that we have the correct value.	if {${edit_SearchString} == ""} {	    set edit_SearchString ${string}	}	if {${string} == ""} {	    set string ${edit_SearchString}	}	if {${string} == ""} {	    bell	    return	}	set ranges [$itk_component(editor) tag ranges sel]	# Skip selection, if the selection is equal to the string	#is looking for	if {${ranges} != ""} {	    #if nocase is on, make nocase comparing.	    if {${edit_SearchNoCase} != ""} {		set cmp1 [string tolower [eval $itk_component(editor) get ${ranges}]]		set cmp2 [string tolower ${string}]	    } else {		set cmp1 [eval $itk_component(editor) get ${ranges}]		set cmp2 ${string}	    }	    #by regexp, we can't compare the string looking for.	    if {[string compare ${cmp1} ${cmp2}] == 0 || ${edit_SearchMethod} == \	      "-regexp"} {		if {${edit_SearchDirection} == "-forwards"} {		    set idx [$itk_component(editor) index "[lindex ${ranges} 0] + 1c"]		} else {		    set idx [lindex ${ranges} 0]		}	    } else {		set idx [$itk_component(editor) index insert]	    }	} else {	    set idx [$itk_component(editor) index insert]	}	# Remove the current selection.	$itk_component(editor) tag remove sel 0.0 end	# Search !	set cmd [list $itk_component(editor) search ${edit_SearchMethod} ${edit_SearchDirection}]	if {${edit_SearchNoCase} != ""} {	    lappend cmd ${edit_SearchNoCase}	}	lappend cmd \	    -count SearchFoundLength \	    -- ${string}         set testcmd $cmd        lappend cmd ${idx}	set pos [eval ${cmd}]        # Now, if this is that last occurrance in the file        # we have to beeps.                if {$SearchFoundLength == 0 || $pos == ""} {            # There are no search results.            bell            return        } else {            lappend testcmd "${pos} + ${SearchFoundLength} chars" end            # Check for more search results.                    if {[eval $testcmd] == ""} {                bell                sn_log "SearchForNext: Last occurrance has been found.(beep)"            }        }	if {[string compare ${pos} ""] != 0} {	    $itk_component(editor) tag add sel ${pos} "${pos} + ${SearchFoundLength} chars"            $itk_component(editor) tag raise sel	    $itk_component(editor) mark set lastpos insert	    $itk_component(editor) mark set insert ${pos}	    $itk_component(editor) see insert	    set df [expr abs(int([$itk_component(editor) index "@0,[winfo height \	      $itk_component(editor)]"]) - int(${pos}))]	    # If the target is closer to the bottom of the page than 3 lines, \	      center it!	    if {${df} <= 3} {		$itk_component(editor) yview scroll [expr int([text_page_num_lines \		  $itk_component(editor)] / 2)] units	    }	    if {[winfo exists ${top}]} {		${top} transient $itk_component(editor)	    }	} else {	    bell	}    }    ############################################    # Replace command    # Get a search&replace string from the user and search for it in the    # specified text widget. Then replace those occurrences by the    # replace string.    ############################################    # Find all occurrences of the text in the file, and feed them through    # the specified search/replace algorithm    method ReplaceAll {w} {	if {${edit_SearchString} == ""} {	    bell	    return	}	set pos end	while {${pos} != ""} {	    set pos [eval ${w} search ${edit_SearchMethod} ${edit_SearchNoCase} \	        -backwards -count len \	        -- [list ${edit_SearchString}] [list ${pos}] 1.0]	    if {${pos} != ""} {		tkTextReplace ${w} ${pos} "${pos} + ${len} char" \		  ${edit_ReplaceString}	    }	}	${w} see insert    }    #called when the variable is changed    method StringModified_cb {btns name1 name2 op} {#FIXME: This is changing the linked variable (the search text)	upvar #0 ${name1} v	if {![info exists v]} {	    return	}	if {${v} != ""} {	    set state normal	} else {	    set state disabled	}	foreach btn ${btns} {	    if {[winfo exists ${btn}]} {		${btn} config \		    -state ${state}	    }	}    }    #add trace for search string to enable/disable related buttons    method Trace_SearchString {btn} {# FIXME: A trace is getting added on top of the existing edit_SearchString# which is likely hosing the result in the search text box	trace variable [itcl::scope edit_SearchString] w [list ${this} \	  StringModified_cb ${btn}]    }    #remove tracing by closing the search window.    method Delete_Trace_SearchString {btn} {	trace vdelete [itcl::scope edit_SearchString] w [list ${this} \	  StringModified_cb ${btn}]	catch {unset edit_SearchString}    }    method Replace_String {btn} {	if {${edit_ReplaceString} != ""} {	    tkTextInsertChar $itk_component(editor) ${edit_ReplaceString}	} else {	    tkTextDelete $itk_component(editor) sel.first sel.last	}	$itk_component(editor) tag add sel "insert -[string length ${edit_ReplaceString}] \	  char" insert        $itk_component(editor) tag raise sel	${btn} config \	    -state disabled    }    method Replace {} {	global sn_options	global SearchFoundLength	set w $itk_component(editor)	catch {	    set edit_SearchString [string trim [selection get]]	}	set s ${topw}.replace	if {[winfo exists ${s}]} {	    raise ${s}	    return	}	set strchk ${s}.strchk	set strs ${strchk}.strings	set str1 ${strs}.str1	set str2 ${strs}.str2	set buts ${s}.but	set chks ${strchk}.chks	sourcenav::Window ${s}	${s} configure -title [sn_title [get_indep String FindReplace]]	${s} on_close "${this} Delete_Trace_SearchString ${buts}.all; itcl::delete object $s"	set foc [focus]	if {${foc} == ""} {	    set foc ${w}	}	${s} transient ${foc}	frame ${strchk}	pack ${strchk} \	    -side left \	    -expand y \	    -fill x	frame ${strs}	pack ${strs} \	    -side top \	    -expand y \	    -fill x	#find string	frame ${str1}	pack ${str1} \	    -side top \	    -expand y \	    -fill x \	    -pady 5 \	    -padx 5	label ${str1}.label \	    -width 14 \	    -text [get_indep String SearchPattern] \	    -underline [get_indep Pos SearchPattern] \	    -anchor w	pack ${str1}.label \	    -side left	entry ${str1}.entry \	    -relief sunken \	    -bd 3 \	    -exportselection no \	    -textvariable [itcl::scope edit_SearchString]	bind ${str1}.entry <Tab> "focus ${str2}.entry"	bind ${str1}.entry <Return> "${buts}.next invoke"	${str1}.entry select to end	pack ${str1}.entry \	    -side left \	    -fill x \	    -expand y	Trace_SearchString ${buts}.all	#replace with string	frame ${str2}	pack ${str2} \	    -side top \	    -expand y \	    -fill x \	    -pady 5 \	    -padx 5	label ${str2}.label \	    -width 14 \	    -text [get_indep String ReplacePattern] \	    -underline [get_indep Pos ReplacePattern] \	    -anchor w	pack ${str2}.label \	    -side left	entry ${str2}.entry \	    -relief sunken \	    -bd 3 \	    -exportselection no \	    -textvariable [itcl::scope edit_ReplaceString]	pack ${str2}.entry \	    -side left \	    -fill x \	    -expand y	bind ${str2}.entry <Return> "${buts}.next invoke"	bind ${str2}.entry <Tab> "focus ${str1}.entry"	#checkbuttons	frame ${chks}	pack ${chks} \	    -side top \	    -expand y \	    -fill x \	    -pady 10 \	    -padx 10	checkbutton ${chks}.case \	    -text [get_indep String IgnoreCase] \	    -underline [get_indep Pos IgnoreCase] \	    -variable [itcl::scope edit_SearchNoCase] \	    -onvalue "-nocase" \	    -offvalue ""	checkbutton ${chks}.regexp \	    -text [get_indep String RegExp] \	    -underline [get_indep Pos RegExp] \	    -variable [itcl::scope edit_SearchMethod] \	    -onvalue "-regexp" \	    -offvalue "-exact"	checkbutton ${chks}.forward \	    -text [get_indep String SQLFfor] \	    -underline [get_indep Pos SQLFfor] \	    -variable [itcl::scope edit_SearchDirection] \	    -onvalue "-forwards" \	    -offvalue "-backwards"	pack ${chks}.case \	    -anchor nw \	    -side top \	    -padx 35	pack ${chks}.regexp \	    -anchor nw \	    -side top \	    -padx 35	pack ${chks}.forward \	    -anchor nw \	    -side top \	    -padx 35	#buttons	frame ${buts}	pack ${buts} \	    -side right \	    -pady 5 \	    -padx 5	button ${buts}.cancel \	    -text [get_indep String Cancel] \	    -underline [get_indep Pos Cancel] \	    -command "		${this} Delete_Trace_SearchString ${buts}.cancel		itcl::delete object ${s}	    "	button ${buts}.next \	    -text [get_indep String UtilSearch] \	    -underline [get_indep Pos UtilSearch] \	    -command "		${this} SearchForNext		if {\$SearchFoundLength > 0} {						${buts}.replace config -state normal					} else {						${buts}.replace config -state disabled					}	    "	# We check whether the pattern can be found at the insertation point.	# It must be also selected	set pos [eval ${w} search ${edit_SearchMethod} ${edit_SearchNoCase} \	    -count SearchFoundLength \	    -- [list ${edit_SearchString}] insert]	if {[string compare ${pos} ""] != 0 && [${w} compare insert == \	  ${pos}]} {	    if {[${w} tag ranges sel] != ""} {		set state normal	    } else {		set state disabled	    }	} else {	    set state disabled	}	button ${buts}.replace \	    -text [get_indep String PafReplace] \	    -underline [get_indep Pos PafReplace] \	    -state ${state} \	    -command "${this} Replace_String ${buts}.replace"	if {${edit_SearchString} == ""} {	    set state disabled	} else {	    set state normal	}	button ${buts}.all \	    -text [get_indep String All] \	    -state ${state} \	    -command "${this} ReplaceAll ${w}"	pack ${buts}.next \	    -fill x \	    -side top \	    -padx 10 \	    -pady 5	pack ${buts}.cancel \	    -fill x \	    -side top \	    -padx 10 \	    -pady 5	pack ${buts}.replace \	    -fill x \	    -side top \	    -padx 10 \	    -pady 5	pack ${buts}.all \	    -fill x \	    -side top \	    -padx 10 \	    -pady 5	focus ${str1}.entry	${s} move_to_mouse	catch {${s} resizable yes no}	catch {${s} grab set}	update idletasks	set geom [split [lindex [split [${s} geometry] "+"] 0] "x"]	${s} minsize [lindex ${geom} 0] [lindex ${geom} 1]    }    #    # Goto a specified line in the file    #    method GotoLine {} {	global sn_options	set w $itk_component(editor)	set pos -2	if {[catch {set pos [string trim [selection get]]}] == 0} {	    if {[catch {set pos [expr int(${pos})]}]} {		set pos -1	    }	}	if {${pos} < 0} {	    set $itk_option(-linenumber_var) [${w} index insert]	} else {	    set $itk_option(-linenumber_var) ${pos}	}	set f [sourcenav::Window ${topw}.goto]	${f} configure -title [sn_title [get_indep String EditGotoLine]]	${f} configure -iconname [get_indep String EditGotoLine]	${f} transient ${topw}	frame ${f}.line	label ${f}.line.label \	    -text [get_indep String LineNumber] \	    -underline [get_indep Pos LineNumber] \	    -width 13 \	    -anchor w	set line 0	set char 0	entry ${f}.line.entry \	    -width 14 \	    -relief sunken \	    -bd 3 \	    -textvariable $itk_option(-linenumber_var) \	    -exportselection n	${f}.line.entry select to end	button ${f}.line.button \	    -text [get_indep String Goto] \	    -underline [get_indep Pos Goto] \	    -command "${this} proceed_gotoline ${f}"	pack ${f}.line.label \	    -side left	pack ${f}.line.entry \	    -side left	pack ${f}.line.button \	    -side left \	    -pady 10 \	    -padx 20	bind ${f}.line.entry <Return> "${f}.line.button invoke"	focus ${f}.line.entry	pack ${f}.line \	    -side top \	    -fill both	focus ${f}.line.entry	${f} move_to_mouse	catch {${f} resizable no no}	catch {${f} grab set}    }    method proceed_gotoline {f} {	global tcl_platform        # FIXME : This is ugly, but the -linenumber_var gets        # changed because the vwait in sn_wait will process        # Focus_In which resets the variable. We hack this        # by saving and resetting the variable here (ugh).        # This fixes goto line under Win32.        set linenum [set $itk_option(-linenumber_var)]	itcl::delete object ${f}	update idletasks	if {$tcl_platform(platform) == "windows"} {	    sn_wait 50	}        set $itk_option(-linenumber_var) $linenum

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -