This chapter describes how to change the start-up and runtime behaviors of Source-Navigator. You can also customize menu items and keyboard shortcuts for the Editor; for more information see "Editor" in the Source-Navigator User's Reference Guide.
An example profile file for the German user interface is:
language:german sn_mailhost:mailhost
When a Symbol Browser window is created, a Tcl procedure called sn_rc_symbolbrowser (if it exists) is called with the following input parameters:
proc sn_rc_symbolbrowser {top menu} { set toolbar_frame $top.exp puts stdout [join [winfo children \ $toolbar_frame] "\n"] }
.multisymbr-1.exp.tree .multisymbr-1.exp.class .multisymbr-1.exp.xref .multisymbr-1.exp.inc .multisymbr-1.exp.space .multisymbr-1.exp.retrfr
proc sn_rc_symbolbrowser {top menu} { global tcl_platform set tool_frame $top.exp # Set a variable that identifies the text widget on # the status bar. set info $top.msg.msg # Create a new button on the toolbar. Note that the # button's command invokes the command line tool # in the background so that Source-Navigator is not # blocked while the tool is running. On Win32, we emulate # `xterm' with `cmd'. if {!$tcl_platform(platform) != "windows"} { set cmdline "exec xterm -T {Source-Navigator} &" set description xterm } else { set cmdline "exec cmd /c start cmd" set description shell } button $tool_frame.xterm -text $description \ -command $cmdline # Set the main window's status bar to read "xterm" # or "shell" when the mouse pointer is over the region # of the button. balloon_bind_info $tool_frame.xterm \ "Starts a new $description" bind $tool_frame.xterm <Leave> "set $top.msg {}" # Pack this button onto the toolbar. pack $tool_frame.xterm -side left }
proc sn_rc_symbolbrowser {win menu} { # Abbreviate the name of the menu to "extras". set extras $menu.extras # Create a new menu called "Extras". menu $extras -tearoff 0 # Add a menu item to the menu. The second character is # the designated hot key. Place this menu fourth in # the menu bar. $menu insert 3 cascade -label Extras -underline 1 \ -menu $extras # Add two items to the menu. $extras add command -label Functions -command \ "custom_show_symbols Functions" -underline 0 $extras add command -label Methods -command \ "custom_show_symbols Methods" -underline 0 } proc custom_show_symbols {symboltype} { # Set the scope appropriately. switch -- $symboltype { "Methods" { set scope "md" } default { set scope "fu" } } if {[info commands paf_db_$scope] == ""} { sn_error_dialog \ "No symbols of the type <$scope> are available in the project." return } # Generate a unique name for our new top-level window # widget. set w .custom_win_$scope # See if the window already exists. if {![info exists $w]} { # Create a new top-level window with a unique name. toplevel $w # Change its title. wm title $w "[sn_read_option project-name] ($symboltype)" # Put a frame around this window and add scrollbars # that scroll through a listbox. frame $w.frm scrollbar $w.frm.scrollx -orient horizontal \ -relief sunken -command "$w.frm.symlist xview" scrollbar $w.frm.scrolly -relief sunken \ -command "$w.frm.symlist yview" # Create a listbox to hold the symbol names. listbox $w.frm.symlist -height 20 -width 40 \ -xscrollcommand "$w.frm.scrollx set" \ -yscrollcommand "$w.frm.scrolly set" # If the user double-clicks in the list box, find # the nearest entry in the list and pass the name of # the symbol to custom_edit_file. This will launch # us into the source file where that symbol is # defined. bind $w.frm.symlist <Double-1> { custom_edit_file [%W get [%W nearest %y]] } # Pack the widgets onto our new window. pack $w.frm.scrolly -side right -fill y pack $w.frm.scrollx -side bottom -fill x pack $w.frm.symlist -expand y -fill both pack $w.frm -fill both -expand y } else { # The window already exists, so just delete # everything from the listbox and we'll re-insert # the current items in the next step. $w.frm.symlist delete 0 end } # Put all of the database keys into the list. eval $w.frm.symlist insert end \ [paf_db_$scope seq -data] } proc custom_edit_file {key} { # We have been passed the key of a record from either # the function or method database tables. We need to # determine the filename and line number for the # editor to jump into the source code. # The key of a record takes the form: # { name, start_position, filename } if {[llength $key] == 3} { set pos [lindex $key 1] set filename [lindex $key 2] } else { set pos [lindex $key 2] set filename [lindex $key 3] } sn_edit_file {} $filename $pos }
set top [winfo toplevel $view]
set menu_frame $top.menu
set tool_frame $top.exp
# Bind Control-a to jump to the start of the line
# (like emacs).
bind $text <Control-a> {
%W mark set insert "insert linestart"
%W yview -pickplace insert
break
}
# Bind Control-e to jump to the end of the line
# (like emacs).
bind $text <Control-e> {
%W mark set insert "insert lineend"
%W yview -pickplace insert
break
}
}
proc sn_rc_editor {view text} { set top [winfo toplevel $view] set menu_frame $top.menu set tool_frame $top.exp.editfr # MAKE SURE THAT THE EXTENDED TOOLBAR BUTTONS ARE ENABLED. # Reassign the command associated with the "compile" button. if {[winfo exists $tool_frame.compile]} { $tool_frame.compile config \ -command "custom_compile $view" } } proc custom_compile {view} { # Save the preconfigured "make" command line; we need # to tamper with it in this procedure. set temp [sn_read_option make-command] # Extract the filename. set file [$view cget -filename] # Set the "make" command line appropriately. if {[string match {*.jav*} $file]} { sn_modify_option make-command "javac \"$file\"" } # Byte-compile the source file. sn_make # Restore the "make" command line. sn_modify_option make-command $temp }
proc sn_rc_editor {view text} { global tcl_platform set topw [winfo toplevel $view] set tool_frame $topw.exp # On Windows call Notepad to edit a file. if {$tcl_platform(platform) == "windows"} { # Create a new button to edit the file using Notepad. button $tool_frame.vi -text Notepad \ -command "exec notepad \[$view getfilename\]" balloon_bind_info $tool_frame.vi \ "Edit current file using the Notepad editor." } else { # Create a new button to edit the file using vi button $tool_frame.vi -text vi \ -command "exec xterm -T vi -e vi \[$view getfilename\]" balloon_bind_info $tool_frame.vi \ "Edit current file using vi" } # Pack this button onto the toolbar. pack $tool_frame.vi -side left }
proc html_doc {topw} { set actview [$topw ActiveWidget] set ed [MultiWindow& @@ list_find_editor $actview] if {$ed == ""} { bell; return } doc_start [list [$ed getfilename]] } proc sn_rc_editor {view editor} { # main window set topw [winfo toplevel $view] # add a menu entry for the html documentation set mn $topw.menu $mn.tools add command \ -label "HTML Documentation" \ -command "html_doc $topw" }
# Source-Navigator regular expressions for compiler, # debugger and grep patterns. # Source-Navigator supports also blanks, so the patterns # must be so defined that blanks could be a part of the filename # "filename.c", line 789 "([^" ]+)",[ ]+line[ ]+([0-9]+) # filename.c, line 789 ([^ ]+),[ ]+line[ ]+([0-9]+) # line 789, filename.c, line[ ]+([0-9]+),[ ]+([^, ]+) # [filename.c:789] \[([^\[: ]+):([0-9]+)\] # filename.c:789 ([^: ]+):[ ]*([0-9]+) # filename.c(789) ([^ ]+\.[^ ]+)\(([0-9]+)\) # filename.c(789,11) or filename.c(789.11) ([^ ]+\.[^ ]+)\(([0-9]+[,.][ ]*[0-9]+)\) # /dir/filename.c, 789 ([^/ ]+),[ ]+([0-9]+)