📄 editorpane.tcl
字号:
# Copyright (c) 2000, 2001, Red Hat, Inc.# # This file is part of Source-Navigator.# # Source-Navigator is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License as published# by the Free Software Foundation; either version 2, or (at your option)# any later version.# # Source-Navigator is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# General Public License for more details.# # You should have received a copy of the GNU General Public License along# with Source-Navigator; see the file COPYING. If not, write to# the Free Software Foundation, 59 Temple Place - Suite 330, Boston,# MA 02111-1307, USA.# ######################################################### Editor that can be integrated in any subwindow.#######################################################option add *Editor&.width 80 widgetDefaultoption add *Editor&.height 25 widgetDefaultoption add *Editor&.wrap "none" widgetDefaultoption add *Editor&.editsate "normal" widgetDefaultitcl::class Editor& { global sn_options inherit sourcenav::MultiChild constructor {args} { global sn_options set class [${this} info class] # Create the text editor. itk_component add editor { text $itk_component(hull).editor \ -relief raised \ -bd 0 \ -yscrollcommand "$itk_component(hull).yview set" \ -xscrollcommand "$itk_component(hull).xview set" } { keep -width -height -wrap rename -state -editstate editState State } # Init some variables. set editor $itk_component(hull).editor set topw [winfo toplevel $itk_component(hull)] # Init some local/global variables. init_Editor # Init options after setting up class variables eval itk_initialize $args # Add menu entries, if availiable. if {$itk_option(-menu) != ""} { } # Add toolbar icons. if {$itk_option(-toolbar) != ""} { itk_component add toolbar { frame $itk_option(-toolbar).edfr } pack $itk_component(toolbar) -side left # Combobox for the find command # do not use filter. itk_component add find_history { Combo& $itk_component(toolbar).find_hist \ -width 20 \ -selectcommand "${this} toolbar_findtext $itk_component(toolbar).find_hist" \ -postcommand "${this} toolbar_findtext_postcommand \ $itk_component(toolbar).find_hist" } { } # FIXME: references to FindCombo should probably be # replaced with itk_component(find_history). set FindCombo $itk_component(find_history) bind $itk_component(find_history).entry <Control-f> \ [bind $itk_component(find_history).entry <Return>] balloon_bind_info $itk_component(find_history).entry [get_indep String \ EINFOEnterPattern] balloon_bind_info [$itk_component(find_history) component arrow] [get_indep String \ EINFOSearchHistory] pack $itk_component(find_history) \ -side left itk_component add find { button $itk_component(toolbar).find \ -takefocus 0 \ -image find_image \ -command "${this} toolbar_search_pattern" } balloon_bind_info $itk_component(find) [get_indep String \ SearchFindSelectionINFO] pack $itk_component(find) \ -side left # FIXME: This is a nasty hack to pat a gap in the toolbar. itk_component add gap { frame $itk_component(toolbar).gap -width 5 } pack $itk_component(gap) -side left # Retriever. itk_component add definition { button $itk_component(toolbar).definition \ -takefocus 0 \ -image search_image \ -command "${this} RetrieveObject" } bind_history $itk_component(definition) retrieve balloon_bind_info $itk_component(definition) [get_indep String \ RetrieverINFO] pack $itk_component(definition) \ -side left # Grep. itk_component add grep { button $itk_component(toolbar).grep \ -takefocus 0 \ -image grep_image \ -command "${this} toolbar_grep" } bind_history $itk_component(grep) grep balloon_bind_info $itk_component(grep) [get_indep String INFOGrep] pack $itk_component(grep) \ -side left } # Set project state to the editor. if {$sn_options(readonly)} { $this configure -editstate disabled } else { $this configure -editstate normal } # Make some initials for editor layout. Update_Layout # Make some bindings for the editor. make_editor_bindings $itk_component(editor) # Create scollbars. scrollbar $itk_component(hull).xview \ -command "$itk_component(editor) xview" \ -orient horizontal scrollbar $itk_component(hull).yview \ -command "$itk_component(editor) yview" grid $itk_component(editor) -row 0 -column 0 -sticky news grid $itk_component(hull).xview -row 1 -column 0 -sticky ew grid $itk_component(hull).yview -row 0 -column 1 -sticky ns grid rowconfigure $itk_component(hull) 0 -weight 1 grid columnconfigure $itk_component(hull) 0 -weight 1 # Call user defined procedure. if {[catch {sn_rc_editor $itk_component(hull) $itk_component(editor)} err]} { sn_log "error while exec sn_rc_editor: ${err}" } } destructor { foreach v [::info globals "${this}-*"] { catch {uplevel #0 unset ${v}} } } method __cget {item} { set item [string range ${item} 1 end] return [set ${item}] } method iset {item value} { return [set ${item} ${value}] } method init_Editor {} { global sn_options # Take last used string for search. set edit_StringSearch [lindex $sn_options(search) 0]#FIXME: This is a rather lame way to init the variables. catch { set edit_SearchNoCase $sn_options(search,nocase) set edit_SearchMethod $sn_options(search,method) set edit_SearchString $sn_options(search,str) } if {! [info exists edit_SearchNoCase]} { set edit_SearchNoCase "-nocase" } if {! [info exists edit_SearchMethod]} { set edit_SearchMethod "-exact" } if {! [info exists edit_SearchDirection]} { set edit_SearchDirection "-forwards" } } ############################################# # Toolbar button commands protected variable FindCombo "" method toolbar_findtext_postcommand {combo} { global sn_options $itk_component(find_history) configure -contents $sn_options(search) } method toolbar_findtext {combo txt} { FindNext \ -forwards ${txt} } method toolbar_search_pattern {} { if {![catch {set string [selection get]}]} { set off [string first "\n" ${string}] if {${off} != -1} { set string [string range ${string} 0 [expr ${off} - 1]] } FindNext \ -forwards ${string} } else { FindNext \ -forwards [$itk_component(find_history) cget -entrytext] } } #Execute grep with selection method toolbar_grep {} { $itk_option(-parent) search_grep } ############################################ ################################### #make some bindings for the editor ################################### method make_editor_bindings {t} { global sn_options global tcl_platform set trav $sn_options(sys,alt-traverse) bind ${t} <FocusIn> "${this} Focus_In" bind ${t} <FocusOut> "${this} Focus_Out" #Bingings for traversal into the editor foreach b [list <Left> <Right> <Up> <Down> <Shift-Left> <Shift-Right> \ <Shift-Up> <Shift-Down> <Control-Left> <Control-Right> <Control-Up> \ <Control-Down> <Shift-Control-Left> <Shift-Control-Right> \ <Shift-Control-Up> <Shift-Control-Down> <Prior> <Shift-Prior> \ <Next> <Shift-Next> <Home> \ <Shift-Home> <End> <Shift-End> <Control-Home> <Control-Shift-Home> \ <Control-End> <Control-Shift-End>] { bind ${t} ${b} "[bind Text ${b}]; ${this} find_and_mark_tag; break" } bind ${t} <ButtonRelease-1> "+ focus %W ${this} find_and_mark_tag " bind ${t} <Control-l> " %W see lastpos %W mark set insert lastpos ${this} find_and_mark_tag break" bind ${t} <Control-m> " tkTextExchangeMark %W ${this} find_and_mark_tag break " # Save File. bind ${t} <Control-s> "${this} save_file; break" # Quick save. bind ${t} <${trav}-s> "${this} fastsave_file; break" bind ${t} <${trav}-S> [bind ${t} <${trav}-s>] # Redo. bind ${t} <Control-Shift-z> "${this} Redo; break" bind ${t} <Control-Shift-Z> "${this} Redo; break" # Cut. bind ${t} <Shift-Delete> "${this} Cut; break" # Copy. bind ${t} <Control-Insert> "${this} Copy; break" # Paste. bind ${t} <Shift-Insert> "${this} Paste; break" # Insert tab/return. bind ${t} <Tab> {Editor&::InsertTab %W; break} bind ${t} <Return> {Editor&::Newline %W; break} # Pass Control-Tab and Shift-Control-Tab up to all bindtag bind ${t} <Control-Tab> continue bind ${t} <Shift-Control-Tab> continue # Pass Control-Prior (PgUp) and Control-Next (PgDn) up to all bindtag bind ${t} <Control-Prior> continue bind ${t} <Control-Next> continue # Grep accelerator. bind ${t} <Shift-Control-G> "${this} toolbar_grep; break" # Search bindings. # Find-dialog. bind ${t} <Control-f> "${this} FindText; break" # Search backward. # <Control-F>==<Control-Shift-f> bind ${t} <Control-F> "${this} FindNext -backwards; break" bind ${t} <Control-Shift-F> [bind ${t} <Control-F>] bind ${t} <Shift-F3> [bind ${t} <Control-F>] # Search forward. bind ${t} <F3> "${this} FindNext -forwards; break" # Sun Find. bind ${t} <F19> [bind ${t} <Control-f>] bind ${t} <Control-r> "${this} Replace; break" bind ${t} <Control-g> "${this} GotoLine; break" bind ${t} <Shift-Control-R> "${this} RetrieveObject; break" # Definition & implementation. bind ${t} <${trav}-d> "Editor&::search_definition ${this}; break" bind ${t} <${trav}-D> [bind ${t} <${trav}-d>] bind ${t} <${trav}-i> "Editor&::search_implementation ${this}; break" bind ${t} <${trav}-I> [bind ${t} <${trav}-i>] bind ${t} <${trav}-h> "sn_classtree \[Editor&::Get_XSelection \ ${this}\]; break" bind ${t} <${trav}-H> [bind ${t} <${trav}-h>] bind ${t} <${trav}-c> "sn_classbrowser \[Editor&::Get_XSelection \ ${this}\]; break" bind ${t} <${trav}-C> [bind ${t} <${trav}-c>] bind ${t} <${trav}-x> "sn_xref both \[Editor&::Get_XSelection \ ${this}\]; break" bind ${t} <${trav}-X> [bind ${t} <${trav}-x>] # New file. bind ${t} <Control-n> "${this} new_file; break" bind ${t} <Control-o> "${this} open_file; break" # Bindings for Indent/Outdent. bind ${t} <Control-greater> "Editor&::Indent ${this} indent; break" bind ${t} <Control-less> "Editor&::Indent ${this} outdent; break" # Define the queue, how the event are handled. sn_add_tags $itk_component(editor) Editor 2 } # Default bindings for the text editor. proc EditorBindings {} { global sn_options set trav $sn_options(sys,alt-traverse) set t Editor bind ${t} <Control-space> {tkTextSetMark %W insert; break} bind ${t} <greater> {+Editor&::Insert_Mark_Bracket %W %A} bind ${t} <quotedbl> {+Editor&::Insert_Mark_Bracket %W %A} bind ${t} <parenright> {+Editor&::Insert_Mark_Bracket %W %A} bind ${t} <bracketright> {+Editor&::Insert_Mark_Bracket %W %A} bind ${t} <braceright> {+Editor&::Insert_Mark_Bracket %W %A} # "{" "[" "]" "}" are bound on Alt-(7,8,9,0), so we need to bind the # numbers for windows nt/95, since bind <braceright> doesn't work. bind ${t} <KeyPress-9> {+Editor&::Insert_Mark_Bracket %W %A} bind ${t} <KeyPress-0> {+Editor&::Insert_Mark_Bracket %W %A} # Traversal on shift-tab. bind ${t} <Shift-Tab> {focus [tk_focusPrev %W]} # Sun UNDO. bind ${t} <F14> [bind Text <Control-z>] bind ${t} <Insert> "Editor&::set_overwrite %W \$tkText(%W,ovwrt);break" bind ${t} <Double-1><ButtonRelease-1> { switch -- [%W get {insert - 1 char}] { "\}" { Editor&::Insert_Mark_Bracket %W "\}" 0 } "\{" { Editor&::Insert_Mark_Bracket %W "\{" 0 } ")" { Editor&::Insert_Mark_Bracket %W ")" 0 } "(" { Editor&::Insert_Mark_Bracket %W "(" 0 } ">" { Editor&::Insert_Mark_Bracket %W ">" 0 } "<" { Editor&::Insert_Mark_Bracket %W "<" 0 } "\]" { Editor&::Insert_Mark_Bracket %W "\]" 0 } "\[" { Editor&::Insert_Mark_Bracket %W "\[" 0 } "\"" { Editor&::Insert_Mark_Bracket %W "\"" 0 } "\'" { Editor&::Insert_Mark_Bracket %W "\'" 0 } } break } } method m3_post_menu {w X Y x y} { set m .sn_pop_menu_listbox # It has to be destroyed because we might have problems with "tk_popup"! catch {destroy ${m}} menu ${m} \ -tearoff 0 \ -postcommand "${this} m3_post_menu_update ${m} ${x} ${y}" wm overrideredirect ${m} 1 tk_popup ${m} ${X} ${Y} } method m3_post_menu_update {m x y} { # Delete old entries. ${m} delete 0 end # Add edit commands (Undo,Copy,Cut,Delete,..). if {$itk_option(-file_changed)} { set state "normal" } else { set state "disabled" } set str [get_indep String EditUndo] ${m} add command \ -label [get_indep String EditUndo] \ -underline [get_indep Pos EditUndo] \ -accelerator "Ctrl+Z" \ -command "${this} Undo" \ -state ${state} if {[catch {$itk_component(editor) get sel.first}]} { set state "disabled" } else { set state "normal" } ${m} add command \ -label [get_indep String EditCut] \ -underline [get_indep Pos EditCut] \ -accelerator "Ctrl+X" \ -command "${this} Cut" \ -state ${state} ${m} add command \ -label [get_indep String EditCopy] \ -underline [get_indep Pos EditCopy] \ -accelerator "Ctrl+C" \ -command "${this} Copy" \ -state ${state} set str [get_indep String EditPaste] if {[catch {selection get \ -displayof $itk_component(editor) \ -selection CLIPBOARD}]} { set state "disabled" } else { set state "normal" }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -