📄 projedit.tcl
字号:
method control_buttons {} { #we can't apply the changes if we don't have files active, #at least one file must be availiable #if {$ProjectFiles == ""} { # set can_apply 0 #} if {${can_apply}} { set apply_state normal set undo_state normal } else { set apply_state disabled set undo_state disabled } if {$itk_option(-new_project)} { set ok_state normal } else { set ok_state ${apply_state} } if {$itk_option(-new_project)} { set apply_state disabled } #user can has have already closed the window if {[winfo exists ${btnsfr}]} { ${btnsfr}.ok configure -state ${ok_state} ${btnsfr}.apply configure -state ${apply_state} ${btnsfr}.undo configure -state ${undo_state} control_file_buttons } } #edit file method tree_edit_file {w} { #no edit, if something is changed, because a update #of the files occurs refreshing the project editor #and the changes will be lost. if {${can_apply}} { bell return } ${w} selection clear 0 end ${w} selection set active set idx [${w} curselection] if {[${w} children ${idx}] != "" || [${w} levels ${idx}] == 0} { bell return } set file [build_filepath ${treew} ${Tree_Mode} ${idx}] sn_edit_file dummy [sn_convert_FileName ${file}] } #post menu for tree method select_post_tree_menu {w X Y y} { set m .prj_post_tree_menu catch {destroy ${m}} menu ${m} -tearoff 0 wm overrideredirect ${m} 1 set y [${w} nearest ${y}] #we are on the base item if {${Tree_Mode} != "list" && [${w} itemcget ${y} -parent] == -1} { set rootitem 1 } else { set rootitem 0 } set sels [${w} curselection] #verify it the pointer points over a selected entry #if not, delete selection and select the current entry if {[lsearch -exact ${sels} ${y}] == -1} { ${w} selection clear 0 end ${w} selection set ${y} set sels ${y} } #for multi selection, only one categorie can be selected set rootname [${w} rootname [lindex ${sels} 0]] set rootname2 [${w} rootname [lindex ${sels} end]] if {${rootname} != ${rootname2}} { ${w} selection clear 0 end ${w} selection set ${y} set sels ${y} } set selcnt [llength ${sels}] if {${selcnt} == 1} { set file [${w} get ${y}] }\ elseif {${selcnt} > 1} { set file "${selcnt} Files" } else { set file "" } set view_state normal set unload_state normal set hide_state normal set rename_state normal #file is marked as hidden if {${rootname} == [get_indep String HiddenFiles]} { set hide_state disabled #file is marked as unloaded }\ elseif {${rootname} == [get_indep String UnloadedFiles]} { set unload_state disabled #file is viewed } else { set view_state disabled } if {${file} == ""} { set lbl "" set view_state disabled set unload_state disabled set hide_state disabled set rename_state disabled } else { set lbl " '${file}'" } #View ${m} add command -label "[get_indep String View]${lbl}"\ -underline [get_indep Pos View] -command "${this} hide_view_unload_files View [list ${sels}]" -state ${view_state} #Hide ${m} add command -label "[get_indep String Hide]${lbl}"\ -underline [get_indep Pos Hide] -command "${this} hide_view_unload_files Hide [list ${sels}]" -state ${hide_state} ${m} add separator #Unload ${m} add command -label "[get_indep String Unload]${lbl}"\ -underline [get_indep Pos Unload] -command "${this} hide_view_unload_files Unload [list ${sels}]" -state ${unload_state} control_file_buttons tk_popup ${m} ${X} ${Y} } method disp_file_statistic {sel} { #verify if the first item is selected (hole project) if {[lindex ${sel} 0] == "0"} { set sel "" } if {${sel} != ""} { sn_statistic [build_file_list ${treew} ${Tree_Mode} ${sel}] } else { #call it for all project sn_statistic } } method hide_view_unload_files {cmd sels} { set files [build_file_list ${treew} ${Tree_Mode} ${sels}] set y [lindex ${sels} 0] if {${files} == ""} { bell return } #store the current state in the undo-variables to be #able to undo the last action set Undo_ProjectFiles ${ProjectFiles} set Undo_HiddenFiles ${HiddenFiles} set Undo_files_to_unload ${files_to_unload} if {${cmd} == "Hide"} { eval lappend HiddenFiles ${files} #delete to hide files from availiable list foreach f ${files} { #verify where the files have to be removed from if {${view_state} == "disabled"} { #delete file from the project list set i [lsearch -exact ${ProjectFiles} ${f}] if {${i} >= 0} { set ProjectFiles [lreplace ${ProjectFiles} ${i} ${i}] } } else { #delete files from the unloaded list set i [lsearch -exact ${files_to_unload} ${f}] if {${i} >= 0} { set files_to_unload [lreplace ${files_to_unload} ${i}\ ${i}] } } } Display_ProjectFiles ${tree} see ${y} }\ elseif {${cmd} == "Unload"} { if {!$itk_option(-new_project)} { eval lappend files_to_unload ${files} } #delete to unload files from availiable list foreach f ${files} { #delete files from viewed list if {${view_state} == "disabled"} { set i [lsearch -exact ${ProjectFiles} ${f}] if {${i} >= 0} { set ProjectFiles [lreplace ${ProjectFiles} ${i} ${i}] } } else { #delete files from the hidden list set i [lsearch -exact ${HiddenFiles} ${f}] if {${i} >= 0} { set HiddenFiles [lreplace ${HiddenFiles} ${i} ${i}] } } } Display_ProjectFiles ${tree} see ${y} }\ elseif {${cmd} == "View"} { eval lappend ProjectFiles ${files} #view files foreach f ${files} { #delete files from hidden list if {${hide_state} == "disabled"} { set i [lsearch -exact ${HiddenFiles} ${f}] if {${i} >= 0} { set HiddenFiles [lreplace ${HiddenFiles} ${i} ${i}] } } else { #delete files from the unloaded list set i [lsearch -exact ${files_to_unload} ${f}] if {${i} >= 0} { set files_to_unload [lreplace ${files_to_unload} ${i}\ ${i}] } } } Display_ProjectFiles ${tree} see ${y} } else { bell return } set can_apply 1 control_buttons } method rename_file {file y} { global sn_root set children [${treew} children ${y}] if {${children} != ""} { set files [build_file_list ${treew} ${Tree_Mode} ${y}] } else { set files ${file} } set nname [sn_prompt_for_files [get_indep String Rename] [list\ [list ${file} ${file}]]] if {${nname} == ""} { return "" } set nname [lindex ${nname} 0] if {[string first ${sn_root} ${nname}] != -1} { bell return } } method tree_toggle {tr x y} { global projtree global ${this}.msg set ret [${tr} identify ${x} ${y}] set idx [${tr} nearest ${y}] set $itk_component(hull).msg [build_filepath ${treew} ${Tree_Mode} ${idx}] #no items or no tree mode if {[${tr} size] < 0} { return } #verify if the icon of a sub tree is clicked if {${ret} != "text"} { #save info that this sub directory is closed set path [build_filepath ${treew} ${Tree_Mode} ${idx} -1] if {${ret} == "view"} { set projtree(${Tree_Mode}/${path}) 1 } else { ::catch {unset projtree($Tree_Mode/$path)} } set img [${tr} itemcget ${idx} -image] #it's a directory if {[string first "dir" ${img}] == 0} { ${tr} toggle @${x},${y} return } #it's a file (view/hide) return } } method post_views {cmb} { } method change_view {cmb view} { upvar #0 ${this}-view vw if {${view} == ""} { set vw "default" set view ${vw} } if {${CurrentView} == ${view}} { return } #if the current view is changed, ask if the #user wants to apply the changes to the current view if {${can_apply}} { set answer [tk_dialog auto [get_indep String View]\ "${CurrentView}: [get_indep String HasBeenModified]"\ question_image 0 [get_indep String Apply] [get_indep String\ Cancel]] if {${answer} != 0} { set vw ${CurrentView} return } set cur_view ${view} set vw ${CurrentView} #apply changes apply set vw ${cur_view} } #verify if the view is already availiable set found 0 foreach v ${ProjectViews} { if {[lindex ${v} 0] == ${view}} { set found 1 break } } if {${found} == 0} { set answer [tk_dialog auto [get_indep String View] "${view}:\ [get_indep String AskForNewView]" question_image 0\ [get_indep String Yes] [get_indep String Cancel]] if {${answer} != 0} { set vw ${CurrentView} return } } #change to an existing view set CurrentView ${view} sn_change_view ${view} ReadProjectFiles } method ReadProjectFiles {{reset 1}} { if {${reset}} { catch {unset ProjectFiles} } if {$itk_option(-new_project)} { set ProjectFiles $itk_option(-new_ProjectFiles) set ProjectViews "default" set CurrentView "default" set HiddenFiles ${new_HiddenFiles} set files_to_unload "" }\ elseif {![info exists ProjectFiles]} { set ProjectFiles [sn_project_file_list 0] #save this sort of files to be ignored by applying the #changes to the project set orig_ProjectFiles ${ProjectFiles} if {[::info commands paf_db_proj] != ""} { set ProjectViews [paf_db_proj get -key views] set CurrentView [paf_db_proj get -key db_exclude] } else { set ProjectViews "" set CurrentView "" } if {${CurrentView} == ""} { set CurrentView "default" } set HiddenFiles [project_excluded_file_list] set files_to_unload "" } if {${reset}} { # Set last_dir to first directory on file list. set default [file dirname [lindex $ProjectFiles 0]] if {[file exists $default] == 1} { set last_dir $default } } #Project views if {${ProjectViews} == ""} { set ProjectViews [list default ""]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -