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

📄 editorpane.tcl

📁 This Source-Navigator, an IDE for C/C++/Fortran/Java/Tcl/PHP/Python and a host of other languages.
💻 TCL
📖 第 1 页 / 共 5 页
字号:
	if {$itk_option(-filename) != ${f}} {	    set itk_option(-filename) ${f}	}	# Change to the project directory.	catch {cd $sn_options(sys,project-dir)}	if {[catch {set lastpos [$itk_component(editor) index insert]}]} {	    set lastpos 1.0	}	if {[catch {set markpos [$itk_component(editor) index markpos]}]} {	    set markpos 1.0	}	# Disable synchronize mode.	incr SyncEditors_Disabled	# Change view-mode to normal.	set old_mode [$itk_component(editor) cget -state]	if {${old_mode} != "normal"} {	    $itk_component(editor) config \	        -state normal	}	# Open an existing file.	if {[file exists $itk_option(-filename)]} {	    # Verify if there is a buffer with the same filename.	    set other [find_Editor_with_File $itk_option(-filename) ${this}]	    if {${revert} != "revert" && ${other} != ""} {		# Call the friend function to copy the contents		# from the other editor into the actual editor.		friend_copy ${this} ${other}	    } else {		# Load the file from disk.		if {[catch {set f [open $itk_option(-filename) r]} msg]} {		    sn_error_dialog "${msg} $itk_option(-filename)"		    return		}		fconfigure ${f} \		    -encoding $sn_options(def,encoding) \		    -blocking 0		$itk_component(editor) delete 1.0 end		$itk_component(editor) insert 1.0 \                    [read -nonewline ${f}]		close ${f}		$this configure -file_changed 0		# Save modification time.		set file_mtime [file mtime $itk_option(-filename)]	    }	    # Color tags.	    color_file ${run_parse}	} else {	    # Edit new file.	    $itk_component(editor) delete 1.0 end	    # When nothing is typed in, the file isn't modified!!	    $this configure -file_changed 0	    # No modification time.	    set file_mtime 0	    # Delete entries from combobox.	    if {$itk_option(-symbols) != ""} {                $itk_option(-symbols) configure -contents "" -entrytext ""	    }	}	# Revert undo list.	tkTextUndoSetup $itk_component(editor)	# Mark last position.	$itk_component(editor) mark set lastpos ${lastpos}	$itk_component(editor) mark set markpos ${markpos}	$itk_component(editor) mark set insert 0.0	$itk_component(editor) tag remove sel 0.0 end	# Goto specified position.	if {${line} != "" && ${line} >= 0} {	    SetFondPos ${line} 1 0	}	# Restore old view-mode.	if {${old_mode} != "normal"} {	    $itk_component(editor) config \	        -state ${old_mode}	}	# Reenable synchronize mode.	incr SyncEditors_Disabled -1	# Configure reusable button to the modified flag.	DispModified	# Set filename on the title.	SetTitle	focus $itk_component(editor)	# Successfull	return 1    }    method get_file_symbols {file} {	global sn_options sn_sep	if {[::info commands paf_db_fil] == ""} {	    return ""	}	return [paf_db_fil seq \	    -col {2 3 4 1 5 6 7} "${file}${sn_sep}"]    }    # Do the housekeeping so we can open a file, and call tkeEdit to actually    # do the editing    proc EditFile {symbol file {line ""} {search 1} {state ""}} {	global sn_options	global tkeWinNumber sn_debug	if {${file} == ""} {	    return ""	}	#convert first the file name to be edited to a	#project-related name	set file [sn_convert_FileName ${file}]	#make sure we stay in project directory (different interpeters).	catch {cd $sn_options(sys,project-dir)}	#verify if we have a read-only project	if {${state} == ""} {	    if {$sn_options(readonly)} {		set state disabled	    } else {		set state normal	    }	}	set external_editor [sn_external_editor ${file}]	#verify if the default external editor is not empty	if {${external_editor} == ""} {	    set external_editor $sn_options(def,edit-external-editor)	}	set external_editor [sn_filecmd format \	    -internal ${external_editor}]	#use external Editor !	if {${external_editor} != ""} {	    if {[regexp "(emacs|gnuclient)" ${external_editor}]} {		if {[string compare ${line} ""] == 0} {		    set line 1.0		}		sn_start_emacs ${file} ${line} ${state} ${external_editor}	    } else {		if {${line} == ""} {		    set line 1		    set col 0		} else {		    set line [trim_text_index ${line}]		    set pos [split ${line} {.}]		    set line [lindex ${pos} 0]		    set col [lindex ${pos} 1]		}		regsub \		    -all {%l} ${external_editor} ${line} external_editor		regsub \		    -all {%c} ${external_editor} ${col} external_editor		regsub \		    -all {%i} ${external_editor} [tk appname] external_editor		regsub \		    -all {%d} ${external_editor} $sn_options(sys,project-dir) \		  external_editor		if {![regsub \		    -all {%f} ${external_editor} ${file} external_editor]} {		    lappend external_editor ${file}		}		lappend external_editor "<" $sn_options(def,null_dev)		sn_log "Editor command: ${external_editor}"		#read the contents into editor in the background		set fd [open "| ${external_editor}"]		fconfigure ${fd} \		    -encoding $sn_options(def,system-encoding) \		    -blocking 0		#wait until the contents are readed,		#some times the executed program is so fast, that the		#following command failes.		catch {fileevent ${fd} readable "wait_editor_end ${fd}"}# FIXME : This will block the GUI for 0.5 sec, that is not acceptable		after 500	    }	    return ""	}	#verify of there is an existing window with the	#same file name	set name [find_window_with_file ${file} ${state}]	#if window is availiable, then raise it	if {[winfo exists ${name}]} {	    ${name} view edit	    set center 0	    if {${line} < 1.0} {		set line ""	    }	} else {	    # The file is not being edited, check whether is has been changed	    # outside of the project !	    # when the file is to update, the update window will be displayed	    if {${search} && [::info commands paf_db_f] != ""} {		#when auto-parsing is disabled, file has to be added, whe		#it's not in the project.		if {! $sn_options(def,auto-reparse)} {		    #set f [paf_db_f get -key $file]		    set f [paf_db_f seq \		        -col 0 ${file}]		}		#reparse file if it's modified outside or the file is new.		if {$sn_options(def,auto-reparse) || ${f} == ""} {		    if {![sn_parse_uptodate [list ${file}]]} {			return 0		    }		}	    }	    set center 1	    # Now, we check whether there is a reusable window.	    set win [MultiWindow&::find_Reusable]	    if {${win} != ""} {		#disable gotosymbol		global gotosymbol_active		set gotosymbol_active 0		#raise editor in the multi window		${win} view edit		#enable gotosymbol		set gotosymbol_active 1		#get editor class & widget		set ed [${win} editor]		set edw [${win} editw]		if {${ed} == ""} {		    return ""		    #Something wrong ??		}		#before edit the file, add the current position		#to the prev/next stack		${win} history_stack_add_point ${ed}		#edit file		${ed} editfile ${file} \		    -1 "" 0		#set edit position		if {${line} == ""} {		    ${edw} mark set insert 0.0		    ${edw} mark set anchor insert		}		${ed} SetFondPos ${line} ${center} 0		#return the edit widget		return ${edw}	    }	    #create a new multiple window	    incr tkeWinNumber	    set name .multiwindow-${tkeWinNumber}	    MultiWindow& ${name} \	        -symbolname ${file} \	        -raise edit	    incr tkeWinNumber	}	set editor [${name} component editor]	# FIXME: Should be using components.	set editw [$editor editor]	if {${line} != ""} {	    #before edit the file, add the current position	    #to the prev/next stack	    ${name} history_stack_add_point $editor	    if {[$editor cget -file_changed] && ${symbol} != "" && \	      [string last " " ${symbol}] != -1} {		set off [lindex ${symbol} 0]		if {${off} == "" || ${off} == "dummy"} {		    set off 0		}		set tg [join [lrange ${symbol} 1 end]]		set pos [${editw} tag ranges ${tg}]		set len [llength ${pos}]		set off [expr ${off} * 2]		if {${len} <= ${off}} {		    set off [expr ${len} - 2]		}		$editor SetFondPos [lindex ${pos} ${off}] ${center} 0	    } else {		$editor SetFondPos ${line} ${center} 0	    }	} else {	    $editor SetFondPos ${line} ${center} 0	}	#maybe readonly state	if {${state} != ""} {	    ${editw} config \	        -state ${state}	}	return ${editw}    }    method new_file {} {	global sn_options	global prj_lines_num	if {[Ask_For_Modified new] == 0} {	    return 0	}	editfile $sn_options(noname_file) \	    -1 revert    }    common last_accessed_dir ""    proc FileDialog {w args} {	global sn_options	global tk_strictMotif	global tcl_platform	global Avail_Parsers Parser_Info        # When called with ::.foo we need to just use .foo as the widget name        set w [namespace tail ${w}]	#default is project directory and not current directory, because	#of symbolic link problems!	if {${last_accessed_dir} == ""} {	    if {$sn_options(sys,project-dir) != ""} {		set last_accessed_dir $sn_options(sys,project-dir)	    } else {		set last_accessed_dir [pwd]	    }	}	#analyze the arguments	set cnt [llength ${args}]	set title ""	set script ""	set prefix "file_dialog"	set save_open "open"	set initialdir ""	set extensions ""	set initialfile ""	if {$tcl_platform(platform) == "windows"} {	    #set defaultextension ".cpp"	    set defaultextension ""	} else {	    #set defaultextension ".c"	    set defaultextension ""	}	for {set i 0} {${i} < ${cnt}} {incr i} {	    set arg [lindex ${args} ${i}]	    incr i	    set val [lindex ${args} ${i}]	    switch -- ${arg} {	    "-title" {		    set title ${val}		}	    "-script" {		    set script ${val}		}	    "-prefix" {		    set prefix ${val}		}	    "-save_open" {		    set save_open ${val}		}	    "-initialdir" -	    "-dir" {		    set initialdir ${val}		}	    "-extensions" {		    set extensions ${val}		}	    "-defaultextension" {		    set defaultextension ${val}		}	    "-initialfile" {		    set initialdir [file dirname ${val}]		    set initialfile [file tail ${val}]		}	    default {		    bell		    return		}	    }	}	if {${title} == ""} {	    if {${save_open} == "open"} {		set title [get_indep String Open]	    } else {		set title [get_indep String Save]	    }	}	if {${initialdir} == "" || ${initialdir} == "."} {	    set initialdir ${last_accessed_dir}	}	#don't call standard motif dialog box, alwayes Tk	#on windows, we call the default dialog box	if {$tcl_platform(platform) != "windows"} {	    set old_motif ${tk_strictMotif}	}	#constract file prefixes from user defined	if {${extensions} != ""} {	    set types ${extensions}	} else {	    #use default extensions	    lappend types [list [get_indep String AllFiles] "*"]	    foreach type ${Avail_Parsers} {		set newsuf ""		foreach s $Parser_Info(${type},SUF) {		    lappend newsuf ${s}		}		if {${newsuf} != ""} {		    lappend types [list $Parser_Info(${type},TYPE) ${newsuf}]		}	    }	}	if {${save_open} == "open"} {	    if {$tcl_platform(platform) == "unix"} {		#don't call motif dialog box		# FIXME: Hack to support both tk 8.1 and tk 8.3		if {! [catch {package require Tcl 8.3}]} {		    set tkFDialog tk::dialog::file::tkFDialog		} else {		    set tkFDialog tkFDialog		}		set f [$tkFDialog open \		    -parent ${w} \		    -title ${title} \		    -initialdir ${initialdir} \		    -defaultextension ${defaultextension} \		    -filetypes ${types} \		    -initialfile ${initialfile}]	    } else {		set f [tk_getOpenFile \		    -parent ${w} \		    -title ${title} \		    -initialdir ${initialdir} \		    -defaultextension ${defaultextension} \		    -filetypes ${types} \		    -initialfile ${initialfile}]	    }	} else {	    if {$tcl_platform(platform) == "unix"} {		#don't call motif dialog box		# FIXME: Hack to support both tk 8.1 and tk 8.3		if {! [catch {package require Tcl 8.3}]} {		    set tkFDialog tk::dialog::file::tkFDialog		} else {		    set tkFDialog tkFDialog		}		set f [$tkFDialog save \		    -parent ${w} \		    -title ${title} \		    -initialdir ${initialdir} \		    -defaultextension ${defaultextension} \		    -filetypes ${types} \		    -initialfile ${initialfile}]	    } else {		set f [tk_getSaveFile \		    -parent ${w} \		    -title ${title} \		    -initialdir ${initialdir} \		    -defaultextension ${defaultextension} \		    -filetypes ${types} \		    -initialfile ${initialfile}]	    }	}	#store last accessed directory	if {${f} != ""} {	    set ff ${f}	    catch {set last_accessed_dir [file dirn

⌨️ 快捷键说明

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