From mboxrd@z Thu Jan 1 00:00:00 1970 From: Syd Polk To: "Khamis Abuelkomboz (UUNET)" , sourcenav@sources.redhat.com Subject: Re: bug fix for the reuse-problem in 5.0 Date: Mon, 09 Apr 2001 11:01:00 -0000 Message-id: <4.2.0.58.20010409110035.01987f00@pop.cygnus.com> References: <3AD17D1D.2020606@knuut.de> X-SW-Source: 2001-q2/msg00069.html Khamis, could you please post things in diff format? Thanks! At 11:13 AM 4/9/01 +0200, Khamis Abuelkomboz (UUNET) wrote: >The attatched files fix the reuse problem with SN5.0. >You need to copy those into /share/sourcenav/gui > >However there are alot of smal problems still in this release! >I would name it as SN5.0Beta. > >khamis > > ># 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. ># >################################################ >## >## Window with all availiable tools by SN >## Copyright (c) 1999 Cygnus Solutions, Inc. >## >################################################ > >## Short cuts: >## edit == editor >## classbr == class browser >## ctree == Class Hierarchy >## xref == cross reference >## incbr == include browser >## dbg == Debug >## retr == Retriever >## grep == Grep >## make == Make >#global for the hole project > >itcl::class MultiWindow& { > global sn_options sn_elix > > inherit sourcenav::Window > > constructor {args} { > global sn_options > > # Setup some default behavior for the MultiWindow. > > ${this} withdraw > ${this} on_close "${this} windows_close dummy" > # Don't close window by hitting Escape. > ${this} bind_tk {;} > > # Init variables to nagivate between view points. > set view_positions(next) "" > set view_positions(prev) "" > > eval itk_initialize $args > > # Add menu. > AddMenu > > # Add the toolbar. > AddToolbar > > # Add statusbar. > AddStatusbar > > # Add the main notebook. > itk_component add notebook { > tixNoteBook $itk_component(hull).nbook -ipadx 0 -ipady 0 > } { } > > # Configure the big bad notebook widget. > set NotebookFrame [$itk_component(notebook) subwidget nbframe] > ${NotebookFrame} config -inactivebackground lightgray > > # Add the pages to the notebook widget. > $itk_component(notebook) add edit\ > -raisecmd [itcl::code ${this} RaiseEditor]\ > -label [get_indep String MultiEditor]\ > -under [get_indep Pos MultiEditor]\ > -state [tool_Exists edit] > > AddEditor $itk_component(notebook) edit > > $itk_component(notebook) add ctree\ > -raisecmd [itcl::code ${this} RaiseClassHierarchy]\ > -image tree_image\ > -label [get_indep String MultiClassHierarchy]\ > -under [get_indep Pos MultiClassHierarchy]\ > -state [tool_Exists ctree] > > AddClassHierarchy $itk_component(notebook) ctree > > $itk_component(notebook) add classbr\ > -raisecmd [itcl::code ${this} RaiseClassBrowser]\ > -label [get_indep String MultiClass]\ > -under [get_indep Pos MultiClass]\ > -state [tool_Exists classbr] > > AddClassBrowser $itk_component(notebook) classbr > > $itk_component(notebook) add xref \ > -raisecmd [itcl::code ${this} RaiseXReference]\ > -label [get_indep String MultiXRef]\ > -under [get_indep Pos MultiXRef]\ > -state [tool_Exists xref] > > AddXReference $itk_component(notebook) xref > > $itk_component(notebook) add incbr\ > -raisecmd [itcl::code ${this} RaiseInclude]\ > -label [get_indep String MultiInclude]\ > -under [get_indep Pos MultiInclude]\ > -state [tool_Exists incbr] > > AddInclude $itk_component(notebook) incbr > > $itk_component(notebook) add retr\ > -raisecmd [itcl::code ${this} RaiseRetriever]\ > -label [get_indep String MultiRetriever]\ > -under [get_indep Pos MultiRetriever]\ > -state [tool_Exists retr] > > AddRetriever $itk_component(notebook) retr > > $itk_component(notebook) add grep \ > -raisecmd [itcl::code ${this} RaiseGrep] \ > -label [get_indep String MultiGrep] \ > -under [get_indep Pos MultiGrep] \ > -state [tool_Exists grep] > > AddGrep $itk_component(notebook) grep > > pack $itk_component(notebook) -fill both -side left -expand y > -anchor nw > > $itk_component(notebook) raise $itk_option(-raise) > > #call user function > catch {sn_rc_mainwindow $itk_component(hull) $itk_component(menu)} > update idletasks > after idle "${this} deiconify" > } > > destructor { > foreach v [::info globals "${this}-*"] { > catch {uplevel #0 unset ${v}} > } > } > > protected variable Activate_executed 0 > > # Activate different notebook page: > # save filter options for the actual tool and > # restore those for the activated tool (notebook page) > > method Activate {page paned pane tool} { > # FIXME: Shouldn't this be in sn_options array? > global Switch_Is_Enabled > > upvar #0 ${SymbolsFilter}-related related > upvar #0 ${tool}-related toolrel > > incr Activate_executed > > set old_view ${ActiveWidget} > > #save related for now active tool > if {${ActiveWidget} != ""} { > upvar #0 ${ActiveWidget}-related rel > ::set rel ${related} > > #dump current position > history_stack_add_point ${ActiveWidget} > } > > #save filter flags for the active widget (radios and checkbuttons) > foreach btn [eval list $AllFilterOptions(radio)\ > $AllFilterOptions(checkbutton)] { > set variable [${btn} cget -variable] > upvar #0 ${variable} value > upvar #0 ${ActiveWidget}-Filter(${btn}) var > ::set var ${value} > } > > #get selection from current tool, only when keep > #is seted or the global variable to disable switching > #is on > if {${keep} && ${Switch_Is_Enabled} > 0 && ${ActiveWidget} != ""} { > set sel [${ActiveWidget} Selection] > } else { > set sel "" > } > > > #deactivate current notepad > if {$ActiveWidget != ""} { > $ActiveWidget deactivate > } > > #hide editor buttons, we must hide it first, > #to enable the icons of the next view as first > #and if an editor is availiable we put the toolbar > #buttons on the far right side of the toolbar > if {[${tool} whoami] != "edit"} { > pack forget ${FindEditFr} > } > > #restore the information about related > if {[catch {::set related ${toolrel}}]} { > if {[${tool} whoami] == "edit"} { > ::set related 1 > } else { > ::set related 0 > } > } > > set ActiveWidget ${tool} > set ActivePage ${page} > set ActivePaned ${paned} > set ActivePane ${pane} > > #restore the values of the filter checkbuttons and radios > foreach btn [eval list $AllFilterOptions(radio)\ > $AllFilterOptions(checkbutton)] { > catch { > set variable [${btn} cget -variable] > upvar #0 ${variable} var > upvar #0 ${ActiveWidget}-Filter(${btn}) value > ::set var ${value} > } > } > > # Delete contents of drop down list > $itk_component(symbolcombo) configure -contents "" > $itk_component(symbolcombo) selecttext "" > > ${ActiveWidget} activate > #if there is a selection, goto it > if {${sel} != ""} { > ::eval ${ActiveWidget} gotosymbol ${sel} 0 > } > ${ActiveWidget} SetTitle > ${ActiveWidget} Focus > > #verify if we have an editor to display the toolbar > #icons > DeActivate_Editor_buttons > > #call user function > catch {sn_rc_changeview ${this} ${ActiveWidget} ${old_view}} > } > > #View toolbar buttons for the editor, if an editor is > #availiable > method DeActivate_Editor_buttons {} { > if {[list_find_editor ${ActiveWidget}] != ""} { > pack ${FindEditFr} -side left > } else { > pack forget ${FindEditFr} > } > } > > ##################################################### > # create editor > ##################################################### > method AddEditor {nb page} { > global sn_options > > itk_component add editor_page { > ${nb} subwidget ${page} > } { } > > $itk_component(editor_page) configure -bg white > > itk_component add editorpaned { > tixPanedWindow $itk_component(editor_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add editorpane { > $itk_component(editorpaned) add edit -size 500 > } { } > > itk_component add editor { > Editor& $itk_component(editorpane).editor\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu $itk_component(menu)\ > -toolbar ""\ > -mesg_area $itk_component(statusbar)\ > -message_var [itcl::scope message]\ > -linenumber_var [itcl::scope linenum] \ > -filename ${symbolname}\ > -findcombo ${FindCombo} \ > -parent $this > } { } > > pack $itk_component(editor) -fill both -expand y > pack $itk_component(editorpaned) -fill both -expand y > > lappend AvailTools $itk_component(editor) > > # Just creating it, might not want to use it just yet. > $itk_component(editor) deactivate > } > > method RaiseEditor {} { > Activate $itk_component(editor_page) $itk_component(editorpaned)\ > $itk_component(editorpane) $itk_component(editor) > } > > ##################################################### > # Class hierarchy > ##################################################### > method AddClassHierarchy {nb page} { > global sn_options > > itk_component add classtree_page { > ${nb} subwidget ${page} > } { } > > itk_component add classtreepaned { > tixPanedWindow $itk_component(classtree_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add classtreepane { > $itk_component(classtreepaned) add ctree > } { } > > itk_component add classtree { > ClassTree& $itk_component(classtreepane).classtree\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter $SymbolsFilter\ > -menu $itk_component(classtree_menu)\ > -toolbar $itk_component(toolbar)\ > -message_var [itcl::scope message]\ > -doubleclickcommand "${this} ClassHierarchyEdit" \ > -parent $this > } { } > > pack $itk_component(classtree) -fill both -expand y > pack $itk_component(classtreepaned) -fill both -expand y > > lappend AvailTools $itk_component(classtree) > > # Just creating it, might not want to use it just yet. > $itk_component(classtree) deactivate > } > > method RaiseClassHierarchy {} { > Activate $itk_component(classtree_page) > $itk_component(classtreepaned)\ > $itk_component(classtreepane) $itk_component(classtree) > } > > method ClassHierarchyEdit {{scope ""} {sym ""} {cls ""} {file ""} {from\ > ""} {type ""} {prm ""} {to ""} {always 1}} { > sn_retrieve_symbol ${sym} ${scope} > } > > ##################################################### > # Class Browser > ##################################################### > method AddClassBrowser {nb page} { > global sn_options > > itk_component add class_page { > ${nb} subwidget ${page} > } { } > > itk_component add classpaned { > tixPanedWindow $itk_component(class_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add classpane { > $itk_component(classpaned) add classbr > } { } > > itk_component add classbrowser { > Class& $itk_component(classpane).classbrowser\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu $itk_component(classbrowser_menu)\ > -toolbar $itk_component(toolbar)\ > -mesg_area $itk_component(statusbar)\ > -class_doubleclickcommand\ > [itcl::code ${this} ClassBrowserEditClass]\ > -doubleclickcommand [itcl::code ${this} EditObject] \ > -parent $this > } { } > > pack $itk_component(classbrowser) -fill both -expand y > pack $itk_component(classpaned) -fill both -expand y > > lappend AvailTools $itk_component(classbrowser) > > # Just creating it, might not want to use it just yet. > $itk_component(classbrowser) deactivate > } > > method RaiseClassBrowser {} { > Activate $itk_component(class_page) $itk_component(classpaned)\ > $itk_component(classpane) $itk_component(classbrowser) > } > > method ClassBrowserEditClass {class} { > sn_retrieve_symbol ${class} "cl" "" -beg 1 1 > } > > method EditObject {{scope ""} {sym ""} {cls ""} {file ""} {from ""} > {type\ > ""} {prm ""} {to ""} {always 1}} { > global sn_sep > > #to look in the database, use sn_sep > set lbl [string trim "${cls}${sn_sep}${sym}" " \t${sn_sep}"] > > if {${lbl} == "" && ${file} == ""} { > bell > return > } > > #we must try to find the correct symbol, so we have to > #accept the parameter list also. > set cnt [read_matched_from_db "" ${scope} -exact ${lbl} ${type} > ${prm}\ > ${file} ${from} ${to} 0] > if {${cnt} == "" && ${file} == ""} { > set cnt [read_matched_from_db "" ${scope} -exact ${lbl}] > } > if {${cnt} != ""} { > set file [lindex [split [lindex ${cnt} 0] \t] 4] > set from [lindex [split [lindex ${cnt} 0] \t] 5] > } > if {${file} != ""} { > #use blank as separator > set lbl [string trim "${cls} ${sym}"] > sn_edit_file [list 0 ${lbl} ${scope}] ${file} ${from} 1 > } else { > bell > return > } > } > > ##################################################### > # X reference > ##################################################### > method AddXReference {nb page} { > global sn_options > > itk_component add xref_page { > ${nb} subwidget ${page} > } { } > > itk_component add xrefpaned { > tixPanedWindow $itk_component(xref_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add xrefpane { > $itk_component(xrefpaned) add xref > } { } > > itk_component add xref { > XRef& $itk_component(xrefpane).xref\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu $itk_component(xref_menu)\ > -toolbar $itk_component(toolbar)\ > -message_var [itcl::scope message]\ > -doubleclickcommand [itcl::code ${this} EditObject] \ > -parent ${this} > } { } > > pack $itk_component(xref) -fill both -expand y > pack $itk_component(xrefpaned) -fill both -expand y > > lappend AvailTools $itk_component(xref) > > # Just creating it, might not want to use it just yet. > $itk_component(xref) deactivate > } > > method RaiseXReference {} { > Activate $itk_component(xref_page) $itk_component(xrefpaned)\ > $itk_component(xrefpane) $itk_component(xref) > } > > ##################################################### > # Include > ##################################################### > method AddInclude {nb page} { > global sn_options > > itk_component add include_page { > ${nb} subwidget ${page} > } { } > > itk_component add includepaned { > tixPanedWindow $itk_component(include_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add includepane { > $itk_component(includepaned) add inc > } { } > > itk_component add include { > Include& $itk_component(includepane).incbr\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu $itk_component(include_menu)\ > -toolbar $itk_component(toolbar)\ > -mesg_area $itk_component(statusbar) \ > -parent $this > } { } > > pack $itk_component(include) -fill both -expand y > pack $itk_component(includepaned) -fill both -expand y > > lappend AvailTools $itk_component(include) > > # Just creating it, might not want to use it just yet. > $itk_component(include) deactivate > } > > method RaiseInclude {} { > Activate $itk_component(include_page) $itk_component(includepaned)\ > $itk_component(includepane) $itk_component(include) > } > > ##################################################### > # Retriever > ##################################################### > method AddRetriever {nb page} { > global sn_options > > itk_component add retriever_page { > ${nb} subwidget ${page} > } { } > > itk_component add retrieverpaned { > tixPanedWindow $itk_component(retriever_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add retrieverpane { > $itk_component(retrieverpaned) add retr > } { } > > itk_component add retriever { > Retr& $itk_component(retrieverpane).retr\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu RetrieverMenu\ > -toolbar $itk_component(toolbar)\ > -mesg_area $itk_component(statusbar) \ > -parent $this > } { } > > pack $itk_component(retriever) -fill both -expand y > pack $itk_component(retrieverpaned) -fill both -expand y > > lappend AvailTools $itk_component(retriever) > > # Just creating it, might not want to use it just yet. > $itk_component(retriever) deactivate > } > > method RaiseRetriever {} { > Activate $itk_component(retriever_page) > $itk_component(retrieverpaned)\ > $itk_component(retrieverpane) $itk_component(retriever) > } > > method retr {} { > return $itk_component(retriever) > } > > ##################################################### > # Grep > ##################################################### > method AddGrep {nb page} { > global sn_options > > itk_component add grep_page { > ${nb} subwidget ${page} > } {} > > itk_component add greppaned { > tixPanedWindow $itk_component(grep_page).paned \ > -paneborderwidth 0 \ > -orientation $sn_options(def,window-alighment) > } {} > > itk_component add greppane { > $itk_component(greppaned) add grep > } > > itk_component add grep { > Grep $itk_component(greppane).grep \ > -symbols $itk_component(symbolcombo) \ > -symbols_filter ${SymbolsFilter} \ > -menu GrepMenu \ > -toolbar $itk_component(toolbar) \ > -mesg_area $itk_component(statusbar) \ > -parent $this > } {} > > pack $itk_component(grep) -fill both -expand y > pack $itk_component(greppaned) -fill both -expand y > > lappend AvailTools $itk_component(grep) > > # Just creating it, might not want to use it just yet. > $itk_component(grep) deactivate > } > > method RaiseGrep {} { > Activate $itk_component(grep_page) $itk_component(greppaned)\ > $itk_component(greppane) $itk_component(grep) > } > > ##################################################### > # Make > ##################################################### > # FIXME: This currently isn't used, but it should probably > # be used (at some point). > > method AddMake {nb page} { > global sn_options > > itk_component add make_page { > ${nb} subwidget ${page} > } { } > > itk_component add makepaned { > tixPanedWindow $itk_component(make_page).paned\ > -paneborderwidth 0\ > -orientation $sn_options(def,window-alighment) > } { } > > itk_component add makepane { > $itk_component(makepaned) add make > } { } > > itk_component add make { > Make $itk_component(makepane).make\ > -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu MakeMenu\ > -toolbar $itk_component(toolbar)\ > -mesg_area $itk_component(statusbar) > } { } > pack $itk_component(make) -fill both -expand y > pack $itk_component(makepaned) -fill both -expand y > > lappend AvailTools $itk_component(make) > } > > method RaiseMake {} { > Activate $itk_component(make_page) $itk_component(makepaned)\ > $itk_component(makepane) $itk_component(make) > } > > method AddMenu {} { > global sn_options > > set state normal > > itk_component add menu { > menu $itk_component(hull).menu -tearoff 0 > } > > ## File menu > #################### > > itk_component add file_menu { > menu $itk_component(menu).file -tearoff 0 -postcommand\ > [itcl::code ${this} file_post $itk_component(menu).file] > } > > $itk_component(file_menu) configure -font > $sn_options(def,layout-font) > > $itk_component(menu) add cascade -label [get_indep String EditFile]\ > -menu $itk_component(file_menu) -underline [get_indep Pos > EditFile] > > $itk_component(file_menu) add command\ > -label [get_indep String EditNewFile]\ > -underline [get_indep Pos EditNewFile] -accelerator "Ctrl+N"\ > -command [itcl::code ${this} file_new] > > $itk_component(file_menu) add command\ > -label [get_indep String Open]\ > -underline [get_indep Pos Open] -accelerator "Ctrl+O"\ > -command [itcl::code ${this} file_open] > > $itk_component(file_menu) add separator > > #Add project menu > AddProjectMenuEntries $itk_component(file_menu) ${this} 1 > > $itk_component(file_menu) add separator > > #File commands > $itk_component(file_menu) add command\ > -accelerator "Ctrl+S"\ > -label [get_indep String EditSave]\ > -underline [get_indep Pos EditSave]\ > -command "[itcl::code ${this} file_save]" > > $itk_component(file_menu) add command\ > -label [get_indep String EditSaveFileAs]\ > -underline [get_indep Pos EditSaveFileAs]\ > -command [itcl::code ${this} file_saveas] > > $itk_component(file_menu) add command\ > -accelerator "$sn_options(sys,alt-accelpref)+S"\ > -label [get_indep String EditFastSave]\ > -underline [get_indep Pos EditFastSave]\ > -command "[itcl::code ${this} file_fastsave]" > > $itk_component(file_menu) add command\ > -accelerator "$sn_options(sys,alt-accelpref)+A"\ > -label [get_indep String EditSaveAll]\ > -underline [get_indep Pos EditSaveAll]\ > -command "[itcl::code ${this} file_saveall]" > > $itk_component(file_menu) add command\ > -label [get_indep String Revert]\ > -underline [get_indep Pos Revert]\ > -command [itcl::code ${this} file_revert] > > $itk_component(file_menu) add separator > > $itk_component(file_menu) add command\ > -label [get_indep String Print]\ > -accelerator "Ctrl+P" -underline [get_indep Pos Print]\ > -command [itcl::code ${this} file_print] > > $itk_component(file_menu) add separator > > #close window > $itk_component(file_menu) add command\ > -command [itcl::code ${this} windows_close > $itk_component(file_menu)]\ > -label [get_indep String WindowsClose] -accelerator "Ctrl+W"\ > -underline [get_indep Pos WindowsClose] > > $itk_component(file_menu) add command -label [get_indep String Exit]\ > -underline [get_indep Pos Exit] -accelerator "Ctrl+Q"\ > -command " sn_exit " > > ## Edit menu > ############# > > itk_component add edit_menu { > menu $itk_component(menu).edit -tearoff 0\ > -postcommand [itcl::code ${this} edit_post > $itk_component(menu).edit] > } > > $itk_component(edit_menu) configure -font > $sn_options(def,layout-font) > > $itk_component(menu) add cascade -label [get_indep String EditEdit]\ > -menu $itk_component(edit_menu) -underline [get_indep Pos > EditEdit] > > $itk_component(edit_menu) add command\ > -label [get_indep String EditUndo]\ > -underline [get_indep Pos EditUndo] -accelerator "Ctrl+Z"\ > -command [itcl::code ${this} edit_undo] -state ${state} > > $itk_component(edit_menu) add command\ > -label [get_indep String EditRedo]\ > -underline [get_indep Pos EditRedo] -accelerator "Ctrl+Y"\ > -command [itcl::code ${this} edit_redo] -state ${state} > > $itk_component(edit_menu) add separator > > $itk_component(edit_menu) add command\ > -label [get_indep String EditCut]\ > -underline [get_indep Pos EditCut] -accelerator "Ctrl+X"\ > -command [itcl::code ${this} edit_cut] -state ${state} > > $itk_component(edit_menu) add command\ > -label [get_indep String EditCopy]\ > -underline [get_indep Pos EditCopy] -accelerator "Ctrl+C"\ > -command [itcl::code ${this} edit_copy] > > $itk_component(edit_menu) add command\ > -label [get_indep String EditPaste]\ > -underline [get_indep Pos EditPaste] -accelerator "Ctrl+V"\ > -state ${state}\ > -command [itcl::code ${this} edit_paste] > > $itk_component(edit_menu) add command\ > -label [get_indep String EditDelete]\ > -underline [get_indep Pos EditDelete] -accelerator "Ctrl+D"\ > -command [itcl::code ${this} edit_delete] -state ${state} > > $itk_component(edit_menu) add command\ > -label [get_indep String SelectAll]\ > -underline [get_indep Pos SelectAll]\ > -command [itcl::code ${this} edit_selectall] > > $itk_component(edit_menu) add command\ > -label [get_indep String EditClear]\ > -underline [get_indep Pos EditClear]\ > -command [itcl::code ${this} edit_clear]\ > -state ${state} > > $itk_component(edit_menu) add separator > > $itk_component(edit_menu) add command\ > -label [get_indep String EditInsertFile]\ > -underline [get_indep Pos EditInsertFile]\ > -command [itcl::code ${this} edit_insert] > > $itk_component(edit_menu) add separator > > $itk_component(edit_menu) add command\ > -label [get_indep String EditIdent]\ > -underline [get_indep Pos EditIdent] -accelerator "Ctrl+>"\ > -command "[itcl::code ${this} edit_indent indent]" > > $itk_component(edit_menu) add command\ > -label [get_indep String EditOutdent]\ > -underline [get_indep Pos EditOutdent] -accelerator "Ctrl+<"\ > -command "[itcl::code ${this} edit_indent outdent]" > > $itk_component(edit_menu) add separator > > $itk_component(edit_menu) add command\ > -label [get_indep String EditPreferences]\ > -underline [get_indep Pos EditPreferences]\ > -command [itcl::code ${this} edit_preferences 0] > > #Search menu > itk_component add search_menu { > menu $itk_component(menu).search -tearoff 0\ > -postcommand [itcl::code ${this} search_post\ > $itk_component(menu).search] > } > > $itk_component(search_menu) configure -font > $sn_options(def,layout-font) > > $itk_component(menu) add cascade -label [get_indep String Search]\ > -underline [get_indep Pos Search]\ > -menu $itk_component(search_menu) > > $itk_component(search_menu) add command\ > -label [get_indep String SearchFind]\ > -underline [get_indep Pos SearchFind] -accelerator "Ctrl+F"\ > -command [itcl::code ${this} search_findtext] > > $itk_component(search_menu) add command\ > -label [get_indep String SearchNext]\ > -underline [get_indep Pos SearchNext] -accelerator "F3"\ > -command [itcl::code ${this} search_next] > > $itk_component(search_menu) add command\ > -label [get_indep String SearchPrev]\ > -underline [get_indep Pos SearchPrev] -accelerator > "Shift+F3"\ > -command [itcl::code ${this} search_prev] > > $itk_component(search_menu) add command\ > -label [get_indep String SearchReplace]\ > -underline [get_indep Pos SearchReplace]\ > -command [itcl::code ${this} search_replace] -state ${state} > > $itk_component(search_menu) add separator > > $itk_component(search_menu) add command\ > -accelerator "$sn_options(sys,alt-accelpref)+D" -label\ > [get_indep String SearchDefinition]\ > -underline [get_indep Pos SearchDefinition]\ > -command [itcl::code ${this} search_definition]\ > -state ${state} > > $itk_component(search_menu) add command\ > -accelerator "$sn_options(sys,alt-accelpref)+I"\ > -label [get_indep String SearchImplementation]\ > -underline [get_indep Pos SearchImplementation]\ > -command [itcl::code ${this} search_implementation]\ > -state ${state} > > $itk_component(search_menu) add separator > > $itk_component(search_menu) add command\ > -accelerator "Ctrl+Shift+G"\ > -label [get_indep String SearchGrep]\ > -underline [get_indep Pos SearchGrep]\ > -command "${this} search_grep" > > $itk_component(search_menu) add separator > > #Add a separate Goto sub menu > itk_component add goto_menu { > menu $itk_component(search_menu).goto -tearoff 0\ > -postcommand [itcl::code ${this} search_goto_post\ > $itk_component(search_menu).goto] > } > > $itk_component(search_menu) add cascade\ > -label [get_indep String Goto]\ > -underline [get_indep Pos Goto]\ > -menu $itk_component(goto_menu) > > $itk_component(goto_menu) add command\ > -label [get_indep String SearchGotoLine]\ > -underline [get_indep Pos SearchGotoLine]\ > -accelerator "Ctrl+G"\ > -command [itcl::code ${this} search_gotoline] > > $itk_component(goto_menu) add separator > > $itk_component(goto_menu) add command\ > -label [get_indep String SearchSetMark]\ > -underline [get_indep Pos SearchSetMark]\ > -accelerator "Ctrl+Space"\ > -command [itcl::code ${this} search_setmark] > > $itk_component(goto_menu) add command\ > -label [get_indep String SearchGotoMark]\ > -underline [get_indep Pos SearchGotoMark]\ > -accelerator "Ctrl+M"\ > -command [itcl::code ${this} search_gotomark] > ># FIXME: targeted for removal > > $itk_component(goto_menu) add command\ > -label [get_indep String SearchGotoError]\ > -underline [get_indep Pos SearchGotoError]\ > -accelerator "Shift+Ctrl+E"\ > -command "MultiWindow&::search_gotoerror" > > > ## Tools menu column > itk_component add tools_menu { > menu $itk_component(menu).tools -tearoff 0\ > -postcommand [itcl::code ${this} tools_post\ > $itk_component(menu).tools] > } > > $itk_component(tools_menu) configure -font > $sn_options(def,layout-font) > > $itk_component(menu) add cascade\ > -label [get_indep String Tools]\ > -menu $itk_component(tools_menu)\ > -underline [get_indep Pos Tools] > > ############################################################ > ## Editor > ############################################################ > > ############################################################ > ## Class Hierarchy > ############################################################ > > itk_component add classtree_menu { > menu $itk_component(tools_menu).ctree -tearoff 0\ > -postcommand [itcl::code ${this} tools_ctree_post\ > $itk_component(tools_menu).ctree] > } > > $itk_component(tools_menu) add cascade\ > -label [get_indep String MultiClassHierarchy]\ > -menu $itk_component(classtree_menu)\ > -underline [get_indep Pos MultiClassHierarchy]\ > -state disabled > > ############################################################ > ## Class Browser > ############################################################ > > itk_component add classbrowser_menu { > menu $itk_component(tools_menu).class -tearoff 0\ > -postcommand [itcl::code ${this} tools_classbr_post\ > $itk_component(tools_menu).class] > } > > $itk_component(tools_menu) add cascade\ > -label [get_indep String MultiClass]\ > -menu $itk_component(classtree_menu)\ > -underline [get_indep Pos MultiClass] -state disabled > > ############################################################ > ## Cross reference > ############################################################ > > itk_component add xref_menu { > menu $itk_component(tools_menu).xref -tearoff 0\ > -postcommand [itcl::code ${this} tools_xref_post\ > $itk_component(tools_menu).xref] > } > > $itk_component(tools_menu) add cascade\ > -label [get_indep String MultiXRef]\ > -menu $itk_component(xref_menu)\ > -underline [get_indep Pos MultiXRef] -state disabled > > ############################################################ > ## Include > ############################################################ > > itk_component add include_menu { > menu $itk_component(tools_menu).incbr -tearoff 0\ > -postcommand [itcl::code ${this} tools_incbr_post\ > $itk_component(tools_menu).incbr] > } > $itk_component(tools_menu) add cascade\ > -label [get_indep String MultiInclude]\ > -menu $itk_component(include_menu)\ > -underline [get_indep Pos MultiInclude]\ > -state disabled > > $itk_component(tools_menu) add separator > > ## Miscellaneous Tools and IDE features > AddMiscSubMenu $itk_component(tools_menu) > > ## Revision control > $itk_component(tools_menu) add separator > > itk_component add rc_menu { > menu $itk_component(tools_menu).rc -tearoff 0 > } > > $itk_component(tools_menu) add cascade\ > -label [get_indep String RCS]\ > -underline [get_indep Pos RCS]\ > -state ${state} -menu $itk_component(rc_menu) > > $itk_component(rc_menu) configure -font $sn_options(def,layout-font) > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseCheckOut]\ > -underline [get_indep Pos ChooseCheckOut]\ > -command [itcl::code ${this} Handle_Rcs sn_rcs_checkout] > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseCheckIn]\ > -underline [get_indep Pos ChooseCheckIn]\ > -command [itcl::code ${this} Handle_Rcs sn_rcs_checkin] > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseDiscard]\ > -underline [get_indep Pos ChooseDiscard]\ > -command [itcl::code ${this} Handle_Rcs sn_rcs_discard] > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseLock]\ > -underline [get_indep Pos ChooseLock]\ > -command [itcl::code ${this} Handle_Rcs\ > "sn_rcs_lockunlockdel lock"] > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseUnlock]\ > -underline [get_indep Pos ChooseUnlock]\ > -command [itcl::code ${this} Handle_Rcs\ > "sn_rcs_lockunlockdel unlock"] > > $itk_component(rc_menu) add separator > > $itk_component(rc_menu) add command\ > -label [get_indep String ChooseDiff]\ > -underline [get_indep Pos ChooseDiff]\ > -command [itcl::code ${this} Handle_Rcs "sn_rcs_diff > ${this}"] > > #revision control editor > $itk_component(rc_menu) add separator > > $itk_component(rc_menu) add command\ > -label [get_indep String RevisionControlEditor]\ > -underline [get_indep Pos RevisionControlEditor]\ > -command " sn_revision_ctrl " > > ## History > AddHistMenu $itk_component(menu) > > ##Windows > AddWindowsMenu $itk_component(menu) ${this} 1 1 > > ##Help menu > AddHelpMenu $itk_component(menu) $itk_component(hull) > > ${this} configure -menu $itk_component(menu) > } > > method AddToolbar {} { > > itk_component add toolbar { > frame $itk_component(hull).toolbar -takefocus 0\ > -relief groove -border 2 > } > > #prev/next buttons > itk_component add hist_prev { > button $itk_component(toolbar).prev\ > -image prev_image\ > -takefocus 0\ > -command [itcl::code ${this} history_stack_goto_point > prev] > } > > bind $itk_component(hist_prev) <3>\ > [itcl::code ${this} toolbar_post_history_stack prev\ > $itk_component(hist_prev)] > > balloon_bind_info $itk_component(hist_prev)\ > [get_indep String GotoPrevPosition] > > pack $itk_component(hist_prev) -side left > > itk_component add hist_next { > button $itk_component(toolbar).next\ > -image next2_image\ > -takefocus 0\ > -command [itcl::code ${this} history_stack_goto_point > next] > } > > bind $itk_component(hist_next) <3> [itcl::code ${this}\ > toolbar_post_history_stack next $itk_component(hist_next)] > > balloon_bind_info $itk_component(hist_next)\ > [get_indep String GotoNextPosition] > > pack $itk_component(hist_next) -side left > > history_stack_control_buttons > > #combobox for the file symbols > itk_component add symbolcombo { > Combo& $itk_component(toolbar).symbolcombo \ > -width 26 \ > -entryballoon [get_indep String ActiveSymbol] \ > -buttonballoon [get_indep String ListRelatedSymbols] \ > -selectcommand [itcl::code $this toolbar_display_selected > $itk_component(toolbar).symbolcombo] > } { } > > pack $itk_component(symbolcombo) -side left -fill x -padx 2 > > # FIXME: Does this actually need to pass parameters? > Add_Symbol_Filter $itk_component(toolbar) > > #add/create editor command buttons > Add_Editor_Buttons $itk_component(toolbar) > > pack $itk_component(toolbar) -side top -fill x > } > > method Add_Symbol_Filter {exp} { > global combobox_editor_scopes > > # Add symbols filter to the right side of the combobox > > set extended [$itk_component(symbolcombo) component extended] > ># FIXME: This SymbolsFilter, opt, itk_component(symbolfilter) ># variable duplication needs to be cleaned up > set opt $extended.symfilter > set SymbolsFilter ${opt} > > $itk_component(symbolcombo) configure \ > -postcommand [itcl::code $this toolbar_post_scope_menu $opt] > > if {[winfo exists ${opt}]} { > destroy ${opt} > } > > itk_component add symbolfilter { > frame ${opt} > } > > pack ${opt} -fill both -expand true > > > #Radiobuttons (Related,All) > # FIXME: this should be a private variable (use "scope"). > uplevel #0 "set ${opt}-related 1" > > radiobutton ${opt}.related -anchor w -text [get_indep String > Related]\ > -command " ${this} toolbar_symbols"\ > -variable ${opt}-related -value 1 > > pack ${opt}.related -side top -fill x -expand y > lappend AllFilterOptions(radio) ${opt}.related > radiobutton ${opt}.all -anchor w -text [get_indep String All]\ > -command " ${this} toolbar_symbols"\ > -variable ${opt}-related -value 0 > pack ${opt}.all -side top -fill x -expand y > lappend AllFilterOptions(radio) ${opt}.all > > #Buttons (All,None) > frame ${opt}.btns > button ${opt}.btns.all -anchor w -text [get_indep String All]\ > -command " ${this} toolbar_symbols 1 " > pack ${opt}.btns.all -side left -fill x -expand y > lappend AllFilterOptions(button) ${opt}.btns.all > > button ${opt}.btns.none -anchor w -text [get_indep String None]\ > -command " ${this} toolbar_symbols -1 " > pack ${opt}.btns.none -side right -fill x -expand y > lappend AllFilterOptions(button) ${opt}.btns.none > > pack ${opt}.btns -side top -fill x -expand y > > #Filter options (cl,com,fd,fu,...) > foreach sc [lsort [array names combobox_editor_scopes]] { > uplevel #0 "set ${opt}-${sc} ${sc}" > checkbutton ${opt}.${sc} -anchor w -text\ > [convert_scope_to_str ${sc}] -command " ${this} > toolbar_symbols\ > " -variable ${opt}-${sc} -onvalue ${sc}\ > -offvalue "off" > pack ${opt}.${sc} -side top -fill x -expand y > lappend AllFilterOptions(checkbutton) ${opt}.${sc} > } > #Add checkbutton for undefined symbols (xref only) > checkbutton ${opt}.ud -anchor w -text [convert_scope_to_str ud]\ > -command " ${this} toolbar_symbols "\ > -variable ${opt}-ud -onvalue ud -offvalue off > lappend AllFilterOptions(checkbutton) ${opt}.ud > pack ${opt}.ud -side top -fill x -expand y > } > > #add editor commands > method Add_Editor_Buttons {exp} { > global sn_options > global tcl_platform > > set FindEditFr ${exp}.editfr > pack [frame ${FindEditFr}] -fill x > pack [frame ${FindEditFr}.grap1 -width 5] -side left > > #add new/open/save/print/copy/paste/undo > if {$sn_options(def,edit-more-buttons)} { > button ${FindEditFr}.new -takefocus 0 -image new_image -command\ > " ${this} file_new " > balloon_bind_info ${FindEditFr}.new [get_indep String > NewFileINFO] > pack ${FindEditFr}.new -side left > > button ${FindEditFr}.open -image open_image -takefocus 0\ > -command " ${this} file_open " > balloon_bind_info ${FindEditFr}.open [get_indep String\ > EINFOOpenFile] > pack ${FindEditFr}.open -side left > > #save > button ${FindEditFr}.save -image save_image -takefocus 0\ > -command " ${this} file_save " > balloon_bind_info ${FindEditFr}.save [get_indep String\ > EINFOSaveChanges] > pack ${FindEditFr}.save -side left > > if {$tcl_platform(platform) != "windows"} { > button ${FindEditFr}.print -takefocus 0 -image print_image\ > -command " ${this} file_print " > balloon_bind_info ${FindEditFr}.print [get_indep String\ > PrintFile] > pack ${FindEditFr}.print -side left > } > > #undo > button ${FindEditFr}.undo -takefocus 0 -image undo_image\ > -command " ${this} edit_undo " > balloon_bind_info ${FindEditFr}.undo [get_indep String > EditUndoINFO] > pack ${FindEditFr}.undo -side left > > #delete > button ${FindEditFr}.delete -takefocus 0 -image waste_image\ > -command " ${this} edit_delete " > balloon_bind_info ${FindEditFr}.delete [get_indep String\ > EINFODeleteSection] > pack ${FindEditFr}.delete -side left > > #cut > button ${FindEditFr}.cut -takefocus 0 -image cut_image -command\ > " ${this} edit_cut " > balloon_bind_info ${FindEditFr}.cut [get_indep String\ > EINFOCutSelection] > pack ${FindEditFr}.cut -side left > > #copy > button ${FindEditFr}.copy -takefocus 0 -image copy_image\ > -command " ${this} edit_copy " > balloon_bind_info ${FindEditFr}.copy [get_indep String\ > EINFOCopySelection] > pack ${FindEditFr}.copy -side left > > #paste > button ${FindEditFr}.paste -takefocus 0 -image paste_image\ > -command " ${this} edit_paste " > balloon_bind_info ${FindEditFr}.paste [get_indep String\ > EINFOPasteSelection] > pack ${FindEditFr}.paste -side left > > #compile > button ${FindEditFr}.compile -takefocus 0 -image compile_image\ > -command " ${this} do_compile_file " > balloon_bind_info ${FindEditFr}.compile [get_indep String\ > CompileINFO] > pack ${FindEditFr}.compile -side left > > } > > #combobox for the find command, do not use filter > Combo& ${FindEditFr}.find_hist -width 16 \ > -entryballoon [get_indep String EINFOEnterPattern]\ > -buttonballoon [get_indep String EINFOSearchHistory]\ > -selectcommand "${this} toolbar_findtext ${FindEditFr}.find_hist"\ > -postcommand "${this} toolbar_findtext_postcommand\ > ${FindEditFr}.find_hist" > set FindCombo ${FindEditFr}.find_hist > bind ${FindEditFr}.find_hist.entry \ > [bind ${FindEditFr}.find_hist.entry ] > bind ${FindEditFr}.find_hist.entry \ > [bind ${FindEditFr}.find_hist.entry ] > pack ${FindEditFr}.find_hist -side left > #button to find next/selected entry > button ${FindEditFr}.find -takefocus 0 -image find_image -command\ > " ${this} toolbar_search_pattern " > balloon_bind_info ${FindEditFr}.find [get_indep String\ > SearchFindSelectionINFO] > pack ${FindEditFr}.find -side left > > #some free space > pack [frame ${FindEditFr}.gap -width 5] -side left > #Retriever > button ${FindEditFr}.definition -takefocus 0 -image search_image\ > -command " ${this} toolbar_retriever " > bind_history ${FindEditFr}.definition retrieve > balloon_bind_info ${FindEditFr}.definition [get_indep String\ > RetrieverINFO] > pack ${FindEditFr}.definition -side left > > #Grep > button ${FindEditFr}.grep -takefocus 0 -image grep_image \ > -command "${this} search_grep" > > bind_history ${FindEditFr}.grep grep > balloon_bind_info ${FindEditFr}.grep [get_indep String INFOGrep] > pack ${FindEditFr}.grep -side left > > #some free space > pack [frame ${FindEditFr}.gap2 -width 5] -side left > } > > method AddStatusbar {} { > global sn_options > > itk_component add statusbar { > frame $itk_component(hull).statusbar > } > > #use the option flag > itk_component add reuse { > checkbutton $itk_component(statusbar).reuse\ > -relief groove\ > -text [get_indep String Reuse]\ > -variable [itcl::scope reusable]\ > -font $sn_options(def,layout-font) > } > > balloon_bind_info $itk_component(reuse) [get_indep String > ReusableINFO] > > pack $itk_component(reuse) -side left > > set reusable $sn_options(def,reuse-window) > > set keep $sn_options(def,window-switchable) > > itk_component add keep { > checkbutton $itk_component(statusbar).keep\ > -relief groove\ > -text [get_indep String Keep]\ > -variable [itcl::scope keep]\ > -font $sn_options(def,layout-font) > } > > balloon_bind_info $itk_component(keep) [get_indep String KeepINFO] > > pack $itk_component(keep) -side left > > itk_component add linenum { > label $itk_component(statusbar).linenum\ > -font $sn_options(def,layout-font)\ > -relief groove -bd 2 -anchor e -width 8\ > -textvar [itcl::scope linenum] > } > > pack $itk_component(linenum) -fill y -side left > > itk_component add message { > label $itk_component(statusbar).message\ > -font $sn_options(def,layout-font)\ > -relief groove -bd 2 -anchor w\ > -textvar [itcl::scope message] > } > > pack $itk_component(message) -expand y -fill both -side left > > pack $itk_component(statusbar) -side bottom -fill x > } > > method file_post {m} { > global sn_options > global prj_lines_num > > #call post command for project menus > ProjectMenuEntries_post ${m} "" .prjsub > > set fast_state normal > set new_state normal > > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > set state disabled > set save_state disabled > set fast_state disabled > set rev_state disabled > } else { > set state normal > if {[${ed} cget -file_changed]} { > set save_state normal > } else { > set save_state disabled > set fast_state disabled > } > #no revert for new files > if {[${ed} cget -filename] == $sn_options(noname_file)} { > set rev_state disabled > } else { > set rev_state ${state} > } > } > > #normal save is only possible, when no process is > #running > if {${save_state} == "normal" && [sn_processes_running]} { > set save_state disabled > } > > #we can't create/open files by readonly-project > if {$sn_options(readonly)} { > set new_state "disabled" > } > > #file commands > ${m} entryconfig [get_indep String EditNewFile] -state ${new_state} > ${m} entryconfig [get_indep String Open] -state ${new_state} > ${m} entryconfig [get_indep String EditSave] -state ${save_state} > ${m} entryconfig [get_indep String EditSaveFileAs] -state ${state} > ${m} entryconfig [get_indep String EditFastSave] -state ${fast_state} > ${m} entryconfig [get_indep String Revert] -state ${rev_state} > } > > proc post_recent_project {m topm pm} { > #get file menu widget name > set event_window [lmatch [winfo children [namespace tail ${topm}]]\ > {*#menu}] > set child [lindex [winfo children ${event_window}] 0] > > #Add menu entries for project history > return [update_project_menu_list ${m} ${pm}] > } > > proc update_project_menu_list {menu event_window} { > global sn_options > global sn_projects_list > > set pf $sn_projects_list(filename) > if {[info exists sn_projects_list(mtime)] && > $sn_projects_list(mtime)\ > == [file mtime ${pf}] && ![catch {${menu} index {*1.*}}]} { > return 0 > } > > set exist_projs [sn_read_exist_projects 1] > set proj_name $sn_options(sys,project-file) > > set off [lsearch -exact ${exist_projs} ${proj_name}] > if {${off} != -1} { > set exist_projs [lreplace ${exist_projs} ${off} ${off}] > } > > # Lets create the menu labels! > ${menu} delete 0 end > > set menu_proj "" > set i 1 > set idx 0 > foreach pr ${exist_projs} { > set lb [file tail ${pr}] > if {${i} < 10} { > ${menu} add command -label "${i}. ${lb}" -command\ > [list sn_open_project ${pr}] -underline 0 > } else { > ${menu} add command -label "${i}. ${lb}" -command\ > [list sn_open_project ${pr}] > } > menu_balloon_bind_info ${event_window} ${idx} ${pr} > > incr i > incr idx > } > return [expr {${i} > 1}] > } > > method file_new {} { > if {${ActiveWidget} != $itk_component(editor)} { > $itk_component(notebook) raise edit > } > [list_find_editor ${ActiveWidget}] new_file > } > > method file_open {} { > if {${ActiveWidget} != $itk_component(editor)} { > $itk_component(notebook) raise edit > } > [list_find_editor ${ActiveWidget}] open_file > } > > #Project callbacks > proc file_open_project {} { > sn_open_project > } > > proc file_save_project {} { > sn_save_project > } > > proc delete_current_project {} { > if {[sn_delete_current_project]} { > sn_projectmanager > delete_interp > } > } > > proc file_close_project {} { > if {[sn_quit]} { > sn_projectmanager > delete_interp > } > } > > #Save managment > method file_save {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} save_file > } > > method file_saveas {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} saveas_file 0 [${ed} cget -filename] > } > > method file_fastsave {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} fastsave_file > } > > method file_saveall {} { > Editor&::SaveAll > } > > method file_revert {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} revert_file > } > > method file_print {} { > ${ActiveWidget} print > } > > method edit_post {m} { > > set ed [list_find_editor ${ActiveWidget}] > > if {${ed} == ""} { > set state disabled > set modstate disabled > } else { > set state normal > if {[${ed} canModify]} { > set modstate normal > } else { > set modstate disabled > } > } > > ${m} entryconfig [get_indep String EditUndo] -state ${modstate} > ${m} entryconfig [get_indep String EditRedo] -state ${modstate} > ${m} entryconfig [get_indep String EditCut] -state ${modstate} > ${m} entryconfig [get_indep String EditCopy] -state ${state} > ${m} entryconfig [get_indep String EditPaste] -state ${modstate} > ${m} entryconfig [get_indep String EditDelete] -state ${modstate} > ${m} entryconfig [get_indep String SelectAll] -state ${state} > ${m} entryconfig [get_indep String EditInsertFile] -state ${modstate} > ${m} entryconfig [get_indep String EditIdent] -state ${modstate} > ${m} entryconfig [get_indep String EditOutdent] -state ${modstate} > } > > method edit_undo {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Undo > } > > method edit_redo {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Redo > } > > method edit_cut {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Cut > } > > method edit_copy {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Copy > } > > method edit_paste {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Paste > } > > method edit_delete {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} Delete > } > > method do_compile_file {} { > global sn_options > > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > > set file [${ed} cget -filename] > if {${file} == $sn_options(noname_file)} { > bell > return > } > > #get file name and convert it to an object file > set tocmpfile [sn_object_file [file tail ${file}]] > set tocmpdir [file dirname ${file}] > > #mask the file with "" if there are blanks in it. > if {[string first " " ${tocmpfile}] > 1} { > set tocmpfile "\"${tocmpfile}\"" > } > > set make [sn_make] > ${make}.make setmakecommand\ > "$sn_options(both,make-command) ${tocmpfile}" > ${make}.make ExecMake > } > > proc edit_proj_preferences {m} { > sn_project_preferences > } > > method edit_preferences {m} { > sn_project_preferences 0 [${ActiveWidget} whoami] ${ActiveWidget}\ > ${this} > } > > if {${sn_elix}} { > proc edit_elix_preferences {} { > sn_elix_preferences > } > } > > method edit_insert {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} insert_file > } > > method edit_indent {mode} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > Editor&::Indent ${ed} ${mode} > } > > method Handle_Rcs {cmd {prm ""}} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > eval ${cmd} ${prm} [${ed} cget -filename] > ${ed} SetTitle > } > > method edit_selectall {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > [${ed} editor] tag add sel 0.0 end > } > > method edit_clear {} { > ${ActiveWidget} clearselection > } > > method search_post {m} { > #if we don't have an editor in the actual view, > #disable string manipulation menu items > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > set state disabled > } else { > set state normal > } > > ${m} entryconfig [get_indep String SearchFind] -state ${state} > ${m} entryconfig [get_indep String SearchNext] -state ${state} > ${m} entryconfig [get_indep String SearchPrev] -state ${state} > ${m} entryconfig [get_indep String SearchReplace] -state ${state} > > # FIXME: using sub menu widgets directly is likely to break > # Disable goto submenu too > ${m}.goto entryconfig [get_indep String SearchGotoLine] -state > ${state} > ${m}.goto entryconfig [get_indep String SearchSetMark] -state > ${state} > ${m}.goto entryconfig [get_indep String SearchGotoMark] -state > ${state} > ${m}.goto entryconfig [get_indep String SearchGotoError] -state > ${state} > > #verify if we can retrieve something > if {${ed} != ""} { > set string [Get_Selection ${ed} ${ActiveWidget}] > } else { > set string "" > } > > if {${string} == ""} { > set retrstate disabled > } else { > set retrstate normal > } > > ${m} entryconfig [get_indep String SearchDefinition] -state > ${retrstate} > ${m} entryconfig [get_indep String SearchImplementation]\ > -state ${retrstate} > ${m} entryconfig [get_indep String SearchGrep] -state ${retrstate} > } > > method search_findtext {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} != ""} { > ${ed} FindText > } else { > bell > } > } > > method search_next {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} != ""} { > ${ed} FindNext -forwards > } else { > bell > } > } > > method search_prev {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} != ""} { > ${ed} FindNext -backwards > } else { > bell > } > } > > method search_replace {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} != ""} { > ${ed} Replace > } else { > bell > } > } > > proc Get_Selection {ed active_wdg} { > > # Get selection from current editor. > > if {${ed} != ""} { > set string [Editor&::Get_XSelection ${ed}] > } else { > set string "" > } > > # Get selection from current view. > > if {${string} == "" && ${ed} != ${active_wdg}} { > set sel [${active_wdg} Selection] > if {${sel} != ""} { > set string [lindex ${sel} 1] > set cls [lindex ${sel} 2] > if {${cls} != ""} { > set string "${cls} ${string}" > } > } > } > > return ${string} > } > > method search_definition {} { > > # Look for an editor. > > set ed [list_find_editor ${ActiveWidget}] > > # We use only the same editor, if the keep flag > # is not seted. > > if {${keep} && ${ed} != ""} { > set cmd "${ed} gotofile_cb" > } else { > set cmd "" > } > > if {${ed} != ""} { > return [Editor&::search_definition ${ed}] > } > > set string [Get_Selection ${ed} ${ActiveWidget}] > > if {${string} == ""} { > bell > return > } > > # Try to find method or function definition (don't bell) > > set ret [sn_retrieve_symbol ${string} {md fd fr} "" -exact 1 0 > ${cmd}] > > # Try to find any definition (not implementation or function body) > # (bell if nothing found) > > if {${ret} == 0} { > sn_retrieve_symbol ${string} all "" -exact 1 1 ${cmd} "" "" > "" "*"\ > -1 {{mi md} {fu fd}} > } > } > > method search_implementation {} { > > set ed [list_find_editor ${ActiveWidget}] > > if {${keep} && ${ed} != ""} { > set cmd "${ed} gotofile_cb" > } else { > set cmd "" > } > > if {${ed} != ""} { > return [Editor&::search_implementation ${ed}] > } > > set string [Get_Selection ${ed} ${ActiveWidget}] > if {${string} == ""} { > bell > return > } > > #find implementation > set ret [sn_retrieve_symbol ${string} {fu mi} "" -exact 1 0 ${cmd}] > > #find probably definition (correct for Tcl) > if {${ret} == 0} { > sn_retrieve_symbol ${string} {fd md fr} "" -exact 1 1 ${cmd} > } > } > > method search_gotoline {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} GotoLine > } > > method search_setmark {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > [${ed} editor] mark set markpos insert > } > ># FIXME: Targeted for removal. > > proc search_gotoerror {} { > if {[catch {sn_grep_edit_file [selection get]}]} { > bell > } > } > > method search_gotomark {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > > set t [${ed} editor] > ${t} mark set lastpos insert > ${t} mark set insert markpos > ${t} see insert > } > > #Execute grep with selection, when there is no selection, > #call grep dialog box > method search_grep {} { ># FIXME: this is not quite right just yet. Perhaps handle ># the case where there is nothing selected???? > #set ed [list_find_editor ${ActiveWidget}] > #if {${ed} == ""} { > # bell > # return > #} > #sn_grep > $itk_component(notebook) raise grep > $itk_component(grep) setPatternFromClipboard > $itk_component(grep) ExecGrep > } > > method search_goto_post {m} { > } > > proc history_post {m} { > sn_post_history_menu ${m} > } > > method tools_post {m} { > > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > set rcsstate disabled > } else { > if {[${ed} validFilename]} { > set rcsstate normal > } else { > set rcsstate disabled > } > } > # RCS submenu is disabled when the filename isn't valid > > $itk_component(rc_menu) entryconfig [get_indep String > ChooseCheckOut] \ > -state ${rcsstate} > > $itk_component(rc_menu) entryconfig [get_indep String > ChooseCheckIn] -state ${rcsstate} > $itk_component(rc_menu) entryconfig [get_indep String > ChooseDiscard] -state ${rcsstate} > $itk_component(rc_menu) entryconfig [get_indep String ChooseLock] > -state ${rcsstate} > $itk_component(rc_menu) entryconfig [get_indep String > ChooseUnlock] -state ${rcsstate} > $itk_component(rc_menu) entryconfig [get_indep String ChooseDiff] > -state ${rcsstate} > $itk_component(rc_menu) entryconfig [get_indep String > RevisionControlEditor] \ > -state ${rcsstate} > } > > method tools_ctree_post {m} { > } > > method tools_classbr_post {m} { > } > > method tools_xref_post {m} { > } > > method tools_incbr_post {m} { > } > > #add breakpoint or execute until the specified line > method tools_breakpoint_or_until {{until "break"}} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > set idx [[${ed} editor] index insert] > if {${idx} == ""} { > bell > return > } > dbg_set_breakpoint [${ed} cget -filename] ${idx} ${until} > } > > proc windows_new_window {{m ""} {page "edit"}} { > global tkeWinNumber > incr tkeWinNumber > > #verify if the tool command exists > if {${page} != "edit" && [tool_Exists ${page}] != "normal"} { > bell > return > } > > return [MultiWindow& .multiwindow-${tkeWinNumber} -raise ${page}] > } > > proc windows_new_post {m} { > set edit_state [tool_Exists edit] > set ctree_state [tool_Exists ctree] > set xref_state [tool_Exists xref] > set retr_state [tool_Exists retr] > set grep_state [tool_Exists grep] > set inc_state [tool_Exists incbr] > > ${m} entryconfig [get_indep String WindowsNew] -state ${edit_state} > ${m} entryconfig [get_indep String MultiClassHierarchy]\ > -state ${ctree_state} > ${m} entryconfig [get_indep String MultiClass] -state ${edit_state} > ${m} entryconfig [get_indep String MultiXRef] -state ${xref_state} > ${m} entryconfig [get_indep String MultiInclude] -state ${inc_state} > > ${m} entryconfig [get_indep String WindowsNewCTreeClass]\ > -state ${ctree_state} > ${m} entryconfig [get_indep String WindowsNewClassEditor]\ > -state ${ctree_state} > if {${ctree_state} == "normal" && ${xref_state} == "normal"} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String WindowsNewClassXRef] -state > ${state} > ${m} entryconfig [get_indep String WindowsNewRetrEditor]\ > -state ${retr_state} > ${m} entryconfig [get_indep String WindowsNewFindEditor]\ > -state ${grep_state} > ${m} entryconfig [get_indep String WindowsNewCTreeClassEditor]\ > -state ${ctree_state} > > } > > proc windows_new_ctree_class {m} { > set win [windows_new_window "" ctree] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_classbr" > } > > proc windows_new_class_edit {m} { > set win [windows_new_window "" classbr] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_edit" > } > > proc windows_new_class_xref {m} { > set win [windows_new_window "" classbr] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_xref" > } > > proc windows_new_retr_edit {m} { > set win [windows_new_window "" retr] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_edit" > } > > proc windows_new_find_edit {m} { > set win [windows_new_window "" grep] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_edit" > } > > proc windows_new_ctree_class_edit {m} { > set win [windows_new_window "" ctree] > update idletasks > after idle "update idletasks; ${win} windows_splitinto_classbr" > update idletasks > after idle "update idletasks; ${win} windows_splitinto_edit" > } > > proc windows_new_symbr {{m ""}} { > global tkeWinNumber > incr tkeWinNumber > return [SymBr& .multisymbr-${tkeWinNumber}] > } > > #return the number of existing windows, to verify > #if we want to exist or close the window > proc num_Existing_windows {} { > set len [llength [itcl::find objects "*" -class MultiWindow&]] > set len [expr ${len} + [llength [itcl::find objects "*" -class > SymBr&]]] > return ${len} > } > > #close window, if it is not the last window > #exit project, if it is the last window > method windows_close {m} { > if {[num_Existing_windows] > 1} { > if {[Close]} { > > #close related preferences window, if availiable > catch {${this}-preferences exitPreferences} > > #close window > itcl::delete object ${this} > } > } else { > #exit the project > MultiWindow&::file_close_project > } > } > > #iconize project > proc windows_iconize {m topw} { > sn_hide_show_project withdraw ${topw} > } > > method windows_split_post {m} { > set last [list_last ${ActiveWidget}] > > #disable deleting last pane, if no panes availiable > if {${last} == ${ActiveWidget}} { > set state disabled > } else { > set state normal > } > ${m} entryconfig [get_indep String SplitDeleteLast] -state ${state} > > ${m} entryconfig [get_indep String SplitIntoEditor]\ > -state [tool_Exists edit] > ${m} entryconfig [get_indep String SplitIntoClassHierarchy]\ > -state [tool_Exists ctree] > ${m} entryconfig [get_indep String SplitIntoClass] -state\ > [tool_Exists class] > ${m} entryconfig [get_indep String SplitIntoXRef] -state\ > [tool_Exists xref] > ${m} entryconfig [get_indep String SplitIntoInclude]\ > -state [tool_Exists incbr] > } > > ############################################ > # Views SECTION > ############################################ > proc find_mainwindow {view} { > foreach win [itcl::find objects "*" -class MultiWindow&] { > foreach tool [${win} tools] { > for {set nxt ${tool}} {${nxt} != ""} {set nxt [${nxt} > next]} { > if {${nxt} == ${view}} { > return [list ${win} ${tool}] > } > } > } > } > return "" > } > > # Find the main page in corresponding to the given view, > # it can be a sub view. > method find_page {view} { > foreach tool [tools] { > for {set nxt ${tool}} {${nxt} != ""} {set nxt [${nxt} next]} { > if {${nxt} == ${view}} { > return [${tool} whoami] > } > } > } > return "" > } > > proc find_browserwindow {view} { > foreach win [itcl::find objects "*" -class SymBr&] { > if {[${win} symbr] == ${view}} { > return ${win} > } > } > return "" > } > > proc windows_views_switchto {view} { > global Switch_Is_Enabled > > # Look for the window in the multiviews windows. > set win_tool [find_mainwindow ${view}] > if {${win_tool} != ""} { > # Disable switching. > ::incr Switch_Is_Enabled -1 > > set win [lindex ${win_tool} 0] > set page [lindex ${win_tool} 1] > > [${win} NoteBook] raise [${page} whoami] > ${view} Focus > ${win} raise > > # Reenable switching. > ::incr Switch_Is_Enabled > } else { > # Window not found, maybe its a retriever in the symbol browser. > set win [find_browserwindow ${view}] > if {${win} == ""} { > bell > return > } > ${win} raise > } > } > > proc windows_views_post {m} { > global sn_options > > if {[itcl::find objects "*" -class Editor&] != ""} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String MultiEditor] -state ${state} > > if {[itcl::find objects "*" -class ClassTree&] != ""} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String MultiClassHierarchy] -state > ${state} > > if {[itcl::find objects "*" -class Class&] != ""} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String MultiClass] -state ${state} > > if {[itcl::find objects "*" -class XRef&] != ""} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String MultiXRef] -state ${state} > > if {[itcl::find objects "*" -class Include&] != ""} { > set state normal > } else { > set state disabled > } > ${m} entryconfig [get_indep String MultiInclude] -state ${state} > > # Is a retriever-view availiable in the mainwindow (only). > set state disabled > foreach rtr [itcl::find objects "*" -class Retr&] { > #only in main windows > if {[catch {set win [[winfo toplevel ${rtr}] whoami]}] || ${win}\ > != "mainw"} { > continue > } else { > set state normal > break > } > } > ${m} entryconfig [get_indep String MultiRetriever] -state ${state} > ># FIXME: DEAR GOD THIS IS AN UGLY HACK! > # Is a grep-view avail. in the main window (only). > set state disabled > foreach gr [itcl::find objects -class Grep] { > #only in main windows > if {[catch {set win [[winfo toplevel ${gr}] whoami]}] || > ${win} !=\ > "mainw"} { > continue > } else { > set state normal > break > } > } > ${m} entryconfig [get_indep String MultiGrep] -state ${state} > } > > proc windows_views_edit_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class Editor&] { > catch { > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]"\ > -underline 0 > incr i > } > } > } > > proc windows_views_ctree_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class ClassTree&] { > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]" -underline 0 > incr i > } > } > > proc windows_views_class_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class Class&] { > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]" -underline 0 > incr i > } > } > > proc windows_views_xref_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class XRef&] { > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]" -underline 0 > incr i > } > } > > proc windows_views_inc_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class Include&] { > if {[catch {set t "${i} [${ed} Title 0]"}]} { > continue > } > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label ${t} -underline 0 > incr i > } > } > > proc windows_views_retr_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class Retr&] { > #only in main windows > if {[catch {set win [[winfo toplevel ${ed}] whoami]}] || > ${win} !=\ > "mainw"} { > continue > } > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]" -underline 0 > incr i > } > } > > proc windows_views_grep_post {m} { > ${m} delete 0 end > set i 1 ># FIXME: Another ugly hack! > foreach gr [itcl::find objects -class Grep] { > #only in main windows > if {[catch {set win [[winfo toplevel ${gr}] whoami]}] || > ${win} !=\ > "mainw"} { > continue > } > ${m} add command -command > "MultiWindow&::windows_views_switchto ${gr}" > -label "${i} [${gr} Title 0]" -underline 0 > incr i > } > } > > proc windows_views_make_post {m} { > ${m} delete 0 end > set i 1 > foreach ed [itcl::find objects "*" -class Make] { > ${m} add command -command > "MultiWindow&::windows_views_switchto ${ed}" \ > -label "${i} [${ed} Title 0]" -underline 0 > incr i > } > } > > ######################################################### > #End of Views SECTION > ######################################################### > > # Find the first classed (class whoami) object in the chain. > proc list_find {w whoami} { > global last_Editor > for {set nxt ${w}} {${nxt} != ""} {set nxt [${nxt} next]} { > if {[${nxt} whoami] == ${whoami}} { > return ${nxt} > } > } > return "" > } > > # Find the last accessed or the first editor in the chain. > proc list_find_editor {w} { > global last_Editor > set fnd "" > for {set nxt ${w}} {${nxt} != ""} {set nxt [${nxt} next]} { > if {[${nxt} whoami] == "edit"} { > if {${last_Editor} == ${nxt}} { > #return last accessed editor > return ${nxt} > }\ > elseif {${fnd} == ""} { > #mark the first editor > set fnd ${nxt} > } > } > } > # Return the first found editor or the empty string. > return ${fnd} > } > > # Return all objects in the list. > proc list_items {w} { > set items "" > for {set nxt ${w}} {${nxt} != ""} {set nxt [${nxt} next]} { > lappend items ${nxt} > } > return ${items} > } > > # Find the last object in the chain. > proc list_last {w {previous ""}} { > if {${previous} != ""} { > upvar ${previous} prev > } > set prev ${w} > set last ${w} > for {set nxt ${w}} {${nxt} != ""} {set nxt [${nxt} next]} { > set prev ${last} > set last ${nxt} > } > return ${last} > } > > method required_size {w} { > global sn_options > if {$sn_options(def,window-alighment) == "vertical"} { > set last_height [winfo height ${w}] > } else { > set last_height [winfo width ${w}] > } > set last_height [expr ${last_height} / 2] > return ${last_height} > } > > method add_new_pane {last} { > global tkeWinNumber > > set size [required_size ${last}] > # Create the editor now. > incr tkeWinNumber > set pane [${ActivePaned} add pane-${tkeWinNumber} -size ${size}] > # Give the upper pane the half size of it's > # original size. > set lastpane [winfo parent ${last}] > set lastpane [string range ${lastpane} [expr [string last\ > "." ${lastpane}] + 1] end] > ${ActivePaned} paneconfigure ${lastpane} -size ${size} > > return ${pane} > } > > # Add an editor to current window. This is not > # possible if we just added an editor. > > method windows_splitinto_edit {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not an editor > set last [list_last ${ActiveWidget}] > > set editpane [add_new_pane ${last}] > > incr tkeWinNumber > set ed ${editpane}.edit-${tkeWinNumber} > Editor& ${ed} -mesg_area $itk_component(statusbar) \ > -linenumber_var [itcl::scope linenum]\ > -message_var [itcl::scope message]\ > -findcombo ${FindCombo} \ > -parent $this > > set who [${last} whoami] > > # Configure selectcommand to be called whenever > # the selection is changed. > # Do this only when the previous command is not an editor. > if {${who} == "edit"} { > # Add the new editor into the chain. > ${last} configure -next ${ed} > > # Edit the same file as the prev. editor. > ${ed} configure -filename [${last} cget -filename] > > # When the active view is a retriever, bind the > # combo box to the editor. > }\ > elseif {${who} == "retr" || ${who} == "grep"} { > # Add the new editor into the chain. > ${last} configure -next ${ed} -selectcommand "${ed} gotosymbol" > > # Set related flag of the combo box to true. > upvar #0 ${SymbolsFilter}-related related > set related 1 > ># FIXME: what the heck? I was using -mesg_area $itk_component(statusbar) > > # Bind all the environment for the editor. > ${ed} configure -symbols $itk_component(symbolcombo)\ > -symbols_filter ${SymbolsFilter}\ > -menu $itk_component(edit_menu) -toolbar ""\ > -mesg_area (itk_component(statusbar))\ > -message_var [itcl::scope message]\ > -linenumber_var [itcl::scope linenum]\ > -findcombo ${FindCombo} > > # Enable combo box. > $itk_component(symbolcombo) configure -state normal > > # Activate editor. > ${ed} activate > > ::eval ${ed} gotosymbol [${last} Selection] > } else { > ${last} configure -next ${ed} -selectcommand "${ed} gotosymbol" > > ::eval ${ed} gotosymbol [${last} Selection] > } > pack ${ed} -fill both -expand y > > # View editor commands in toolbar, if not availiable. > DeActivate_Editor_buttons > > return ${ed} > } > > # Add a hierarchy browser to current window. This is not > # possible if we just added a class hierarchy. > > method windows_splitinto_ctree {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not a hierarchy browser > set last [list_last ${ActiveWidget}] > if {[${last} whoami] == "ctree"} { > bell > return "" > } > > # Create a new ctree pane. > set ctreepane [add_new_pane ${last}] > > incr tkeWinNumber > set ctree ${ctreepane}.ctree-${tkeWinNumber} > ClassTree& ${ctree} \ > -message_var [itcl::scope message] \ > -parent $this > > # Configure selectcommand to be called, when > # ever the selection is changed. > ${last} configure -selectcommand "${ctree} gotosymbol" -next ${ctree} > pack ${ctree} -fill both -expand y > > ::eval ${ctree} gotosymbol [${last} Selection] > > return ${ctree} > } > > # Add a class browser to current window. This is not > # possible if we just added a class browser. > > method windows_splitinto_classbr {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not a class browser. > set last [list_last ${ActiveWidget}] > if {[${last} whoami] == "classbr"} { > bell > return "" > } > > # Create the classbr now. > set classbrpane [add_new_pane ${last}] > incr tkeWinNumber > set classbr ${classbrpane}.classbr-${tkeWinNumber} > > Class& ${classbr} \ > -doubleclickcommand "${this} EditObject"\ > -class_doubleclickcommand "${this} ClassBrowserEditClass"\ > -mesg_area $itk_component(statusbar) \ > -parent $this > > # Configure selectcommand to be called, when > # ever the selection is changed. > ${last} configure -selectcommand "${classbr} gotosymbol" -next > ${classbr} > pack ${classbr} -fill both -expand y > > ::eval ${classbr} gotosymbol [${last} Selection] > > return ${classbr} > } > > # Add a xref browser to current window. This is not > # possible if we just added a xref browser. > > method windows_splitinto_xref {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not a xref > set last [list_last ${ActiveWidget}] > if {[${last} whoami] == "xref"} { > bell > return "" > } > > # Create the xref now > set xrefpane [add_new_pane ${last}] > incr tkeWinNumber > set xref ${xrefpane}.xref-${tkeWinNumber} > > XRef& ${xref} \ > -mesg_area $itk_component(statusbar) \ > -parent ${this} > > # Configure selectcommand to be called, when > # ever the selection is changed. > ${last} configure -selectcommand "${xref} gotosymbol" -next ${xref} > pack ${xref} -fill both -expand y > > ::eval ${xref} gotosymbol [${last} Selection] > > return ${xref} > } > > # Add an include browser to current window. This is not > # possible if we just added an include browser. > > method windows_splitinto_incbr {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not an include browser. > set last [list_last ${ActiveWidget}] > if {[${last} whoami] == "incbr"} { > bell > return "" > } > > # Create the include browser now. > set incbrpane [add_new_pane ${last}] > incr tkeWinNumber > set incbr ${incbrpane}.incbr-${tkeWinNumber} > > Include& ${incbr} \ > -mesg_area $itk_component(statusbar) \ > -parent $this > > # Configure selectcommand to be called, when > # ever the selection is changed. > ${last} configure -selectcommand "${incbr} gotosymbol" -next ${incbr} > pack ${incbr} -fill both -expand y > > ::eval ${incbr} gotosymbol [${last} Selection] > > return ${incbr} > } > > # Add a build window to current window. This is not > # possible if we just added a build window. > > method windows_splitinto_build {{m ""}} { > global tkeWinNumber > > # Verify that the last widget is not a build window > set last [list_last ${ActiveWidget}] > if {[${last} whoami] == "make"} { > bell > return "" > } > > # Create the make window now. > set makepane [add_new_pane ${last}] > incr tkeWinNumber > set make ${makepane}.make-${tkeWinNumber} > > Make ${make} -mesg_area $itk_component(statusbar) > > # Configure selectcommand to be called, when > # ever the selection is changed. > ${last} configure -selectcommand "${make} gotosymbol" -next ${make} > > pack ${make} -fill both -expand y -padx 3 -pady 3 > > # FIXME : not clear what this would do. > #::eval $incbr gotosymbol [$last Selection] > > return ${make} > } > > # Deletes the last pane from a view. > method windows_delete_last_pane {m} { > set last [list_last ${ActiveWidget} prev] > if {${last} == ${ActiveWidget}} { > return 0 > } > > set force_close 0 > > if {[$last whoami] == "edit"} { > # If we have more instances of this file open > # in different editors we don't have to worry > # about saving it when calling Close. > > set file [$last cget -filename] > > if {[CountInstancesOfFile $file] != 1} { > set force_close 1 > } > } > > # Ask the object for deleting. > if {[${last} Close $force_close] != 1} { > return 0 > } > > # Delete pointer to the deleted widget > # and the selectcommand. > ${prev} configure -next "" -selectcommand "" > > # Delete object from the pane widget. > itcl::delete object ${last} > > # Delete pane page. > set pane [string range ${last} 0 [expr {[string last "." ${last}] > - 1}]] > set page [string range ${pane} [expr {[string last "." ${pane}] + > 1}] end] > set pane [string range ${pane} 0 [expr {[string last "." ${pane}] > - 1}]] > ${pane} del ${page} > > # Hide editor buttons, if availiable. > DeActivate_Editor_buttons > > # If we enabled the combobox when splitting > # the window, disable it now. > set who [${prev} whoami] > if {${who} == "retr" || ${who} == "grep"} { > $itk_component(symbolcombo) configure -state disabled > } > > return 1 > } > > method switch_to_next_view {fcs} { > for {set w ${ActiveWidget}} {${w} != ""} {set w [${w} next]} { > if {[string first ${w} ${fcs}] == 0} { > set nxt [${w} next] > if {${nxt} != ""} { > ${nxt} Focus > return > } > } > } > ${ActiveWidget} Focus > } > > proc windows_post {my_top w {pref 0}} { > global sn_options > > # Delete only the menubuttons for availiable windows. > set cnt [expr 3 + ${pref}] > set num [${w} index end] > if {${num} >= ${cnt}} { > ${w} delete ${cnt} end > } > > set proj_len [expr [string length [sn_title]] + 1] > > set toplevs(${my_top}) 1 > # Ignore the menu's toplevel window! > set prjName [sn_title] > set pars "" > foreach win [winfo children .] { > set top [winfo toplevel ${win}] > > if {[info exists toplevs(${top})] || [::wm overrideredirect\ > ${top}]} { > continue > } > set toplevs(${top}) 1 > > set state_ind "" > switch [wm state ${top}] { > "withdrawn" { > continue > } > "iconic" { > set state_ind {+} > } > "normal" { > } > default { > continue > } > } > set title [wm title ${top}] > > regsub -all {[ ]+} ${title} { } title > set off [string first ${prjName} ${title}] > switch -- ${off} { > -1 { > } > 0 { > incr off ${proj_len} > set title [string trim [string range ${title} ${off}\ > end]] > } > default { > set title [string trim [string range ${title} 0\ > [expr ${off} - 1]]] > if {[string index ${title} 0] == "*"} { > set title [string trimleft ${title} "*"] > } > set title [string trimright ${title} "- "] > } > } > lappend pars [list ${title} ${state_ind} ${top}] > } > > set i 1 > foreach p [lsort -dictionary ${pars}] { > set title [lindex ${p} 0] > set accel [lindex ${p} 1] > set win [lindex ${p} 2] > > ${w} add command -label "${i} ${title}" -accelerator ${accel}\ > -underline 0 -command " raise_toplevel ${win} " > incr i > } > } > > method toolbar_post_scope_menu {m} { > global combobox_editor_scopes > > ${ActiveWidget} postcommand ${m} > > if {[${ActiveWidget} whoami] == "edit"} { > #enable buttons (All,Related,All,None) > foreach btn [eval list $AllFilterOptions(radio)\ > $AllFilterOptions(checkbutton)] { > ${btn} configure -state normal > } > foreach grp [lsort [array names combobox_editor_scopes]] { > set st "disabled" > set ind 0 > foreach sc $combobox_editor_scopes(${grp}) { > if {[::info commands paf_db_${sc}] != ""} { > set st "normal" > set ind 1 > break > } > } > if {${ind} == 0} { > uplevel #0 "set ${m}-${grp} off" > ${m}.${grp} configure -state ${st} > } else { > ${m}.${grp} configure -state ${st} > } > } > # Unknown scopes (only for xref). > ${m}.ud configure -state disabled > }\ > elseif {[${ActiveWidget} whoami] == "xref"} { > # Disable All, Related. > foreach btn $AllFilterOptions(button) { > ${btn} configure -state disabled > } > > # Enable buttons (All,None). > foreach btn $AllFilterOptions(radio) { > ${btn} configure -state normal > } > > foreach grp [lsort [array names combobox_editor_scopes]] { > set st "disabled" > set ind 0 > foreach sc $combobox_editor_scopes(${grp}) { > if {[::info commands paf_db_${sc}] != ""} { > set st "normal" > set ind 1 > break > } > } > if {${ind} == 0} { > uplevel #0 "set ${m}-${grp} off" > ${m}.${grp} configure -state ${st} > } else { > ${m}.${grp} configure -state ${st} > } > } > > # Unknown scopes (only for xref). > ${m}.ud configure -state normal > } else { > # Enable All, Related radios. > foreach btn $AllFilterOptions(radio) { > ${btn} configure -state normal > } > > # Disable filter options (buttons and checkbuttons). > foreach btn [eval list $AllFilterOptions(radio)\ > $AllFilterOptions(checkbutton)] { > ${btn} configure -state disabled > } > > # Unknown scopes (only for xref). > ${m}.ud configure -state disabled > } > } > > method history_stack_control_buttons {} { > if {$view_positions(next) == ""} { > set next_state disabled > } else { > set next_state normal > } > if {$view_positions(prev) == ""} { > set prev_state disabled > } else { > set prev_state normal > } > $itk_component(hist_prev) configure -state ${prev_state} > $itk_component(hist_next) configure -state ${next_state} > } > > # Add into view stack > # where: prev/next > # wdg: View widget (Editor, Class, Ctree, ..) > protected variable history_stack_active 0 > method history_stack_add_point {wdg {where ""}} { > global sn_options > global sn_history > > # Stack managment is active. > if {${history_stack_active}} { > return > } > > # Enter. > incr history_stack_active > > if {${where} == ""} { > set where ${stack_history_side} > } > > # Dump the current view of the widget. > set dump [${wdg} Dump] > > # Check if we have a restorable position at all. > if {${dump} == ""} { > #leave > incr history_stack_active -1 > # No dump position availiable. > return > } > > # Title for the list. > set title [${wdg} DumpTitle ${dump}] > > # Add it on the top of the stack. > set entry [list ${wdg} ${dump} ${title}] > > # Add to global (normal history from menu) history. > ${wdg} AddHistoryFromDump ${dump} ${title} > > # If view point is already availiable move it to top. > set i [lsearch -exact $view_positions(${where}) ${entry}] > if {${i} != -1} { > set view_positions(${where}) [lreplace $view_positions(${where})\ > ${i} ${i}] > } > set view_positions(${where}) [linsert $view_positions(${where}) 0\ > ${entry}] > > # If we add a view point into the prev list, we > # must delete all the next positions. > # Add it to the end of the previous list!! > # Do not do it when the user navigates using the history dump > # points. > if {${history_stack_navigate} == 0 && ${where} == "prev"} { > set nlen [llength $view_positions(next)] > set len [llength $view_positions(prev)] > if {[expr ${nlen} + ${len}] > $sn_history(stacksize)} { > set len [expr ${nlen} + ${len} - $sn_history(stacksize)] > set minlen [expr $sn_history(stacksize) / 2] > if {${len} < ${minlen}} { > set len ${minlen} > } > set view_positions(prev) [lrange $view_positions(prev) 0 > ${len}] > } > eval lappend view_positions(prev) $view_positions(next) > set view_positions(next) "" > } > > # Limit the number of history stack dump points. > if {[llength $view_positions(${where})] > $sn_history(stacksize)} { > set view_positions(${where}) [lrange $view_positions(${where}) 0\ > $sn_history(stacksize)] > } > > # Control history/stack navigation buttons. > history_stack_control_buttons > > # Leave stack managment. > incr history_stack_active -1 > } > > method toolbar_post_history_stack_menu {m what} { > set i 0 > foreach point $view_positions(${what}) { > set wdg [lindex ${point} 0] > if {![winfo exists ${wdg}]} { > #view removed > continue > } > ${m} add command -command " ${this} history_stack_goto_point\ > ${what} ${i} " -label [lindex ${point} 2] > incr i > } > } > > # Post menu to list all availiable saved view positions > method toolbar_post_history_stack {what btn} { > # Nothing in the stack > if {$view_positions(${what}) == ""} { > return > } > > # Set (x,y) for option-menu > set y [expr {[winfo rooty ${btn}] + [winfo height ${btn}]}] > set x [winfo rootx ${btn}] > > set m .view_position_pop_menu > catch {destroy ${m}} > menu ${m} -title "Views" -tearoff 0 -postcommand\ > "${this} toolbar_post_history_stack_menu ${m} ${what}" > wm overrideredirect ${m} 1 > tk_popup ${m} ${x} ${y} > } > > # True when the user navigates between the existing > # stack dump-points. > protected variable history_stack_navigate 0 > protected variable history_stack_goto_point_active 0 > > # Restore the first view point in the stack. > method history_stack_goto_point {where {index 0}} { > global Switch_Is_Enabled > > if {$view_positions(${where}) == ""} { > return > } > > if {${history_stack_goto_point_active}} { > bell > return > } > incr history_stack_goto_point_active 1 > > set point [lindex $view_positions(${where}) ${index}] > > # Fetch the widget path and verify if it exists, if not > # delete it from the history stack. > set wdg [lindex ${point} 0] > while {! [winfo exists ${wdg}]} { > catch {set view_positions(${where})\ > [lreplace $view_positions(${where}) ${index} ${index}]} > > if {$view_positions(${where}) == ""} { > break > } > > set point [lindex $view_positions(${where}) ${index}] > set wdg [lindex ${point} 0] > if {${point} == "" || ${wdg} == ""} { > break > } > } > > # Stack empty. > if {$view_positions(${where}) == "" || ${point} == "" || ${wdg} > == ""} { > incr history_stack_goto_point_active -1 > return > } > > # We must disable auto-switching to current position. > ::incr Switch_Is_Enabled -1 > > # Navigation between stack points is active, > # don't delete the next-stack. > incr history_stack_navigate > > if {${where} == "prev"} { > set stack_history_side "next" > } else { > set stack_history_side "prev" > } > > # Delete (before execution) the entry from the stack list. > catch {set view_positions(${where})\ > [lreplace $view_positions(${where}) ${index} ${index}]} > > # Find page in corresponding to the widget, it can be a sub widget. > set page [find_page ${wdg}] > > # Restore view point. > if {${page} != ""} { > catch { > # Popup view, don't raise the window. > view ${page} 0 > ${wdg} Restore [lindex ${point} 1] > # Focus on the restored view. > ${wdg} Focus > } err > if {${err} != ""} { > sn_log "stack goto history:${err}" > } > } else { > # A sub widget is deleted, no restore possible. > bell > } > > history_stack_control_buttons > > # Default is adding to previous list. > set stack_history_side "prev" > > # Navigation between stack points finished. > incr history_stack_navigate -1 > > # Reenable switching. > ::incr Switch_Is_Enabled > > incr history_stack_goto_point_active -1 > } > > method toolbar_display_selected {combo txt} { > ${ActiveWidget} goto ${combo} ${txt} > } > > method toolbar_findtext {combo txt} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} != ""} { > ${ed} FindNext -forwards ${txt} > } else { > bell > } > } > > method toolbar_findtext_postcommand {combo} { > global sn_options > ${combo} configure -contents $sn_options(search) > } > > method toolbar_search_pattern {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > if {![catch {set string [selection get]}]} { > set off [string first "\n" ${string}] > if {${off} != -1} { > set string [string range ${string} 0 [expr ${off} - 1]] > } > ${ed} FindNext -forwards ${string} > } else { > ${ed} FindNext -forwards [${FindCombo} cget -entrytext] > } > } > > method toolbar_retriever {} { > set ed [list_find_editor ${ActiveWidget}] > if {${ed} == ""} { > bell > return > } > ${ed} RetrieveObject > } > > method toolbar_symbols {{all 0}} { > ${ActiveWidget} filter ${all} > } > > method editor {} { > return $itk_component(editor) > } > > method editw {} { > if {[catch {set w [$itk_component(editor) editor]}]} { > return "" > } > return ${w} > } > > #find a reusable window > method is_Reusable {} { > if {![winfo exists $itk_component(reuse)] || !${reusable} ||\ > [$itk_component(reuse) cget -state] != "normal"} { > return 0 > } > return 1 > } > > method ActiveWidget {} { > return ${ActiveWidget} > } > > method NoteBook {} { > return $itk_component(notebook) > } > > method view {page {rs 1}} { > set old ${Activate_executed} > $itk_component(notebook) raise ${page} > > #Activate isn't executed, because the page is > #already active, add dump-point into history-stack > if {${old} == ${Activate_executed}} { > history_stack_add_point ${ActiveWidget} > } > if {${rs}} { > raise > } > } > > #find a window with specified class name > proc find_Reusable {} { > foreach win [itcl::find objects "*" -class MultiWindow&] { > if [${win} is_Reusable] { > # Remove the :: namespace qualifier. > return [namespace tail ${win}] > } > } > return "" > } > > method tools {} { > return ${AvailTools} > } > > #Close your self > method Close {} { > foreach tool ${AvailTools} { > for {set nxt ${tool}} {${nxt} != ""} {set nxt [${nxt} next]} { > # By editor with more than one buffer for the > # same file, do ask only one time!! > if {[${nxt} whoami] == "edit"} { > if {[info exists alread_Asked([${nxt} cget > -filename])]} { > continue > } > set alread_Asked([${nxt} cget -filename]) 1 > } > if {[${nxt} Close] != 1} { > # User canceled command. > return 0 > } > } > } > # Window can be closed. > return 1 > } > > # Verify if all buffers can be refereted. > proc CloseAll {} { > foreach win [itcl::find objects "*" -class Editor&] { > if {[info exists alread_Asked([${win} cget -filename])]} { > continue > } > set alread_Asked([${win} cget -filename]) 1 > if {[${win} Close] == 0} { > return 0 > } > } > # Close all symbol browsers. > return [SymBr&::CloseAll] > } > > method Restore {win} { > foreach page ${win} { > set i 0 > # Views in the page > # format " " > foreach view [lrange ${page} 1 end] { > if {${i} == 0} { > $itk_component(notebook) raise [lindex ${view} 0] > set w ${ActiveWidget} > } else { > switch -- [lindex ${view} 0] { > "edit" { > set w [windows_splitinto_edit] > } > "ctree" { > set w [windows_splitinto_ctree] > } > "classbr" { > set w [windows_splitinto_classbr] > } > "xref" { > set w [windows_splitinto_xref] > } > "incbr" { > set w [windows_splitinto_incbr] > } > default { } > } > } > ${w} Restore [lindex ${view} 3] > incr i > } > } > } > > # The function refreshes all views after updating the project > # XRef state is handled, not the views added to xref. > # > # vw: EMPTY to update all the views > # vw: List of view names to update > method Control_Display {{vw ""}} { > global combobox_editor_scopes > > if {${vw} == ""} { > set who_views [list edit classbr ctree xref incbr retr grep] > } else { > set who_views xref > } > > # Verify if the views are still availiable. > foreach who ${who_views} { > set page [$itk_component(notebook) subwidget ${who}] > set state [tool_Exists ${who}] > $itk_component(notebook) pageconfigure ${who} -state ${state} > } > > # Delete sub windows of disabled views > # except XRef windows, this must be updated after > # finishing XRef process. > foreach tool [tools] { > set who [${tool} whoami] > set page [$itk_component(notebook) subwidget ${who}] > if {${vw} != "" && ${vw} != ${who}} { > continue > }\ > elseif {${vw} == "" && ${who} == "xref"} { > continue > } > set state [tool_Exists ${who}] > > # Delete all sub views, if the view isn't more availiable. > if {${state} == "disabled"} { > set oldActive ${ActiveWidget} > set ActiveWidget ${tool} > while {1} { > if {[windows_delete_last_pane ""] == 0} { > break > } > } > set ActiveWidget ${oldActive} > } > } > > # If xref is the active page, then configure it's combo box. > if {${vw} == "xref" && [${ActiveWidget} whoami] == "xref"} { > ${ActiveWidget} Reenable > } > > # Check wether the combobox entries are still valid. > if {${vw} != "xref"} { ># FIXME: ugly hack uses internals of menu in combobox ! > set opt [$itk_component(symbolcombo) component menu].symfilter > foreach sc [lsort [array names combobox_editor_scopes]] { > if {! [winfo exists ${opt}.${sc}]} { > # Read the filters. > Add_Symbol_Filter $itk_component(toolbar) > break > > } > } > } > } > > method whoami {} { > return "mainw" > } > > # This function is called, when the project state is > # changes, like file is saved and reparsed, > # this function update the availiable views to > # the latest state. > proc Refresh_YourSelf {} { > > foreach win [itcl::find objects "*" -class MultiWindow&] { > ${win} Control_Display > } > > # Refresh editors. > foreach ed [itcl::find objects "*" -class Editor&] { > ${ed} Refresh_Display > } > > # Refresh hierarchy. > foreach ct [itcl::find objects "*" -class ClassTree&] { > ${ct} Refresh_Display > } > > # Refresh class. > foreach cl [itcl::find objects "*" -class Class&] { > ${cl} Refresh_Display > } > > # Refresh xref. > foreach xr [itcl::find objects "*" -class XRef&] { > ${xr} Refresh_Display > } > > # Refresh include. > foreach inc [itcl::find objects "*" -class Include&] { > ${inc} Refresh_Display > } > > # Refresh Retriever (exclusive mode). > foreach r [itcl::find objects "*" -class Retr&] { > ${r} Refresh_Display > } > > # Refresh Symbol browsers. > foreach sb [itcl::find objects "*" -class SymBr&] { > ${sb} Refresh_Display > } > } > > # This function is called after xref process is finished. > proc Refresh_YourSelf_After_XRef {} { > foreach win [itcl::find objects "*" -class MultiWindow&] { > ${win} Control_Display xref > } > > # Refresh xref windows. > foreach xr [itcl::find objects "*" -class XRef&] { > ${xr} Refresh_Display > } > } > > # This function saves the status of all opened multiwindows > # in the project file. > proc SaveYourSelf {} { > > sn_log "MutliWindow& SaveYourSelf.." > > set val "" > foreach win [itcl::find objects "*" -class MultiWindow&] { > > # Window id. > set wdump "window" > > # Window geometry. > lappend wdump [winfo x [${win} component hull]] > lappend wdump [winfo y [${win} component hull]] > lappend wdump [winfo width [${win} component hull]] > lappend wdump [winfo height [${win} component hull]] > lappend wdump [wm geometry [${win} component hull]] > lappend wdump [[${win} ActiveWidget] whoami] > > # Notepad pages. > # Note: only save the active view, don't save all views, > # this is not nesessary. > foreach tool [${win} ActiveWidget] { > set sub "page" > > if {${tool} == ""} { > continue > } > > # Save the tool and it's sub windows. > foreach page [MultiWindow&::list_items ${tool}] { > if {${page} == ""} { > continue > } > set who [${page} whoami] > > # We don't need to dump the settings for grep&retriever. > if {[lsearch -exact {retr grep} ${who}] != -1} { > continue > } > > # Save geometry. > set subpage "" > lappend subpage ${who} > lappend subpage [winfo width ${page}] > lappend subpage [winfo width ${page}] > > # Save widget settings. > lappend subpage [${page} Dump] > lappend sub ${subpage} > } > > lappend wdump ${sub} > } > lappend val ${wdump} > } > paf_db_proj put MultiWindows ${val} > > # Save existing browsers. > SymBr&::SaveYourSelf > > sn_log "MutliWindow& SaveYourSelf..end" > } > > # This function restores all the windows saved in the > # project file. > proc RestoreYourSelf {} { > global sn_options > global tkeWinNumber > global Switch_Is_Enabled > > # First disable switching. > ::incr Switch_Is_Enabled -1 > > # Let the status window be refreshed. > update idletasks > update > > # First restore saved symbol browsers. > SymBr&::RestoreYourSelf > > set val [paf_db_proj get -key MultiWindows] > if {${val} != ""} { > catch { > foreach win ${val} { > set id [lindex ${win} 0] > if {${id} != "window"} { > continue > } > > set geom [lindex ${win} 5] > > # Create window. > incr tkeWinNumber > set nwin ".multiwindow-${tkeWinNumber}" > MultiWindow& ${nwin} -geometry ${geom} > > # Restore settings. > ${nwin} Restore [lrange ${win} 7 end] > > # Toggle to active page. > ${nwin} view [lindex ${win} 6] > > update idletasks > } > } > } > # Reenable switching. > ::incr Switch_Is_Enabled > } > > # Create by default, a window with the retriever containing > # the file list. > # Create a symbol browser by default. > proc Default_Window {} { > global tkeWinNumber > global keybindings_initialized > > # Is a main window availiable. > set wins [itcl::find objects "*" -class MultiWindow&] > if {${wins} != ""} { > return > } > # Is a symbol browser available. > set wins [itcl::find objects "*" -class SymBr&] > if {${wins} != ""} { > return > } > > # Let the status window be refreshed. > update idletasks > update > > windows_new_symbr "" > } > > method isakeep {} { > return keep > } > > private variable reusable "1" ; # Is this window resuable. > private variable keep "1" ; # Keep window context(??). > private variable linenum "0" ; # Line number. > private variable message "" ; # Statusbar message. > > protected variable AllFilterOptions > > protected variable ActivePage "" > protected variable ActivePaned "" > protected variable ActivePane "" > protected variable ActiveWidget "" > > protected variable SymbolsFilter "" > protected variable FindCombo "" > protected variable FindEditFr "" > protected variable AvailTools "" > > # Contains all next positions. > # Contains all previous positions. > protected variable view_positions > protected variable stack_history_side "prev" > > public variable geometry "" > public variable symbolname $sn_options(noname_file) > > itk_option define -raise raise Raise "edit" > public variable x "" > public variable y "" >} > >proc ProjectMenuEntries_post {m {subwindow ""} {prjsub ""}} { > > # XRef process is running <==> no save & no project editor. > if {[sn_processes_running]} { > set xref_state disabled > } else { > set xref_state normal > } > > # No project editor/delete project during xref is running. > ${m}${prjsub} entryconfig [get_indep String ProjectEditorMenu]\ > -state ${xref_state} > ${m}${prjsub} entryconfig [get_indep String DeleteProject]\ > -state ${xref_state} > > # Close can only called, when there is another opend > # windows, by sub windows it must be able to close > # the window every time. > if {${subwindow} == "subwindow" || [MultiWindow&::num_Existing_windows]\ > > 1} { > set closestate normal > } else { > set closestate disabled > } > ${m} entryconfig [get_indep String WindowsClose] -state ${closestate} >} > ># Add project section. >proc AddProjectMenuEntries {m topw {submenu 0}} { > global sn_options sn_elix > set origm ${m} > > # Add project commands into a submenu. > if {${submenu}} { > # Project submenu... > set prjsub ${m}.prjsub > menu ${prjsub} -tearoff 0 > > ${prjsub} configure -font $sn_options(def,layout-font) > > ${m} add cascade -label [get_indep String ProjectMenu]\ > -underline [get_indep Pos ProjectMenu] -menu ${prjsub} > > set m ${prjsub} > } > > # Project. > ${m} add command -label [get_indep String NewProj] -underline\ > [get_indep Pos NewProj] -command sn_new_project > > ${m} add command -label [get_indep String OpenProject]\ > -underline [get_indep Pos OpenProject]\ > -command " MultiWindow&::file_open_project " > > ${m} add command -label [get_indep String DeleteProject]\ > -underline [get_indep Pos DeleteProject]\ > -command " MultiWindow&::delete_current_project " > > if {${m} == ${origm}} { > ${origm} add command -label [get_indep String CloseProject]\ > -underline [get_indep Pos CloseProject]\ > -command " MultiWindow&::file_close_project " > } > > ${m} add separator > > # Project editor. > ${m} add command -label [get_indep String ProjectEditorMenu]\ > -underline [get_indep Pos ProjectEditorMenu]\ > -command project_editor > > # Add preferences to the file menu (only in symbol browser). > ${m} add command -label [get_indep String ProjectPreferencesMenu]\ > -underline [get_indep Pos ProjectPreferencesMenu]\ > -command " MultiWindow&::edit_proj_preferences 0 " > > if {${sn_elix}} { > # EL/IX config. > ${m} add command -label [get_indep String ElixPreferences]\ > -underline [get_indep Pos ElixPreferences]\ > -command " MultiWindow&::edit_elix_preferences " > } > > # Recent project files. > set recent ${origm}.recent > menu ${recent} -tearoff 0 > > ${origm} add cascade -label [get_indep String RecentProjects]\ > -underline [get_indep Pos RecentProjects] -menu ${recent} > ghosting_menu_item ${origm} [get_indep String RecentProjects]\ > "MultiWindow&::post_recent_project ${recent} ${topw} ${m}" > > if {${m} != ${origm}} { > ${origm} add command -label [get_indep String CloseProject]\ > -underline [get_indep Pos CloseProject]\ > -command " MultiWindow&::file_close_project " > } > >} > >########################################################### >## Miscellaneous tools >########################################################### >proc RescanProject {} { > global sn_options sn_product_name > > #display a loading window > sn_loading_message [get_indep String Scanning] > > sn_parse_uptodate > > #delete the loading window > hide_loading_message >} > >proc AddMiscSubMenu {m} { > global sn_options > > set misc ${m} > > ${misc} configure -font $sn_options(def,layout-font) > > #Refresh project > ${misc} add command -label [get_indep String ScanProject]\ > -underline [get_indep Pos ScanProject] -command "RescanProject" > > #Reparse project > ${misc} add command -label [get_indep String Reparse]\ > -underline [get_indep Pos Reparse]\ > -command "Preferences&::Reparse ask" > > ${misc} add separator > > AddDebugFunctionality ${misc} > > # Ide Target Manager. > ${misc} add command -label [get_indep String BuildTargetManager]\ > -underline [get_indep Pos BuildTargetManager]\ > -command "sn_start_build_manager" > > # Make. > ${misc} add command -label [get_indep String MultiMake]\ > -underline [get_indep Pos MultiMake] -command "sn_make" >} > >############################################################ >## Debugger functionality >############################################################ >proc AddDebugFunctionality {m {topw ""}} { > ${m} add command -label [get_indep String DbgTitle] -underline\ > [get_indep Pos DbgTitle] -command sn_debugger >} > >########################################################### >## History menu >## Make History more fun >########################################################### >proc AddHistMenu {m} { > global sn_options > menu ${m}.history -tearoff 0\ > -postcommand "MultiWindow&::history_post ${m}.history" > > ${m}.history configure -font $sn_options(def,layout-font) > > ${m} add cascade -label [get_indep String History] -menu ${m}.history\ > -underline [get_indep Pos History] >} > >########################################################### >## Windows menu >## Make Windows with more fun >########################################################### >proc AddWindowsMenu {m cls {add_split 0} {add_views 1}} { > global sn_options > set win ${m}.windows > menu ${win} -postcommand "MultiWindow&::windows_post ${cls} ${m}.windows\ > [expr ${add_split} + ${add_views}]" -tearoff 0 > ${m} add cascade -label [get_indep String Windows] -menu ${win}\ > -underline [get_indep Pos Windows] > > ${m}.windows configure -font $sn_options(def,layout-font) > > # Submenu to create views. > set new ${m}.windows.new > menu ${new} -tearoff 0\ > -postcommand "MultiWindow&::windows_new_post ${new}" > > ${new} configure -font $sn_options(def,layout-font) > > ${m}.windows add cascade -label [get_indep String NewWork] -menu ${new}\ > -underline [get_indep Pos NewWork] > > # New editor. > ${new} add command -command " MultiWindow&::windows_new_window ${new} "\ > -label [get_indep String WindowsNew]\ > -underline [get_indep Pos WindowsNew]\ > -accelerator "F5" > > # New Class Hierarchy. > ${new} add command -command " MultiWindow&::windows_new_window ${new}\ > ctree " -label [get_indep String MultiClassHierarchy]\ > -underline [get_indep Pos MultiClassHierarchy] -accelerator "F6" > > # New Class. > ${new} add command -command " MultiWindow&::windows_new_window ${new}\ > classbr " -label [get_indep String MultiClass]\ > -underline [get_indep Pos\ > MultiClass] -accelerator "F7" > > # New Xref. > ${new} add command\ > -command " MultiWindow&::windows_new_window ${new} xref "\ > -label [get_indep String MultiXRef]\ > -underline [get_indep Pos MultiXRef] -accelerator "F8" > > # New Include. > ${new} add command\ > -command " MultiWindow&::windows_new_window ${new} incbr "\ > -label [get_indep String MultiInclude]\ > -underline [get_indep Pos MultiInclude] -accelerator "F9" > > ${new} add separator > > # New CTree-Class. > ${new} add command\ > -command " MultiWindow&::windows_new_ctree_class ${new} "\ > -label [get_indep String WindowsNewCTreeClass]\ > -underline [get_indep Pos WindowsNewCTreeClass] > > # New Class-Edit. > ${new} add command\ > -command " MultiWindow&::windows_new_class_edit ${new} "\ > -label [get_indep String WindowsNewClassEditor]\ > -underline [get_indep Pos WindowsNewClassEditor] > > # New Class-Xref. > ${new} add command\ > -command " MultiWindow&::windows_new_class_xref ${new} "\ > -label [get_indep String WindowsNewClassXRef]\ > -underline [get_indep Pos WindowsNewClassXRef] > > # New Retriever-Edit. > ${new} add command\ > -command " MultiWindow&::windows_new_retr_edit ${new}"\ > -label [get_indep String WindowsNewRetrEditor]\ > -underline [get_indep Pos WindowsNewRetrEditor] > > # New Find-Edit. > ${new} add command\ > -command " MultiWindow&::windows_new_find_edit ${new}"\ > -label [get_indep String WindowsNewFindEditor]\ > -underline [get_indep Pos WindowsNewFindEditor] > > # New CTreeClassEditor. > ${new} add command\ > -command " MultiWindow&::windows_new_ctree_class_edit ${new} "\ > -label [get_indep String WindowsNewCTreeClassEditor]\ > -underline [get_indep Pos WindowsNewCTreeClassEditor] > > ${new} add separator > > # New Symbol browser. > ${new} add command -command " MultiWindow&::windows_new_symbr ${new} "\ > -label [get_indep String MultiBrowser]\ > -underline [get_indep Pos MultiBrowser]\ > -accelerator "F4" > > # We support now splited windows. > if {${add_split} && ${cls} != ""} { > set split ${win}.split > menu ${split} -postcommand "${cls} windows_split_post ${split}"\ > -tearoff 0 > > ${split} configure -font $sn_options(def,layout-font) > > ${win} add cascade -label [get_indep String SplitInto] -menu > ${split}\ > -underline [get_indep Pos SplitInto] > > # Split into editor. > ${split} add command\ > -command " ${cls} windows_splitinto_edit ${split}"\ > -label [get_indep String SplitIntoEditor]\ > -underline [get_indep Pos SplitIntoEditor]\ > -accelerator "Ctrl+F5" > > # Split into class hierarchy. > ${split} add command\ > -command " ${cls} windows_splitinto_ctree ${split} "\ > -label [get_indep String SplitIntoClassHierarchy]\ > -underline [get_indep Pos SplitIntoClassHierarchy]\ > -accelerator "Ctrl+F6" > > # Split into class. > ${split} add command\ > -command " ${cls} windows_splitinto_classbr ${split} "\ > -label [get_indep String SplitIntoClass]\ > -underline [get_indep Pos SplitIntoClass]\ > -accelerator "Ctrl+F7" > > # Split into xref. > ${split} add command\ > -command " ${cls} windows_splitinto_xref ${split}"\ > -label [get_indep String SplitIntoXRef]\ > -underline [get_indep Pos SplitIntoXRef]\ > -accelerator "Ctrl+F8" > > # Split into include browser. > ${split} add command\ > -command " ${cls} windows_splitinto_incbr ${split} "\ > -label [get_indep String SplitIntoInclude]\ > -underline [get_indep Pos SplitIntoInclude]\ > -accelerator "Ctrl+F9" > > # Split into build winow. > ${split} add command\ > -command " ${cls} windows_splitinto_build ${split} "\ > -label [get_indep String BuildMenuItem]\ > -underline [get_indep Pos BuildMenuItem]\ > -accelerator "Ctrl+F10" > > ${split} add separator > > # Delete last pane. > ${split} add command\ > -command " ${cls} windows_delete_last_pane ${split} "\ > -label [get_indep String SplitDeleteLast]\ > -underline [get_indep Pos SplitDeleteLast]\ > -accelerator "Ctrl+F4" > } > > ###################################################### > #Availiable Views > #To list the availiable views > ###################################################### > > if {${add_views}} { > set views ${win}.views > menu ${views}\ > -postcommand "MultiWindow&::windows_views_post ${views}"\ > -tearoff 0 > ${win} add cascade -label [get_indep String Views] -menu ${views}\ > -underline [get_indep Pos Views] > > # Editor views. > set edview ${views}.edit > menu ${edview}\ > -postcommand "MultiWindow&::windows_views_edit_post > ${edview}"\ > -tearoff 0 > > ${views} add cascade -label [get_indep String MultiEditor]\ > -menu ${edview} -underline [get_indep Pos MultiEditor] > > # Hierarchy views. > set hview ${views}.ctree > menu ${hview}\ > -postcommand "MultiWindow&::windows_views_ctree_post > ${hview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiClassHierarchy]\ > -menu ${hview} -underline [get_indep Pos MultiClassHierarchy] > > # Class views. > set cview ${views}.class > menu ${cview}\ > -postcommand "MultiWindow&::windows_views_class_post > ${cview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiClass]\ > -menu ${cview} -underline [get_indep Pos MultiClass] > > # Xref views. > set xview ${views}.xview > menu ${xview}\ > -postcommand "MultiWindow&::windows_views_xref_post > ${xview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiXRef]\ > -menu ${xview} -underline [get_indep Pos MultiXRef] > > # Include views. > set iview ${views}.iview > menu ${iview}\ > -postcommand "MultiWindow&::windows_views_inc_post ${iview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiInclude]\ > -menu ${iview} -underline [get_indep Pos MultiInclude] > > # Retriever views. > set rview ${views}.rview > menu ${rview}\ > -postcommand "MultiWindow&::windows_views_retr_post > ${rview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiRetriever]\ > -menu ${rview} -underline [get_indep Pos MultiRetriever] > > # Grep views. > set gview ${views}.gview > menu ${gview}\ > -postcommand "MultiWindow&::windows_views_grep_post > ${gview}"\ > -tearoff 0 > ${views} add cascade -label [get_indep String MultiGrep]\ > -menu ${gview} -underline [get_indep Pos MultiGrep] > } > ###################################################### > # END of availiable views > ###################################################### > > # Iconize project. > ${m}.windows add command\ > -command " MultiWindow&::windows_iconize ${m}.windows ${cls} "\ > -label [get_indep String WindowsIconize]\ > -underline [get_indep Pos WindowsIconize] > ${m}.windows add separator > ${m}.windows add command -label "dummy" >} > >proc raise_toplevel {w} { > global sn_force_flag > if {[wm state ${w}] == "iconic"} { > wm deiconify ${w} > } else { > # Make sure that the window has focus on windows. > catch { > set wdg [focus -lastfor ${w}] > eval focus ${sn_force_flag} [${w} twidget] > focus ${wdg} > } > raise ${w} > } >} > ># Help menu. >proc AddHelpMenu {m topw} { > global sn_options > > menu ${m}.help -tearoff 0 > > ${m} add cascade -label [get_indep String Help] -menu ${m}.help\ > -underline [get_indep Pos Help] > > ${m}.help configure -font $sn_options(def,layout-font) > > ${m}.help add command -command " sn_help "\ > -label [get_indep String HelpContents]\ > -underline [get_indep Pos HelpContents] > > ${m}.help add command -label [get_indep String Abrav]\ > -underline [get_indep Pos Abrav]\ > -command " sn_show_abbrav " > > ${m}.help add separator > > ${m}.help add command -label [get_indep String Version]\ > -underline [get_indep Pos Version]\ > -command " focus ${topw} > sn_show_version_window > " >} > ># Synchronize more than one editor with the same file name ># to contain the same data. > >global SyncEditors_Disabled >global SyncEditors_Active > >set SyncEditors_Disabled 0 >set SyncEditors_Active 0 > >proc SyncEditors {cls args} { > global sn_options > global SyncEditors_Disabled > global SyncEditors_Active > > if {${SyncEditors_Disabled}} { > return > } > > if {$SyncEditors_Active} { > return > } > > if {[itcl::find object -isa Editor& $cls] == ""} { > set cls [winfo parent $cls] > } > > # Do not sync it if it's not an Editor&. > if {[itcl::find objects -isa Editor& $cls]==""} { > return > } > > set SyncEditors_Active 1 > > set file [${cls} cget -filename] > > # Edit a new file. > if {${file} != $sn_options(noname_file)} { > set editor [${cls} editor] > set cmd [lindex ${args} 0] > > switch ${cmd} { > "insert" { > set pos [${editor} index [lindex ${args} 1]] > set args [lreplace ${args} 1 1 ${pos}] > if {[string compare [lindex ${args} 2] ""] == 0} { > return > } > } > "delete" { > set pos1 [${editor} index [lindex ${args} 1]] > set args [lreplace ${args} 1 1 ${pos1}] > set pos2 [lindex ${args} 2] > if {${pos2} != ""} { > set pos2 [${editor} index ${pos2}] > set args [lreplace ${args} 2 2 ${pos2}] > } > } > default { > return > } > } > > foreach obj [itcl::find objects "*" -class Editor&] { > set cls [namespace tail $cls] > if {${obj} != ${cls} && [${obj} cget -filename] == ${file}} { > eval [${obj} editor] ${args} > if {[${obj} cget -file_changed] == 0} { > ${obj} setmodified 1 > ${obj} SetTitle > } > } > } > } > > if {[${cls} cget -file_changed] == 0} { > ${cls} setmodified 1 > ${cls} SetTitle > } > set SyncEditors_Active 0 > >} > ># Counts the number of Editor wigets that ># have $file currently open. > >proc CountInstancesOfFile {file} { > > set filecount 0 > > foreach obj [itcl::find objects "*" -class Editor&] { > if {[$obj cget -filename] == $file} { > incr filecount > } > } > > return $filecount >} > >######################################################### ># Global keybindings >######################################################### > ># Returns the current class from the active window. >proc get_active_class {} { > set fcs [focus] > if {${fcs} == ""} { > return "" > } > set cls ".[lindex [split ${fcs} .] 1]" > if {${cls} == "."} { > return "" > } > return ${cls} >} > >proc del_last_view {} { > set cls [get_active_class] > if {${cls} == ""} { > bell > return > } > catch {${cls} windows_delete_last_pane ""} >} > >proc add_view {vw} { > set cls [get_active_class] > if {${cls} == ""} { > bell > return > } > catch {${cls} windows_splitinto_${vw}} >} > >proc switch_to_view {view} { > > set cls [get_active_class] > > if {${cls} == ""} { > bell > return > } > > # Verify if the view can be launched. > > if {[tool_Exists ${view}] != "normal"} { > bell > return > } > > catch {${cls} view ${view}} >} > >proc main_print {w} { > catch {[winfo toplevel ${w}] file_print} >} > >proc close_main_window {w} { > > # This procedure is bound on Control-w, so don't > # close window when it's the last one in the project. > > if {[MultiWindow&::num_Existing_windows] > 1} { > catch {[winfo toplevel ${w}] windows_close dummy} > } >} > >proc find_dialog {w} { > catch {[winfo toplevel ${w}] search_findtext} >} > >proc switch_to_next_view {w} { > catch {[winfo toplevel ${w}] switch_to_next_view ${w}} >} > >############################################################## >## End of keybindings >############################################################## > >proc sn_start_build_manager {} { > > if {[itcl::find objects .build_manager]!=""} { > .build_manager raise > } else { > snIdeTargetMgr .build_manager > } > >} > ># dbg_start ># Start the nominated debugger. Pop up an error dialog if the exec fails. > >proc dbg_start {} { > global sn_options > > set cmd $sn_options(def,gdb-command) > if {[catch {exec ${cmd} &} msg] != 0} { > sn_error_dialog ${msg} > } >} > ># Last accessed editor. >set last_Editor "" > ># 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 widgetDefault >option add *Editor&.height 25 widgetDefault >option add *Editor&.wrap "none" widgetDefault >option add *Editor&.editsate "normal" widgetDefault > >itcl::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 > } > > eval itk_initialize $args > > # Init some variables. > set editor $itk_component(hull).editor > > set topw [winfo toplevel [namespace tail ${this}]] > > # Init some local/global variables. > init_Editor > > # 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 \ > [bind $itk_component(find_history).entry ] > > 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" > } > ># FIXME: The above toolbar_grep needs to be replaced by a call ># that will switch to the greppane and do a grep, I was thinking ># of calling sn_grep here, but that API needs to get replaced > > 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" > > # Load file into editor. > editfile $itk_option(-filename) \ > -1 "" 0 > > pack $itk_component(hull).xview \ > -side bottom \ > -fill x > pack $itk_component(hull).yview \ > -side right \ > -fill y > pack $itk_component(editor) \ > -fill both \ > -expand y > > # 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] > } > } > >#FIXME : This toolbar_grep method needs to be replaced by something ># that will just switch to the active grep pane! > > #Execute grep with selection, when there is no selection, > #call grep dialog box > method toolbar_grep {} { > #something must be selected > if {[catch {set pat [string trim [selection get]]}]} { > sn_error_dialog [get_indep String NoSelection] [get_indep > String \ > MultiGrep] > return > } > sn_grep 1 ${pat} > } > ############################################ > > ################################### > #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} "${this} Focus_In" > bind ${t} "${this} Focus_Out" > > #Bingings for traversal into the editor > foreach b [list > \ > > \ > \ > \ > \ > > \ > ] { > > bind ${t} ${b} "[bind Text ${b}]; ${this} find_and_mark_tag; > break" > } > > bind ${t} "+ > focus %W > ${this} find_and_mark_tag > " > bind ${t} " > %W see lastpos > %W mark set insert lastpos > > ${this} find_and_mark_tag > break" > bind ${t} " > tkTextExchangeMark %W > > ${this} find_and_mark_tag > break > " > # Save File. > bind ${t} "${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} "${this} Redo; break" > bind ${t} "${this} Redo; break" > > # Cut. > bind ${t} "${this} Cut; break" > > # Copy. > bind ${t} "${this} Copy; break" > > # Paste. > bind ${t} "${this} Paste; break" > > # Insert tab/return. > bind ${t} {Editor&::InsertTab %W; break} > bind ${t} {Editor&::Newline %W; break} > ># FIXME : need to be replaced with call to switch to the grep pane! > # Grep accelerator. > bind ${t} "${this} toolbar_grep; break" > > # Search bindings. > > # Find-dialog. > bind ${t} "${this} FindText; break" > > # Search backward. > # == > bind ${t} "${this} FindNext -backwards; break" > bind ${t} [bind ${t} ] > bind ${t} [bind ${t} ] > > # Search forward. > bind ${t} "${this} FindNext -forwards; break" > > # Sun Find. > bind ${t} [bind ${t} ] > > bind ${t} "${this} Replace; break" > bind ${t} "${this} GotoLine; break" > bind ${t} "${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} "${this} new_file; break" > bind ${t} "${this} open_file; break" > > # Bindings for Indent/Outdent. > bind ${t} "Editor&::Indent ${this} indent; break" > bind ${t} "Editor&::Indent ${this} outdent; break" > > # Define the queue, how the event are handled. > sn_add_tags $itk_component(editor) Editor > } > > # Default bindings for the text editor. > proc EditorBindings {} { > global sn_options > > set trav $sn_options(sys,alt-traverse) > set t Editor > > bind ${t} {tkTextSetMark %W insert; break} > > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > bind ${t} {+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 doesn't work. > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > bind ${t} {+Editor&::Insert_Mark_Bracket %W %A} > > # Traversal on shift-tab. > bind ${t} {focus [tk_focusPrev %W]} > > # Sun UNDO. > bind ${t} [bind Text ] > > bind ${t} "puts \"Other insert binding call\" ; > Editor&::set_overwrite %W \$tkText(%W,ovwrt);break" > > bind ${t} { > switch -- [%W get insert] { > \} { > 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 disabled > } else { > set state normal > } > 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" > } > ${m} add command \ > -label [get_indep String EditPaste] \ > -underline [get_indep Pos EditPaste] \ > -accelerator "Ctrl+V" \ > -command "${this} Paste" \ > -state ${state} > > # Text sensitive commands, (Retriever, Views). > ${m} add separator > > AddRetrieveMenu ${m} ${this} $itk_component(editor) ${x} ${y} > } > > # Take only valid identifier characters > # to retrieve valid symbols. > proc format_for_retriever {string} { > # Don't delete spaces in the middle of the text. > regexp \ > -- "\[^\t\n\r^#%*{};',`\"\\\?()\]*" ${string} string > > return [string trim ${string}] > } > > # Verify if we stay on a symbol declaration/implementaion > # this procedure returns the key tagname pointing to, > # when it's true. > proc points_to_header {ed pos} { > global sn_scopes > set lasttag "" > foreach tg [${ed} tag names ${pos}] { > if {[string first " " ${tg}] == -1} { > # Tags like "scope". > set lasttag ${tg} > } > } > if {[lsearch \ > -exact ${sn_scopes} ${lasttag}] == -1} { > set lasttag "" > } > return ${lasttag} > } > > # Adds the option menu for editor. > proc AddRetrieveMenu {m cls ed x y} { > global sn_options sn_scopes > > # Verify if the user has clicked on > # 1. a selection <==> retrieve selection > # 2. outside of a selected region <==> retrieve current word > # 3. word <==> retrieve word > # 4. nothing or unused <==> retrieve current symbol > # 5. No scope active <==> disabled > set pos [${ed} index @${x},${y}] > > # Verify if we stay on a symbol declaration/implementaion > set scopetag [points_to_header ${ed} ${pos}] > if {${scopetag} != ""} { > set file [${cls} getvalidfilename] > } else { > set file "" > } > > set selrng [${ed} tag ranges sel] > set current 1 > set string "" > if {${selrng} != ""} { > set pos1 [split ${pos} "."] > set by [lindex ${pos1} 0] > set bx [lindex ${pos1} 1] > > set rng1 [split [lindex ${selrng} 0] "."] > set rng2 [split [lindex ${selrng} 1] "."] > > set sy1 [lindex ${rng1} 0] > set sx1 [lindex ${rng1} 1] > set sy2 [lindex ${rng2} 0] > set sx2 [lindex ${rng2} 1] > # Clicked in the selection region. > if {${by} == ${sy1} && ${bx} >= ${sx1} &&(${sx2} >= ${bx} || \ > ${sy2} > ${by}) || ${by} == ${sy2} && ${bx} <= ${sx2} > &&(${sx1} \ > <= ${bx} || ${sy1} < ${by}) || ${by} > ${sy1} && ${by} < > ${sy2}} { > set string [format_for_retriever [lindex [${cls} > Selection] 1]] > set current 0 > } > } > if {${current} || ${string} == ""} { > # Current word. > set string [format_for_retriever [${ed} get "${pos} wordstart" \ > "${pos} wordend"]] > > # Take current symbol. > if {${string} == ""} { > set tg [${cls} find_tag ${pos}] > if {${tg} != ""} { > split_symbol ${tg} class sym scope > if {${class} != ""} { > set string "${class}\:\:${sym}" > } else { > set string ${sym} > } > set string [format_for_retriever ${string}] > } > } > } > if {${string} == ""} { > set findstate disabled > set lbl "" > } else { > set findstate normal > set lbl " [get_indep String Of] '${string}'" > } > > # Retrieve definition. > ${m} add command \ > -accelerator "$sn_options(sys,alt-accelpref)+D" \ > -label "[get_indep String SearchDefinition]${lbl}" \ > -underline [get_indep Pos SearchDefinition] \ > -command "Editor&::search_definition ${cls} [list ${string}]" \ > -state ${findstate} > > # Retrieve implementation. > ${m} add command \ > -accelerator "$sn_options(sys,alt-accelpref)+I" \ > -label "[get_indep String SearchImplementation]${lbl}" \ > -underline [get_indep Pos SearchImplementation] \ > -command "Editor&::search_implementation ${cls} [list > ${string}]" \ > -state ${findstate} > > ${m} add separator > > set vw "" > set vlen [string length ${vw}] > > # View Hierarchy. > ${m} add command \ > -accelerator "$sn_options(sys,alt-accelpref)+H" \ > -label "${vw}[get_indep String MultiClassHierarchy] ${lbl}" \ > -underline [expr [get_indep Pos MultiClassHierarchy] + ${vlen}] \ > -command "sn_classtree [list ${string}]" \ > -state ${findstate} > > # View Class. > ${m} add command \ > -accelerator "$sn_options(sys,alt-accelpref)+C" \ > -label "${vw}[get_indep String MultiClass] ${lbl}" \ > -underline [get_indep Pos MultiClass] \ > -command "sn_classbrowser [list ${string}]" \ > -state ${findstate} > > if {${scopetag} != ""} { > set xstring "${string}(${scopetag})" > } else { > set xstring ${string} > } > > if {${findstate} == "normal" && ! [have_xref]} { > set xref_state disabled > } else { > set xref_state normal > } > > # View XRef. > ${m} add command \ > -accelerator "$sn_options(sys,alt-accelpref)+X" \ > -label "${vw}[get_indep String MultiXRef] ${lbl}" \ > -underline [get_indep Pos MultiXRef] \ > -command "sn_xref both [list ${xstring}] [list ""] [list > ${file}]" \ > -state ${xref_state} > } > > method bind_right_mouse {t} { > global sn_options > if {$sn_options(def,edit-rightmouse-action) == "scroll"} { > bind ${t} <3> { } > bind ${t} { } > } else { > bind ${t} <3> "${this} m3_post_menu %W %X %Y %x %y; break" > bind ${t} {break} > } > } > > # If tabsize is not specified, use default tab size. > proc set_tabsize {t {tabsize ""} {refr ""}} { > global sn_options > > if {${tabsize} == ""} { > # If $wd is empty or not a valid number, take 8 ! > if {[catch {set sn_options(def,edit-tabstop) \ > [expr $sn_options(def,edit-tabstop) + 0]}]} { > set sn_options(def,edit-tabstop) 8 > } > set tb $sn_options(def,edit-tabstop) > } else { > set tb ${tabsize} > } > > # Don't use "-tabs" to change the tab size, it does > # have another behavior as normal tabulators. > ${t} config \ > -tabsize ${tb} > } > > # If tabsize is not specified, use default tab size. > proc set_tab {t {tabsize ""} {refr ""}} { > global sn_options > > set font [${t} cget -font] > set text_avg_width [font measure ${font} "M"] > > if {${tabsize} == ""} { > # If $wd is empty or not a valid number, take 8 ! > if {[catch {set sn_options(def,edit-tabstop) \ > [expr $sn_options(def,edit-tabstop) + 0]}]} { > set sn_options(def,edit-tabstop) 8 > } > set tb $sn_options(def,edit-tabstop) > } else { > set tb ${tabsize} > } > > ${t} config \ > -tabs [expr {${text_avg_width} * ${tb}}] > } > > proc set_wrap {w} { > global sn_options > ${w} config \ > -wrap $sn_options(def,edit-wrap) > } > > # Toggle or set the insert/overwrite flag. > proc set_overwrite {w {overwrite ""} {toggle "toggle"}} { > global sn_options > global tkText > > if {${overwrite} == ""} { > set overwrite $sn_options(def,edit-overwrite-mode) > } > > if {${toggle} == "toggle" || ${toggle} == "yes"} { > if {${overwrite}} { > set overwrite 0 > } else { > set overwrite 1 > } > } > > set tkText(${w},ovwrt) ${overwrite} > > if {$tkText(${w},ovwrt)} { > set wd 8 > } else { > set wd 2 > } > > ${w} config \ > -insertwidth ${wd} > } > > # The basic insertion routine for a tab. > proc InsertTab {w {pos ""}} { > global sn_options > > # Insert Spaces ansted of Tabs. > if {$sn_options(def,edit-tab-inserts-spaces)} { > # At least we should insert one character. > set txt " " > for {set i 1} {${i} < $sn_options(def,edit-tabstop)} {incr i} { > append txt " " > } > > if {${pos} == ""} { > tkTextInsertChar ${w} ${txt} > } else { > tkTextInsert ${w} ${pos} ${txt} > } > return > } > > if {${pos} == ""} { > tkTextInsertChar ${w} \t > } else { > tkTextInsert ${w} ${pos} \t > } > # NOBODY asks us to translate previous blanks to tabs when > # the user inserts a TAB. > return > } > > method Undo {} { > tkTextUndo $itk_component(editor) > } > > method Redo {} { > global tkText > ::set tkText($itk_component(editor),prevCmd) "Redo" > tkTextUndo $itk_component(editor) > } > > method Cut {} { > # Only cut when there is a valid selection. > if {![catch {$itk_component(editor) get sel.first}]} { > tkTextCut $itk_component(editor) > } > } > > method Copy {} { > tkTextCopy $itk_component(editor) > } > > method Paste {} { > tkTextPaste $itk_component(editor) > } > > method Delete {} { > catch {tkTextDelete $itk_component(editor) insert > [tkTextPlaceChar $itk_component(editor) +] 1 0} > } > > method FindNext {{direction ""} {string ""}} { > global sn_options > > if {![info exists edit_SearchString]} { > set edit_SearchString $sn_options(search,str) > } > > if {${direction} != ""} { > set edit_SearchDirection ${direction} > } > if {[string compare ${string} ""] == 0} { > set string ${edit_SearchString} > } > SearchForNext ${string} > > find_and_mark_tag > } > > # Get a search string from the user and search for it in the specified > # text widget. > method FindText {} { > global sn_options > > set s ${topw}.multiedit_search > if {[winfo exists ${s}]} { > if {[${s} state] != "normal"} { > ${s} deiconify > } else { > ${s} raise > } > ${s} move_to_mouse > > # Set text only and return. > catch {set edit_SearchString [string trim \ > [selection get]]} > return > } > > # See if there is a selection to look for. > catch { > set edit_SearchString [string trim [selection get]] > } > > set s [sourcenav::Window ${s}] > set strchk ${s}.strchk > set strs ${strchk}.string > set chk ${strchk}.chk > set but ${s}.but > > ${s} title [sn_title [get_indep String EditSearchFor]] > ${s} on_close "${this} Delete_Trace_SearchString ${but}.start; > itcl::delete object ${s}" > > frame ${strchk} > > frame ${strs} > label ${strs}.label \ > -text [get_indep String SearchPattern] \ > -underline [get_indep Pos SearchPattern] \ > -anchor w > entry ${strs}.entry \ > -width 30 \ > -bd 3 \ > -relief sunken \ > -exportselection no \ > -textvariable [itcl::scope edit_SearchString] > ${strs}.entry select to end > bind ${strs}.entry "${but}.start invoke" > pack ${strs}.label \ > -side left \ > -padx 5 > pack ${strs}.entry \ > -side left \ > -padx 5 \ > -fill x \ > -expand y > > frame ${but} > if {${edit_SearchString} == ""} { > set state disabled > } else { > set state normal > } > button ${but}.start \ > -text [get_indep String UtilSearch] \ > -underline [get_indep Pos UtilSearch] \ > -state ${state} \ > -command "${this} SearchForNext" > # Trace the button to enable/disable it, when string is (not) empty. > Trace_SearchString ${but}.start > button ${but}.cancel \ > -text [get_indep String Cancel] \ > -underline [get_indep Pos Cancel] \ > -command " > ${this} Delete_Trace_SearchString ${but}.start > itcl::delete object ${s}" > pack ${but}.start \ > -side top \ > -fill x \ > -padx 10 \ > -pady 5 > pack ${but}.cancel \ > -side top \ > -fill x \ > -padx 10 \ > -pady 5 > > frame ${chk} > checkbutton ${chk}.case \ > -text [get_indep String IgnoreCase] \ > -underline [get_indep Pos IgnoreCase] \ > -variable [itcl::scope edit_SearchNoCase] \ > -onvalue "-nocase" \ > -offvalue "" > checkbutton ${chk}.regexp \ > -text [get_indep String RegExp] \ > -underline [get_indep Pos RegExp] \ > -variable [itcl::scope edit_SearchMethod] \ > -onvalue "-regexp" \ > -offvalue "-exact" > checkbutton ${chk}.forward \ > -text [get_indep String SQLFfor] \ > -underline [get_indep Pos SQLFfor] \ > -variable [itcl::scope edit_SearchDirection] \ > -onvalue "-forwards" \ > -offvalue "-backwards" > pack ${chk}.case \ > -side top \ > -anchor nw \ > -padx 35 > pack ${chk}.regexp \ > -side top \ > -anchor nw \ > -padx 35 > pack ${chk}.forward \ > -side top \ > -anchor nw \ > -padx 35 > > # Bind_focus_enter $s "focus $strs.entry". > > pack ${strs} \ > -side top \ > -fill x \ > -pady 5 \ > -expand y > pack ${chk} \ > -side top \ > -fill x \ > -pady 5 \ > -expand y > pack ${strchk} \ > -side left \ > -fill x \ > -pady 20 \ > -fill x \ > -expand y > pack ${but} \ > -anchor nw \ > -side left \ > -padx 20 \ > -pady 5 > focus ${strs}.entry > > ${s} move_to_mouse > catch {${s} resizable yes no} > > update idletasks > set geom [split [lindex [split [${s} geometry] "+"] 0] "x"] > ${s} minsize [lindex ${geom} 0] [lindex ${geom} 1] > } > > # Search from the current insertion point to EOF for a given string and > # highlight the first occurrence found; search will wrap-around. > method SearchForNext {{string ""} {top ""}} { > global sn_options > global SearchFoundLength > ># FIXME: What is this SearchFoundLength used for ?? > set SearchFoundLength 0 > > if {[string compare ${string} ""] != 0} { > 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) 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 > ${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 "focus ${str2}.entry" > bind ${str1}.entry "${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 "${buts}.next invoke" > bind ${str2}.entry "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 "${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 > > itcl::delete object ${f} > update idletasks > if {$tcl_platform(platform) == "windows"} { > sn_wait 50 > } > ${this} SetFondPos [set $itk_option(-linenumber_var)] 1 0 > } > > # > # The basic insertion routine for brackets > # If requested, does bracket matching > # > # w: Editor widget > # sb: start bracket > # eb: end bracket > # insert: marks if a bracket is inserted or the region > # has to selected > proc Insert_Mark_Bracket {args} { > after idle "Editor&::x_Insert_Mark_Bracket ${args}" > } > proc x_Insert_Mark_Bracket {w sb {bracket 1}} { > global sn_options > > #by insertion, do a bracket selection > #by double-click on a bracket, do a real selection > if {${bracket}} { > set tag bracket > } else { > set tag sel > } > > #delay is invalid > if {$sn_options(def,edit-bracket-delay) <= 0} { > return > } > > set ebees "\"\'\>\]\)\}" > set sbees "\"\'\<\[\(\{" > set i [string first ${sb} ${ebees}] > if {${i} != -1} { > set eb [string index ${sbees} ${i}] > } else { > set i [string first ${sb} ${sbees}] > if {${i} == -1} { > return > } > set eb [string index ${ebees} ${i}] > } > > set str_range "" > > switch -- ${sb} { > \" - > \' { > #if string tag is availiable, mark the whole reagon > #of the string > set tags [${w} tag names insert] > if {[lsearch \ > -exact ${tags} str] != -1} { > set str_range [${w} tag prevrange str insert+1c] > if {${str_range} != ""} { > set idx [lindex ${str_range} 0] > set end [lindex ${str_range} end] > > #somebody tries to select a region in text area > #can he do it? > if {[${w} compare ${idx} < insert] && [${w} compare \ > ${end}-1c > insert]} { > return > } > } > } > > #do normal selection (locate a matching \" > if {${str_range} == ""} { > set ob "" > set cb ${eb} > set beg_off [${w} index "insert-200c"] > set cont [${w} get ${beg_off} "insert-1c"] > set forw 0 > } > } > \> - > \] - > \) - > \} { > set ob ${sb} > set cb ${eb} > set beg_off 0.0 > if {${bracket}} { > set cont [${w} get ${beg_off} insert] > } else { > set cont [${w} get ${beg_off} "insert+1c"] > } > set forw 0 > } > \< - > \[ - > \( - > \{ { > set ob ${sb} > set cb ${eb} > set beg_off "insert" > set cont [${w} get ${beg_off} end] > set forw 1 > } > default { > return > } > } > > if {${str_range} == ""} { > # brace_balance is written in C. If it does not exist just > return. > if {[::info commands brace_balance] != ""} { > set off [brace_balance ${cont} ${forw} ${ob} ${cb}] > } else { > return > } > if {${off} == -1} { > return > } > set idx [${w} index "${beg_off} + ${off} chars"] > set end [${w} index insert] > } > > ${w} tag remove ${tag} 0.0 end > ${w} see ${idx} > > if {${str_range} == ""} { > if {[${w} compare ${idx} > "insert"]} { > set end ${idx} > set idx "insert" > } \ > elseif {${bracket}} { > set end "insert" > } else { > set end "insert+1c" > } > } > > after idle "${w} tag add ${tag} ${idx} ${end}" > if {${bracket}} { > # If we just insert remove the selection. > set cmd "; ${w} tag remove ${tag} 0.0 end" > } else { > set cmd "" > } > update idletasks > after $sn_options(def,edit-bracket-delay) "${w} see insert ${cmd}" > } > > # > # The basic insertion routine for adding a new line > # > proc Newline w { > global sn_options > if {$sn_options(def,edit-indentwidth) <= 0} { > tkTextInsertChar ${w} \n > } else { > set l [${w} get "insert linestart" "insert lineend"] > set rest [${w} get "insert" "insert lineend"] > set ind_off [list 0 0] > regexp \ > -indices "^\[ \t\]*" ${l} ind_off > set end [lindex ${ind_off} 1] > set indentStr [string range ${l} 0 ${end}] > # Unexpand the spaces to TABS. > set spaces [format "%8.8s" ""] > regsub \ > -all ${spaces} ${indentStr} "\t" indentStr > regsub \ > -all "\[ \]+\t" ${indentStr} "\t" indentStr > set l [${w} get insert "insert lineend"] > set ind_off [list 0 0] > regexp \ > -indices "^\[ \t\]*" ${l} ind_off > set end [expr [lindex ${ind_off} 1] + 1] > tkTextInsertChar ${w} \n${indentStr} > } > } > > # The function tries to get an identifier from the text widget. > # 1. from the selection (if that exists) > # 2. from the cursor position > proc get_current_word {{cls ""}} { > global sn_all_scopes > set w [${cls} editor] > set name "" > > if {[catch {set name [selection get]}]} { > set name "" > foreach nm [${w} tag names insert] { > if {[lsearch \ > -exact ${sn_all_scopes} ${nm}] != -1} { > set rng [${w} tag prevrange ${nm} "insert +1c"] > set name [format_for_retriever [eval ${w} get ${rng}]] > } > } > if {${name} == ""} { > set name [format_for_retriever [${w} get "insert wordstart" \ > "insert wordend"]] > } > } > > return ${name} > } > > proc Get_XSelection {{cls ""}} { > if {![catch {set string [selection get]}]} { > set off [string first "\n" ${string}] > if {${off} != -1} { > set string [string trim [string range ${string} 0 \ > [expr ${off} - 1]]] > } > } else { > set string "" > } > > #look for the current symbol in the editor > if {${string} == "" && ${cls} != ""} { > set sel [${cls} Selection] > if {${sel} != ""} { > set string [lindex ${sel} 1] > if {[lindex ${sel} 2] != ""} { > set string "[lindex ${sel} 2] ${string}" > } > } > } > > #look for the current word in the editor > if {${string} == "" && ${cls} != ""} { > set string [Editor&::get_current_word ${cls}] > } > > return ${string} > } > > proc search_definition {cls {string ""} {file ""}} { > search_implementation ${cls} ${string} ${file} "def" > } > proc search_implementation {cls {string ""} {file ""} {imp_def "imp"}} { > global sn_scopes > set cls [namespace tail $cls] > > if {$cls != "" && [[$cls cget -parent] isakeep] == 1} { > set cmd "${cls} gotofile_cb" > } else { > set cmd "" > } > > #see if cursor stays on a symbol header > if {${cls} != ""} { > set editor [${cls} editor] > set pos [$editor index {insert wordstart}] > } > if {${cls} != "" && [points_to_header [${cls} editor] ${pos}] != > ""} { > set sel [${cls} Selection] > set scope [lindex ${sel} 0] > set sym [lindex ${sel} 1] > set cls [lindex ${sel} 2] > set file [lindex ${sel} 3] > set type [lindex ${sel} 5] > set prm [lindex ${sel} 6] > > set string [string trim "${cls}\:\:${sym}" "\:\:"] > > set have_declaration 1 > } else { > if {${string} == ""} { > set string [Get_XSelection ${cls}] > } > if {${string} == ""} { > bell > return > } > set from "" > set type "" > set prm "" > set to "" > > set have_declaration 0 > } > > #look using the following table > #pattern file param type > #pattern file param "" > #pattern "" param type > #pattern "" param "" > #pattern "" "" "" > #don't look for declarations, if we already have declarations > if {${imp_def} == "imp"} { > lappend scopes {fu mi} > if {! ${have_declaration}} { > lappend scopes {fd md fr} > } > } else { > lappend scopes {fd md fr} > #exclude implementations as like the scopes "fd md fr" > set rest "" > foreach s ${sn_scopes} { > if {[lsearch \ > -exact {fu mi fd md fr} ${s}] == -1} { > lappend rest ${s} > } > } > if {${rest} != ""} { > lappend scopes ${rest} > } > } > foreach scopegrp ${scopes} { > lappend looking_list [list ${file} ${scopegrp} ${prm} ${type}] > lappend looking_list [list ${file} ${scopegrp} ${prm} ""] > lappend looking_list [list "" ${scopegrp} ${prm} ${type}] > lappend looking_list [list "" ${scopegrp} ${prm} ""] > lappend looking_list [list "" ${scopegrp} "" ""] > } > > #find first "mi fu", if nothing is found try to find declaration > #look first in the same file, when nothing is found, try to find > #in all files > foreach l ${looking_list} { > set file [lindex ${l} 0] > set scopes [lindex ${l} 1] > set prm [lindex ${l} 2] > set type [lindex ${l} 3] > > #make sure that a fetch hasn't been done twice > if {[info exists > looking_arr(${file},${scopes},${prm},${type})]} { > continue > } > set looking_arr(${file},${scopes},${prm},${type}) 1 > > #1. find implementation by accepting types and parameters > set ret [sn_retrieve_symbol ${string} ${scopes} ${file} \ > -exact 1 0 ${cmd} "" ${type} ${prm}] > > #if something found, break the selection > if {${ret}} { > break > } > } > catch {unset looking_list} > catch {unset looking_arr} > } > > method RetrieveObject {} { > global sn_options Parser_Info > set case -1 > set file $itk_option(-filename) > if {${file} != $sn_options(noname_file)} { > set type [file_type_using_suf [file extension ${file}]] > set case $Parser_Info(${type},CASE) > } > if {[catch {set name [selection get]}]} { > set name "" > } > set name [string trim ${name}] > if {${name} == ""} { > sn_error_dialog [get_indep String NoSelection] [get_indep > String \ > MultiRetriever] > return > } > > if {!${case}} { > set name [string toupper ${name}] > } > sn_retrieve_symbol [list ${name}] all "" \ > -exact 1 1 > } > > #this function set the color for the different symbols > #displayed in the editor > proc init_tags {t} { > global sn_options > global combobox_editor_scopes > > if {$sn_options(iscolor)} { > #init symbol colors > set sc [::lunique [lsort [eval concat [array get \ > combobox_editor_scopes]]]] > foreach tg "key ${sc}" { > catch {${t} tag configure ${tg} \ > -foreground $sn_options(def,color_${tg})} > } > if {$sn_options(def,edit-xref-highlight)} { > catch {${t} tag configure "xref_g" \ > -foreground orange} > catch {${t} tag configure "xref_u" \ > -foreground green} > catch {${t} tag configure "xref_l" \ > -foreground "cornflower blue"} > } > > ${t} tag configure rem \ > -foreground $sn_options(def,color_rem) > ${t} tag configure str \ > -foreground $sn_options(def,color_str) > ${t} tag configure bracket \ > -background $sn_options(def,bracketmatch-bg) \ > -foreground white > > catch {${t} tag raise mi md} > } else { > ${t} tag configure bracket \ > -background black \ > -foreground white > } > ${t} tag configure grep \ > -foreground white \ > -background black > } > > method color_file {{run_parse 1}} { > if {${highlight}} { > UpdateHighlights ${run_parse} > > #read symbols from DB > set file_syms [get_file_symbols $itk_option(-filename)] > > #create tags for the found symbols in the editor > sn_db_create_symbol_tags $itk_component(editor) ${file_syms} > "in iu lv" > > #mark actual tag and display found tags into > #the combobox > GetFileTags 0 ${file_syms} > } > } > > # This file is called, when ever a file must be edited. > method editfile {f {line ""} {revert ""} {run_parse 1}} { > global sn_options > global SyncEditors_Disabled > > # Check we haven't been called before creation. > if {![info exists itk_component(editor)] \ > || ![winfo exists $itk_component(editor)]} { > return > } > > if {${f} == ""} { > return 0 > } > > # Verify if the momentan file is modified. > if {${revert} != "revert" && [Ask_For_Modified revert] == 0} { > return 0 > } > > # We should never be asked to edit a directory. > if {[file isdirectory ${f}]} { > error "editfile method called for a directory \"${f}\"" > } > > # Test if file exists and readable, returns if > # file doesn't exist. > if {${f} != $sn_options(noname_file) &&(! [file exists ${f}] || ! \ > [file readable ${f}])} { > return 0 > } > > # Parse file to see if we could add it into the project. > if {[file exists ${f}]} { > # Make sure that we want to refresh a file before > # editing it. This could be a slow mechanism, when somebody > # wants to work only with "Fast Save" (without refreshing). > if {$sn_options(def,auto-reparse)} { > if {! [sn_parse_uptodate [list ${f}] 0]} { > return 0 > } > } > } > > 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|gnudoit)" ${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 {${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 multiple 0 > 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} > } > "-multiple" { > set multiple ${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 > set f [tkFDialog open \ > -parent ${w} \ > -title ${title} \ > -initialdir ${initialdir} \ > -defaultextension ${defaultextension} \ > -filetypes ${types} \ > -multiple ${multiple} \ > -initialfile ${initialfile}] > } else { > set f [tk_getOpenFile \ > -parent ${w} \ > -title ${title} \ > -initialdir ${initialdir} \ > -defaultextension ${defaultextension} \ > -filetypes ${types} \ > -multiple ${multiple} \ > -initialfile ${initialfile}] > } > } else { > if {$tcl_platform(platform) == "unix"} { > #don't call motif dialog box > 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} != ""} { > if {${multiple}} { > set ff [lindex ${f} 0] > } else { > set ff ${f} > } > catch {set last_accessed_dir [file dirname ${ff}]} > } > > if {${f} != "" && ${script} != ""} { > ::eval ${script} [list ${f}] > } > #always return used file name > return ${f} > } > > #choose a directory > proc DirDialog {w args} { > global sn_options > global tcl_platform > > #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 initialdir "" > set prefix "file_dialog" > 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} > } > "-initialdir" - > "-dir" { > set initialdir ${val} > } > default { > bell > return > } > } > } > > if {${title} == ""} { > set title [get_indep String SelectDirectory] > } > > if {${initialdir} == "" || ${initialdir} == "."} { > set initialdir ${last_accessed_dir} > } > > if {$tcl_platform(platform) == "windows"} { > # ide_get_directory doesn't like a leading :: in the > # window name, so we remove it if any. > set w [namespace tail $w] > set dir [ide_get_directory \ > -initialdir ${initialdir} \ > -parent ${w} \ > -title ${title}] > #store last accessed directory > if {${dir} != ""} { > set last_accessed_dir ${dir} > } > > if {${dir} != "" && ${script} != ""} { > ::eval ${script} [list ${dir}] > return "" > } else { > return ${dir} > } > } else { ># FIXME: What is this -script option doing here? > set obj [sourcenav::DirDialog ${w}.dirdialog \ > -title ${title} \ > -script ${script} \ > -initialdir ${initialdir}] > > set dir [${obj} activate] > itcl::delete object ${obj} > if {${dir} != ""} { > set last_accessed_dir ${dir} > } > if {${dir} != "" && ${script} != ""} { > eval ${script} [list ${dir}] > return "" > } else { > return ${dir} > } > } > } > > method open_file_cb {file} { > global sn_options > global prj_lines_num > > #make sure we stay in project directory (different interpeters). > catch {cd $sn_options(sys,project-dir)} > > #it can happen, that the open-dialog has changed the > #current working directory. > catch {cd $sn_options(sys,project-dir)} > > if {![file exists ${file}]} { > sn_error_dialog "[get_indep String FileNotExist]: ${file}" \ > [get_indep String FileNotExist] > } else { > catch {set file [sn_convert_FileName ${file}]} > editfile ${file} \ > -1 revert > #remove selection, somehow the text widget have strange behavior > #after calling the file dialog > $itk_component(editor) tag remove sel 0.0 end > } > focus $itk_component(editor) > } > > method open_file {} { > global sn_options > if {[Ask_For_Modified open] == 0} { > return 0 > } > set ret [FileDialog ${this} \ > -title [get_indep String Open] \ > -script [list ${this} open_file_cb] \ > -prefix open_file] > return 1 > } > > method saveas_file_cb {fast file} { > set file [sn_convert_FileName ${file}] > set xref [sn_processes_running] > > #Save file as a file, that not exist in the project > #when xref is running (fastsave only) > if {${xref} && ${fast} == 0} { > #focus $editor > set answer [tk_dialog auto [get_indep String > SaveAsFastSaveTitle] \ > "[get_indep String XRefIsRunning]\n[get_indep String \ > SaveAsFastSave]\n${file} ?" question_image 0 [get_indep > String \ > FastSave] [get_indep String Cancel]] > if {${answer} != 0} { > return 0 > } > set fast 1 > } > > return [save_file ${fast} ${file}] > } > > # Save As ... > method saveas_file {{fast 0} {file ""}} { > global sn_options > > #noname has to be replaced with blank > if {${file} == $sn_options(noname_file)} { > set file "" > } > if {${file} != ""} { > set initialdir [file dirname ${file}] > set file [file tail ${file}] > } else { > set initialdir "" > } > set ret [FileDialog ${this} \ > -title [get_indep String EditSaveFileAs] \ > -script [list ${this} saveas_file_cb ${fast}] \ > -prefix saveas_file \ > -save_open save \ > -initialdir ${initialdir} \ > -initialfile ${file}] > if {${ret} == ""} { > return 0 > } else { > return 1 > } > } > > # Quick Save > method fastsave_file {} { > return [save_file 1] > } > > method revert_file {{mode ""} {ignore_obj ""}} { > global SyncEditors_Disabled > > if {${mode} != "revert"} { > if {[sn_processes_running]} { > bell > return > } > set answer [Ask_For_Revert revert] > } else { > set answer 0 > } > > #reopen file > # > #Actualy we must revert all the editors with the > #same file name > if {${answer} != 0} { > return > } > incr SyncEditors_Disabled > foreach cls [itcl_info objects "*" \ > -class Editor&] { > if {[lsearch \ > -exact ${ignore_obj} ${cls}] != -1} { > continue > } > if {[${cls} cget -filename] == $itk_option(-filename)} { > set ed [${cls} editor] > ${cls} editfile $itk_option(-filename) "" revert > catch {${ed} see lastpos} > ${ed} mark set insert lastpos > ${cls} find_and_mark_tag > } > } > incr SyncEditors_Disabled -1 > } > > # Save the contents of a specified text widget into a specified file > # The previous contents of the file is saved to a ".bak" file before > being > # overwritten > method save_file {{fast 0} {file ""}} { > global sn_options > > #make sure we stay in project directory (different interpeters). > catch {cd $sn_options(sys,project-dir)} > > if {${file} != ""} { > set ff ${file} > } else { > set ff $itk_option(-filename) > } > > #no filename is specified > if {${ff} == $sn_options(noname_file)} { > return [saveas_file ${fast}] > } > > #file isn't modified > if {${ff} == $itk_option(-filename) && !$itk_option(-file_changed)} { > return 1 > } > > #xref is running, only fastsave is possible > #if edit mode disabled, no save possible > if {!${fast} && [sn_processes_running] || $sn_options(readonly)} { > bell > return 0 > } > > #test if the file has been modified external > if {[file exists ${ff}] && ${file_mtime} != 0 && ${file_mtime} != \ > [file mtime ${ff}]} { > set answer [tk_dialog auto [get_indep String \ > FileModifiedOutsideTitle] "[format [get_indep String \ > FileModifiedOutside] ${ff}]" question_image 0 [get_indep > String \ > Overwrite] [get_indep String Cancel]] > if {${answer} != 0} { > return 0 > } > } > > if {[sn_save_file $itk_component(editor) ${ff}] == 0} { > return 0 > } > > set file_mtime [file mtime ${ff}] > #file isn't modified now. > $this configure -file_changed 0 > > #refresh filename (needed by save-as) > if {${ff} != $itk_option(-filename)} { > set filename ${ff} > } > > #recolor file, after storing the new file name > if {!${fast}} { > color_file > } > > #That's meen that it is possible that the file is > #already availiable in other buffer and now has > #been overridden, revert those files > set allobj [itcl_info objects "*" \ > -class Editor&] > foreach other ${allobj} { > if {${other} == ${this} || [${other} cget -filename] != ${ff}} { > continue > } > set i [lsearch \ > -exact ${allobj} ${other}] > set ign_obj [lreplace ${allobj} ${i} ${i}] > if {!${fast}} { > ${other} revert_file "revert" ${ign_obj} > } else { > ${other} setmodified 0 > } > #update modification date for all other edit views > #with the dame file name > ${other} config \ > -file_mtime ${file_mtime} > ${other} DispModified > ${other} SetTitle > } > > # Important ! > set tkText($itk_component(editor),prevCmd) {} > > #actualize the reuse-checkbutton and the title > #to reset the changed flag > DispModified > SetTitle > > return 1 > } > > proc SaveAll {} { > catch {unset files} > #first fast save all files > foreach ed [itcl_info objects "*" \ > -class Editor&] { > if {[${ed} cget -file_changed]} { > ${ed} fastsave_file > set files([${ed} cget -filename]) 1 > } > } > catch {unset files} > } > > method insert_file_cb {f} { > global sn_options > > if {![file exists ${f}]} { > sn_error_dialog "[get_indep String FileNotExist]: ${f}" \ > [get_indep String FileNotExist] > return 0 > } > > #open file > if {[catch {set f [open ${f} r]} msg]} { > sn_error_dialog "${msg} ${f}" > return 0 > } else { > fconfigure ${f} \ > -encoding $sn_options(def,encoding) \ > -blocking 0 > } > > #insert text into editor > if {![catch {$itk_component(editor) get sel.first sel.last}]} { > set fpos [$itk_component(editor) index sel.first] > tkTextReplace $itk_component(editor) [$itk_component(editor) > index sel.first] \ > [$itk_component(editor) index sel.last] [read \ > -nonewline ${f}] > } else { > set fpos [$itk_component(editor) index insert] > tkTextInsert $itk_component(editor) insert [read \ > -nonewline ${f}] > } > close ${f} > > #sometimes there is a wrong selected block, delete it > set epos [$itk_component(editor) index insert] > $itk_component(editor) tag del sel > #mark new inserted text > $itk_component(editor) tag add sel ${fpos} ${epos} > > #see last inserted character > $itk_component(editor) see insert > > return 1 > } > > method insert_file {} { > set ret [FileDialog ${this} \ > -title [get_indep String EditInsertFile] \ > -script [list ${this} insert_file_cb] \ > -prefix insert_file] > if {${ret} == ""} { > return 0 > } else { > return 1 > } > } > > #find a window with specified filename > proc find_window_with_file {file {state "normal"}} { > foreach win [itcl_info objects "*" -class MultiWindow&] { > set ed [${win} editor] > set ew [${win} editw] > if {${ed} == "" || ${ew} == ""} { > continue > } > if {[${ed} cget -filename] == ${file} && [${ew} cget -state] > == ${state}} { > return ${win} > } > } > return "" > } > > method SetFondPos {pos {center 0} {find_mark 1} {select 1}} { > global sn_options > global sn_all_scopes > > if {${pos} == ""} { > set pos [$itk_component(editor) index insert] > set select 0 > } > > if {$sn_options(def,edit-mark-current-position) == 0} { > set mrk 0 > } else { > set mrk 1 > } > > set w $itk_component(editor) > > ${w} mark set lastpos insert > > set poi_sn [string first "." ${pos}] > > set pos [trim_text_index \ > -digit ${pos}] > > if {${pos} == ""} { > bell \ > -displayof ${w} > return > } > > #cut integer value to be max. 8 digits > set line [lindex [split ${pos} .] 0] > if {[string length ${line}] > 8} { > set pos "[string range ${line} 0 8].[lindex [split ${pos} .] 1]" > } > > ${w} mark set insert ${pos} > ${w} mark set anchor insert > ${w} tag remove sel 0.0 end > if {${select}} { > if {${poi_sn} == -1} { > #mark or goto first character > if {${mrk}} { > ${w} tag add sel "insert linestart" "insert lineend + 1c" > } else { > #goto line, move the insert cursor to first printable > #character in the line > set txt [${w} get "insert linestart" "insert lineend"] > set txt1 [string trim ${txt}] > if {${txt} != ${txt1}} { > set i [string first [string range ${txt1} 0 0] > ${txt}] > if {${i} > 0} { > ${w} mark set insert "${pos} +${i}c" > ${w} mark set anchor insert > } > } > } > } else { > set fnd 0 > foreach nm [${w} tag names insert] { > if {[lsearch \ > -exact ${sn_all_scopes} ${nm}] != -1} { > set fnd 1 > set rng [${w} tag prevrange ${nm} "insert+1c"] > if {${mrk}} { > eval ${w} tag add sel ${rng} > } > break > } > } > > if {${mrk} && !${fnd}} { > ${w} tag add sel "insert wordstart" "insert wordend" > } > } > } > > if {${center}} { > set pos [expr int(${line} - [text_page_num_lines ${w}] / 2) - 1] > if {${pos} < 0} { > set pos 0 > } > ${w} yview ${pos} > } else { > ${w} see ${pos} > } > > if {${pos} > 1} { > find_and_mark_tag > } > > focus $itk_component(editor) > } > > method addselection {pos ranges} { > eval $itk_component(editor) tag add sel ${pos} ${ranges} > $itk_component(editor) mark set lastpos insert > $itk_component(editor) mark set insert ${pos} > $itk_component(editor) see insert > } > > method DispModified {} { > if {[winfo exists $itk_option(-mesg_area).reuse]} { > if {$itk_option(-file_changed)} { > $itk_option(-mesg_area).reuse config \ > -state disabled > } else { > $itk_option(-mesg_area).reuse config \ > -state normal > } > } > } > > #Find an editor with a specified file name > proc find_Editor_with_File {file {except ""}} { > foreach cls [itcl_info objects "*" \ > -class Editor&] { > if {${cls} != ${except} && ${file} == [${cls} cget -filename]} { > return ${cls} > } > } > return "" > } > > method Ask_For_Revert {reason} { > global sn_options > > #we can revert the buffer, when there is another > #editor with the same file name > if {${reason} != "revert" && $itk_option(-file_changed) && > $itk_option(-filename) != \ > $sn_options(noname_file) && [find_Editor_with_File > $itk_option(-filename) \ > ${this}] != ""} { > return 0 > } > if {$itk_option(-file_changed)} { > > if {$itk_option(-filename) == $sn_options(noname_file)} { > set file "Buffer" > } else { > set file $itk_option(-filename) > } > > switch ${reason} { > "new" { > set txt [get_indep String HasBeenModified] > set title [get_indep String EditNewFile] > set ok [get_indep String NewFile] > } > "open" { > set txt [get_indep String HasBeenModified] > set title [get_indep String OpenFile] > set ok [get_indep String Open] > } > "revert" { > set txt [get_indep String HasBeenModified] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > "another" { > set txt [get_indep String OpenNewBuffer] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > default { > set txt [get_indep String HasBeenModified] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > } > > focus $itk_component(editor) > set answer [tk_dialog auto ${title} "${file} ${txt}" \ > question_image 0 ${ok} [get_indep String Cancel]] > } else { > #file not modified > set answer 0 > } > return ${answer} > } > > method Ask_For_Modified {reason} { > global sn_options > > #we can revert the buffer, when there is another > #editor with the same file name > if {${reason} != "revert" && $itk_option(-file_changed) && > $itk_option(-filename) != \ > $sn_options(noname_file) && [find_Editor_with_File > $itk_option(-filename) \ > ${this}] != ""} { > return 1 > } > if {$itk_option(-file_changed)} { > > if {$itk_option(-filename) == $sn_options(noname_file)} { > set file "Buffer" > } else { > set file $itk_option(-filename) > } > > switch ${reason} { > "new" { > set txt [get_indep String HasBeenModified] > set title [get_indep String EditNewFile] > set ok [get_indep String NewFile] > } > "open" { > set txt [get_indep String HasBeenModified] > set title [get_indep String OpenFile] > set ok [get_indep String Open] > } > "revert" { > set txt [get_indep String HasBeenModified] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > "another" { > set txt [get_indep String OpenNewBuffer] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > default { > set txt [get_indep String HasBeenModified] > set title [get_indep String RevertFile] > set ok [get_indep String Revert] > } > } > > #Is Auto-Save enabled > if {$sn_options(def,auto-save)} { > set answer 1 > } else { > focus $itk_component(editor) > set answer [tk_dialog auto ${title} "${file} ${txt}" \ > question_image 0 [get_indep String Save] [get_indep > String \ > EditFastSave] [get_indep String DonotSave] \ > [get_indep String Cancel]] > } > switch -- ${answer} { > 0 { > #save > return [save_file] > } > 1 { > #fast save > return [fastsave_file] > } > 2 { > #don't save (revert) > #don't save file > return 1 > } > default { > #cancel > return 0 > } > } > } else { > #file not modified > return 1 > } > } > > method Title {{full 1}} { > global sn_options > > set tf [file tail $itk_option(-filename)] > if {$itk_option(-file_changed)} { > set tf "** ${tf} **" > } > if {[$itk_component(editor) cget -state] != "normal"} { > append tf " [get_indep String FileViewOnly]" > } \ > elseif {[file exists $itk_option(-filename)] && ![file writable > $itk_option(-filename)]} { > append tf " [get_indep String TitleReadOnly]" > } > if {${full}} { > return [sn_title ${tf}] > } else { > return ${tf} > } > } > method Icon {} { > if {$itk_option(-file_changed)} { > return [sn_view_icon "" "** [file tail > $itk_option(-filename)] **"] > } else { > return [sn_view_icon [file tail $itk_option(-filename)]] > } > } > method SetTitle {} { > global sn_options sn_root > > #toplevel window > set win [winfo toplevel $itk_component(editor)] > > wm title ${win} [Title] > wm iconname ${win} [Icon] > set lines 0 > scan [$itk_component(editor) index "end-1c"] %d lines > > set nm [file join $sn_options(sys,project-dir) > $itk_option(-filename)] > > #display the file name in native OS conditions > set nm [file nativename ${nm}] > > set $itk_option(-message_var) "$nm: $lines [get_indep String Lines]" > } > > proc is_fileModified {file} { > #we must accept that by creating a file in an empty project > #paf_db_f is not defined. > if {[::info commands paf_db_f] == ""} { > return 0 > } > > #this happens when neu file is being edited! > if {![file exists ${file}]} { > return 0 > } > > #compare stored and actual file status > set filestatus [paf_db_f get \ > -key -col [list 0 1 2] ${file}] > file stat ${file} st > > #modify time changed? > if {[lindex ${filestatus} 1] != $st(mtime)} { > return 1 > } > return 0 > } > > method UpdateHighlights {{run_parse 1}} { > global sn_options > global env > global sn_debug > global $itk_component(editor)-group > upvar #0 $itk_component(editor)-group grp > > if {! [file exists $itk_option(-filename)]} { > return > } > > #maybe the file is not availiable in the project > if {${run_parse}} { > if {$sn_options(def,auto-reparse)} { > if {![sn_parse_uptodate [list $itk_option(-filename)] 0]} { > return > } > } > } > > if {[::info commands paf_db_f] != ""} { > set highfile [paf_db_f get \ > -key -col {0 2} $itk_option(-filename)] > } else { > set highfile "" > } > > set grp [lindex ${highfile} 0] > > if {[lsearch \ > -exact $sn_options(sys,builtin-highlighting) ${grp}] != -1} { > global sn_text_highlight_group > ::set sn_text_highlight_group($itk_component(editor)) ${grp} > > sn_log "Highlighting -delall \"$itk_option(-filename)\", > group \"${grp}\"" > > Sn_Syntax_Highlight \ > -delall ${grp} $itk_component(editor) 1.0 end > return > } > > set highfile [lindex ${highfile} 1] > > #verify if the file is modified (modified status) > set mod [is_fileModified $itk_option(-filename)] > > if {!${mod} && ${highfile} != "" && [file exists ${highfile}]} { > sn_log "Highlighting \"$itk_option(-filename)\": ${highfile}" > if {[catch {Sn_Highlight_Text $itk_component(editor) > ${highfile}} err]} { > bgerror ${err} > } > if {$sn_options(def,edit-xref-highlight)} { > catch {Sn_Highlight_Text $itk_component(editor) > $itk_option(-filename).HIGH} > } > return > } > > set highcmd [sn_highlight_browser $itk_option(-filename) "h"] > if {${highcmd} == ""} { > sn_log "Empty highlighter command for \"$itk_option(-filename)\"" > return > } > > set outf [sn_tmpFileName] > lappend highcmd \ > -s ${outf} > > if {!${mod}} { > lappend highcmd \ > -n $sn_options(db_files_prefix) $itk_option(-filename) > } > > sn_log "Highlighter: ${highcmd}" > > if {${mod}} { > $itk_component(editor) tag remove key 1.0 end > $itk_component(editor) tag remove rem 1.0 end > if {[catch {eval exec \ > -- ${highcmd} << {[$editor get 1.0 end]}} err]} { > bgerror ${err} > return > } > } else { > if {[catch {eval exec \ > -- ${highcmd}} err]} { > bgerror ${err} > return > } > } > > if {!${mod}} { > set highfile [paf_db_f get \ > -key -col [list 2] $itk_option(-filename)] > } else { > set highfile ${outf} > } > > # It might happen, that the highlighting filename could > # not be inserted into thet database. > if {${highfile} == ""} { > set fd [open ${outf}] > fconfigure ${fd} \ > -encoding $sn_options(def,system-encoding) \ > -blocking 0 > set highfile [gets ${fd}] > close ${fd} > # Lets mark it for delete. > lappend outf ${highfile} > } > > sn_log "Loading: ${highfile}" > > if {${highfile} != ""} { > if {[catch {Sn_Highlight_Text $itk_component(editor) > ${highfile}} err]} { > bgerror ${err} > } > } > > if {$sn_options(def,edit-xref-highlight)} { > catch {Sn_Highlight_Text $itk_component(editor) > $itk_option(-filename).HIGH} > } > > if {[info exists env(TMP)] && [file dirname ${highfile}] != > $env(TMP)} { > lappend outf ${highfile} > } > > if {!${sn_debug}} { > file delete \ > -- ${outf} > } > } > > #all == -1: disable all filter flags > #all == 1: enable all filter flags > #all == 0: current state of filter flags > private method read_filetags {{all 0} {file_cont ""}} { > global sn_options sn_sep combobox_editor_scopes > > if {$itk_option(-symbols) == ""} { > error "read_filetags should not be called with a symbol combo" > } > > #we do have new symbols in the combo box, make sure that > #this symbols are drawn when pulldown the combo box > set displayed 0 > > if {$itk_option(-symbols_filter) != ""} { > upvar #0 $itk_option(-symbols_filter)-related related > set qry "" > foreach s [array names combobox_editor_scopes] { > upvar #0 $itk_option(-symbols_filter)-${s} value > if {${all} == -1} { > uplevel #0 "set $itk_option(-symbols_filter)-${s} off" > continue > } > if {${all} ||([info exists value] && ${value} != "off")} { > foreach db $combobox_editor_scopes(${s}) { > if {[::info commands paf_db_${db}] != ""} { > uplevel #0 "set > $itk_option(-symbols_filter)-${s} \ > ${s}" > lappend qry ${db} > } > } > } > } > } else { > set qry "" > set related 1 > } > > if {${qry} == ""} { > return "" > } > > if {${related}} { > #read only the symbols for the edited file > # Class,symbol,type,position. > if {${file_cont} != ""} { > #set qry ".+ \([join $qry "|"]\) .*" > set qry ".+${sn_sep}\([join ${qry} "|"]\)${sn_sep}.*" > #calls a C/function > return [sn_db_format_qry [lmatch \ > -regexp ${file_cont} ${qry}]] > } else { > #set qry ".+ \([join $qry "|"]\)\$" > set qry ".+${sn_sep}\([join ${qry} "|"]\)\$" > if {[::info commands paf_db_fil] != ""} { > set syms [paf_db_fil seq \ > -data -col {2 3 4 1} \ > -regexp ${qry} "$itk_option(-filename)${sn_sep}"] > #calls a C/function > return [sn_db_format_qry ${syms}] > } else { > return "" > } > } > } else { > #read all symbols of all files > set combo [string range $itk_option(-symbols) 0 [expr \ > [string last "." $itk_option(-symbols)] - 1]] > set syms "" > #set qry ".+ \([join $qry "|"]\)\$" > set qry ".+${sn_sep}\([join ${qry} "|"]\)\$" > catch { > set syms [paf_db_fil seq \ > -data -regexp ${qry} \ > -col {2 3 4 1}] > } > return [sn_db_format_qry ${syms}] > } > } > > method GetFileTags {all {file_cont ""}} { > #add symbols into combobox for symbol list > #only if the related flag is setted > upvar #0 $itk_option(-symbols_filter)-related related > > if {$itk_option(-symbols) != "" && ${related}} { > $itk_option(-symbols) configure -contents [read_filetags > ${all} ${file_cont}] > } > > #find the actual tag (symbol), mark it and view > #it in the combo box > find_and_mark_tag > } > > method find_tag {{pos ""}} { > global sn_options sn_sep > if {${pos} == ""} { > if {[catch {set idx [$itk_component(editor) index {insert > wordstart}]}]} { > return > } > } else { > set idx ${pos} > } > > set tag [lindex [lmatch [$itk_component(editor) tag names ${idx}] > "* *"] end] > if {${tag} == "" || [lindex ${tag} end] == "cl"} { > set sec_idx [$itk_component(editor) index "${idx} lineend -1c > wordstart"] > set sec_tag [lindex [lmatch [$itk_component(editor) tag names > ${sec_idx}] \ > "* *"] end] > > if {${sec_tag} == ""} { > if {${tag} == ""} { > $itk_component(editor) mark unset %beg% %end% > return > } > } else { > set tag ${sec_tag} > set idx ${sec_idx} > } > } > > set beg 0.0 > set end 0.0 > set ranges [$itk_component(editor) tag ranges ${tag}] > for {set off 0; set max [expr [llength ${ranges}] / 2]} {${off} < \ > ${max}} {incr off} { > set v [expr ${off} * 2] > set beg [lindex ${ranges} ${v}] > set end [lindex ${ranges} [expr ${v} + 1]] > if {[$itk_component(editor) compare ${beg} <= ${idx}] && > [$itk_component(editor) compare \ > ${end} >= ${idx}]} { > break > } > } > > if {[lindex ${tag} end] != "cl"} { > $itk_component(editor) mark set %beg% ${beg} > $itk_component(editor) mark set %end% ${end} > } else { > $itk_component(editor) mark unset %beg% %end% > } > > return [tag_with_sep ${tag}] > } > method find_offset {} { > if {[catch {set idx [$itk_component(editor) index {insert > wordstart}]}]} { > return 0 > } > > set tag [lindex [lmatch [$itk_component(editor) tag names ${idx}] > "* *"] end] > if {${tag} == "" || [lindex ${tag} end] == "cl"} { > set sec_idx [$itk_component(editor) index "${idx} lineend -1c > wordstart"] > set sec_tag [lindex [lmatch [$itk_component(editor) tag names > ${sec_idx}] \ > "* *"] end] > > if {${sec_tag} == ""} { > if {${tag} == ""} { > return 0 > } > } else { > set tag ${sec_tag} > set idx ${sec_idx} > } > } > > set beg 0.0 > set end 0.0 > set ranges [$itk_component(editor) tag ranges ${tag}] > for {set off 0; set max [expr [llength ${ranges}] / 2]} {${off} < \ > ${max}} {incr off} { > set v [expr ${off} * 2] > set beg [lindex ${ranges} ${v}] > set end [lindex ${ranges} [expr ${v} + 1]] > if {[$itk_component(editor) compare ${beg} <= ${idx}] && > [$itk_component(editor) compare \ > ${end} >= ${idx}]} { > return ${off} > } > } > return 0 > } > > proc tag_with_sep {tag} { > global sn_sep > if {[llength ${tag}] < 3} { > set tag "# ${tag}" > } > #set tag [join $tag $sn_sep] > return [sn_db_format_qry [list ${tag}]] > } > > method find_and_mark_tag {} { > global sn_options sn_sep sn_scopes > if {[catch {set idx [$itk_component(editor) index {insert > wordstart}]}]} { > return > } > > set $itk_option(-linenumber_var) [$itk_component(editor) index > insert] > > if {$itk_option(-symbols) != ""} { > $itk_option(-symbols) configure -entrytext "" > } > > #verify if we stay on a symbol declaration/implementaion > set pos_tags "" > foreach tg [$itk_component(editor) tag names ${idx}] { > if {[string first " " ${tg}] != -1} { > #tags like "symbol scope" > lappend pos_tags ${tg} > } > } > > set tag [lindex ${pos_tags} end] > if {${tag} == "" || [lindex ${tag} end] == "cl"} { > set sec_idx [$itk_component(editor) index "${idx} lineend -1c > wordstart"] > set sec_tag [lindex [lmatch [$itk_component(editor) tag names > ${sec_idx}] \ > "* *"] end] > > if {${sec_tag} == ""} { > if {${tag} == ""} { > $itk_component(editor) mark unset %beg% %end% > return > } > } else { > set tag ${sec_tag} > set idx ${sec_idx} > } > } > > set beg 0.0 > set end 0.0 > set ranges [$itk_component(editor) tag ranges ${tag}] > for {set off 0; set max [expr [llength ${ranges}] / 2]} {${off} < \ > ${max}} {incr off} { > set v [expr ${off} * 2] > set beg [lindex ${ranges} ${v}] > set end [lindex ${ranges} [expr ${v} + 1]] > if {[$itk_component(editor) compare ${beg} <= ${idx}] && > [$itk_component(editor) compare \ > ${end} >= ${idx}]} { > break > } > } > > if {[lindex ${tag} end] != "cl"} { > $itk_component(editor) mark set %beg% ${beg} > $itk_component(editor) mark set %end% ${end} > } else { > $itk_component(editor) mark unset %beg% %end% > } > > set tg [tag_with_sep ${tag}] > > if {$itk_option(-symbols) != ""} { > $itk_option(-symbols) selecttext [join ${tg}] ${off} > } > > upvar #0 ${this}-off old_off > > if {${tg} == ${old_tg} && ${old_off} == ${off}} { > return > } > > set old_tg ${tg} > set old_off ${off} > > #execute selectcommand, when the tag is changed > if {$itk_option(-selectcommand) != ""} { > split_symbol ${tg} cls sym scope > set line [$itk_component(editor) index insert] > #::eval $selectcommand [list $scope $sym $cls $filename $line > "" \ > "" ""] > ::eval $itk_option(-selectcommand) [Selection] > } > } > > # > # Indent/Outdent the selected area (or the current line) of the file. > # > proc Indent {cls indent} { > global sn_options > global tkPriv > global sn_text_highlight_group > > set editor [${cls} editor] > set pos [$editor index @0,0] > > if {[catch {set beg [$editor index "sel.first linestart"]}]} { > set beg [$editor index "insert linestart"] > set end [$editor index "insert lineend"] > } else { > #avoid to include an extra line by getting the index > #this can happen, when the selection is make to the > #end of line > set last_line_col [lindex [split [$editor index sel.last] \ > "."] end] > if {${last_line_col} == "0"} { > ::set tkPriv(selectMode) "line" > set end [$editor index "sel.last -1c"] > } else { > set end [$editor index "sel.last lineend"] > } > } > > if {[info exists sn_text_highlight_group($editor)]} { > set group $sn_text_highlight_group($editor) > } else { > set group "" > } > upvar #0 ${cls}-indenting_broken indenting_broken > set indenting_broken 0 > > #execute SN-internal indent/outdent procedure > set txt [$editor get ${beg} ${end}] > set newtxt [sn_indent_outdent \ > -indent ${indent} \ > -indentwidth $sn_options(def,edit-indentwidth) \ > -tabwidth $sn_options(def,edit-tabstop) \ > -replacetabs $sn_options(def,edit-tab-inserts-spaces) \ > -group ${group} ${txt}] > > #nothing changed, return! > if {${indenting_broken} || [string compare ${newtxt} ${txt}] == 0} { > return > } > > #replace with reworked text > tkTextReplace $editor ${beg} ${end} ${newtxt} > > #eventually reparse a fast-saved file > #$cls UpdateHighlights > > #reset some tags > $editor tag remove sel 0.0 end > $editor tag add sel ${beg} "${end} lineend + 1c" > set ypos [expr [lindex [split ${pos} "."] 0] - 1] > $editor yview ${ypos} > > #that's all folk > return > } > > method print {} { > global tcl_platform > if {$tcl_platform(platform) != "windows"} { > print_dialog $itk_component(editor) > } else { > ide_print_text $itk_component(editor) > } > } > > proc print_file {print_dialog t} { > global tcl_platform sn_options > > upvar #0 ${print_dialog}-ptarget target > switch -- ${target} { > "marked" { > if {[catch {set lst [${t} get sel.first sel.last]} err]} { > #no selection? > sn_error_dialog ${err} > return > } > } > "view" { > set end [${t} index @0,[winfo height ${t}]] > set lst [${t} get @0,0 "${end} lineend"] > } > "all" - > default { > set lst [${t} get 0.0 end] > } > } > > if {${print_dialog} != ""} { > itcl::delete object ${print_dialog} > } > > #we have to translate \t to the current size number of tabs > #this have to be done always, because the pr command on unix > #makes also indenting at the beginning of line, so that the > #first tab could be wrong displayed > set tabsize [${t} cget -tabsize] > #at lease one space > set spaces " " > for {set i 1} {${i} < ${tabsize}} {incr i} { > append spaces " " > } > regsub \ > -all \t ${lst} ${spaces} lst > > #write contents into file > set tmpf [sn_tmpFileName] > set fd [open ${tmpf} "w+"] > fconfigure ${fd} \ > -encoding $sn_options(def,system-encoding) \ > -blocking 0 > puts ${fd} ${lst} > close ${fd} > > if {$tcl_platform(platform) != "windows"} { > upvar #0 ${print_dialog}-cmd cmd > } else { > set cmd ide_winprint > } > > sn_print_file ${cmd} ${tmpf} > > catch {file delete \ > -- ${tmpf}} > catch {unset target} > catch {unset cmd} > } > > proc print_dialog {t} { > global sn_options > global tcl_platform > > set print_dialog "[winfo toplevel ${t}].printdlg" > > if {$tcl_platform(platform) == "windows"} { > upvar #0 ${print_dialog}-ptarget target > > #default print all when no selection > ::set target "all" > > #if selection availiable ask to print selection only > if {! [catch {set lst [${t} get sel.first sel.last]}] && ${lst} \ > != ""} { > set answer [tk_dialog auto [get_indep String Print] \ > [get_indep String PrintSelection] question_image 0 \ > [get_indep String All] [get_indep String Marked] \ > [get_indep String Cancel]] > if {${answer} == 2} { > return > } > if {${answer} == 1} { > ::set target "marked" > } > } > Editor&::print_file ${print_dialog} ${t} > return > } > > if {[winfo exists ${print_dialog}]} { > ${print_dialog} raise > return > } > set topl [winfo toplevel ${t}] > set print_dialog [sourcenav::Window ${print_dialog} \ > -leader ${t}] > > sn_motif_buttons ${print_dialog} bottom 0 [get_indep String ok] \ > [get_indep String cancel] > ${print_dialog}.button_0 config \ > -command "Editor&::print_file ${print_dialog} ${t}" > ${print_dialog}.button_1 config \ > -command "itcl::delete object ${print_dialog}" > > global ${print_dialog}-ptarget ${print_dialog}-cmd > set ${print_dialog}-ptarget "all" > set tit [wm title ${topl}] > regsub \ > -all {\*} ${tit} "" tit > regsub \ > -all {\[} ${tit} {\\[} tit > regsub \ > -all {\]} ${tit} {\\]} tit > set ${print_dialog}-cmd [format > $sn_options(def,ascii-print-command) \ > ${tit}] > ${print_dialog} configure -title [list [get_indep String Print] > ${tit}] > > frame ${print_dialog}.command > label ${print_dialog}.command.prompt \ > -text [get_indep String SQLPprintercmd] > entry ${print_dialog}.command.cmd \ > -width 70 \ > -textvariable ${print_dialog}-cmd > focus ${print_dialog}.command.cmd > bind ${print_dialog}.command.cmd \ > "${print_dialog}.button_0 invoke" > pack ${print_dialog}.command.prompt \ > -side left > pack ${print_dialog}.command.cmd \ > -side left \ > -padx 10 \ > -fill x \ > -expand y > pack ${print_dialog}.command \ > -fill x \ > -expand y > > radiobutton ${print_dialog}.marked \ > -text [get_indep String Marked] \ > -variable ${print_dialog}-ptarget \ > -value marked > radiobutton ${print_dialog}.all \ > -text [get_indep String All] \ > -variable ${print_dialog}-ptarget \ > -value all > #radiobutton $print_dialog.view -text [get_indep String View] \ > # -variable $print_dialog-ptarget -value view > pack ${print_dialog}.marked \ > -anchor w \ > -padx 60 > pack ${print_dialog}.all \ > -anchor w \ > -padx 60 > #pack $print_dialog.view -anchor w -padx 60 > > ${print_dialog} move_to_mouse > catch {${print_dialog} resizable no no} > > ${print_dialog} take_focus > } > > method filter {{all 0}} { > if {$itk_option(-symbols) != ""} { > $itk_option(-symbols) configure -contents [read_filetags ${all}] > } > } > > #this function is called, when the symbols combobox > #is called > method postcommand {m} { > if {! ${displayed}} { > filter > set displayed 1 > } > } > > #called, when the editor should be activated > method activate {} { > if {$itk_option(-menu) != ""} { > } > if {$itk_option(-toolbar) != ""} { > pack $itk_component(toolbar) \ > -side left > } > #by switching to the editor, disable the > #flag to read all symbols, because it can take > #a long time > if {$itk_option(-symbols_filter) != ""} { > upvar #0 $itk_option(-symbols_filter)-related related > ::set related 1 > } > DispModified > GetFileTags 0 "" > focus $itk_component(editor) > } > > method deactivate {} { > if {$itk_option(-toolbar) != ""} { > pack forget $itk_component(toolbar) > } > set $itk_option(-message_var) "" > > if {$itk_option(-linenumber_var) != ""} { > set $itk_option(-linenumber_var) "" > } > } > > method Focus_In {} { > global last_Editor > ::set last_Editor ${this} > > if {$itk_option(-linenumber_var) != ""} { > set $itk_option(-linenumber_var) [$itk_component(editor) > index insert] > } > SetTitle > } > > method Focus_Out {} { > > set $itk_option(-message_var) "" > > if {$itk_option(-linenumber_var) != ""} { > set $itk_option(-linenumber_var) "" > } > } > > #converts "symbol(scope) class" to "class symbol scope" > proc split_symbol {ssym class symbol scope} { > upvar ${class} cc > upvar ${symbol} ss > upvar ${scope} xs > > #convert 'foo()(md) boo' --> 'foo%%(md) boo' > regsub \ > -all {\(\)\(} [join ${ssym}] {%%\(} sym > #convert 'foo%%(md) boo' --> 'foo%% md boo' > regsub \ > -all {\(|\)} ${sym} " " sym > #convert 'foo%% md boo' --> 'foo() md boo' > regsub \ > -all {%%} ${sym} {()} sym > set ss [lindex ${sym} 0] > set xs [lindex ${sym} 1] > set cc [lindex ${sym} 2] > } > > # Figure out which symbol menus should be used in the editor! > proc combobox_scopes {} { > global combobox_editor_scopes sn_fortran_scopes > set scp [list cl {cl t un} e {e ec} fu {fu fd md mi} fr {fr} gv \ > {con gv iv} ma {ma}] > > foreach sc {com cov su} { > if {[::info commands paf_db_${sc}] != ""} { > lappend scp com {com cov} su {su} > break > } > } > array set combobox_editor_scopes ${scp} > } > > ################################################ > #goto specified symbol > # > #one important information is that this function > #should only be called from the combobox and not > #external, except the call simulate the combobox > #functionality > method goto {combo ssym} { > if {${ssym} == ""} { > return > } > > #dump the current view into the history stack > ${topw} history_stack_add_point ${this} > > if {$itk_option(-symbols_filter) != ""} { > upvar #0 $itk_option(-symbols_filter)-related related > } else { > set related 1 > } > > #convert 'foo()(md) boo' --> 'foo%%(md) boo' > regsub \ > -all {\(\)\(} ${ssym} {%%\(} sym > #convert 'foo%%(md) boo' --> 'foo%% md boo' > regsub \ > -all {\(|\)} ${sym} " " sym > #convert 'foo%% md boo' --> 'foo() md boo' > regsub \ > -all {%%} ${sym} {()} sym > if {[llength ${sym}] == 3} { > set name "[lindex ${sym} 2] [lindex ${sym} 0]" > set scope [lindex ${sym} 1] > } else { > set name [lindex ${sym} 0] > set scope [lindex ${sym} 1] > } > if {${scope} == ""} { > set scope cl > } > > #get the offset of the selected text, if there > #are more than one entry with the same text > if {${combo} != ""} { > set off [${combo} offset] > } else { > set off 0 > } > > if {${related}} { > #get ranges with the specified scope > set tg "${name} ${scope}" > set pos [$itk_component(editor) tag ranges ${tg}] > set len [llength ${pos}] > #there are two tags (first,end) with the same name > set pos [lindex ${pos} [expr {${off} * 2}]] > > SetFondPos ${pos} 0 0 > } else { > set pos "" > } > > # If the given symbol is not found by searching > # for tags in the text widget, search the DB > # without a scope for symbols in this file. > > if {${pos} == ""} { > set cnt [read_matched_from_db "" "" \ > -exact ${name} "" "" $itk_option(-filename) \ > -1 -1 0 ${off}] > if {${cnt} != ""} { > gotofile_cb "" [lindex ${cnt} 0] "" ${off} > } > } > } > > method getfilename {} { > return $itk_option(-filename) > } > > method getvalidfilename {} { > global sn_options > if {$itk_option(-filename) != $sn_options(noname_file)} { > return $itk_option(-filename) > } else { > return "" > } > } > > method editor {} { > return $itk_component(editor) > } > > method setmodified {m {reporterror ""}} { > # If file is readonly and first modified, warn user > # for this. > if {${reporterror} != "noerror" && ${m} && [file exists > $itk_option(-filename)] \ > && ![file writable $itk_option(-filename)]} { > sn_error_dialog "$itk_option(-filename) [get_indep String > ErrorNotWrite]" > set ret "error" > } else { > set ret "" > } > > $this configure -file_changed ${m} > DispModified > return ${ret} > } > > #tells if the current file is editable > method canModify {} { > global sn_options > #no permissions > if {[file exists $itk_option(-filename)] && ![file writable > $itk_option(-filename)]} { > return 0 > } > #file is opened as readonly > if {$itk_option(-editstate) != "normal"} { > return 0 > } > return 1 > } > > #tells if the file is a valid file, this is true > #if the file name is valid > method validFilename {} { > global sn_options > if {$itk_option(-filename) == $sn_options(noname_file)} { > return 0 > } > return 1 > } > > #simulate Text Edit > method mark args { > ::eval $itk_component(editor) mark ${args} > } > > #this function is called from the retriever, when something > #is selected > method gotofile_cb {w line data {off 0}} { > if {${w} != ""} { > set line [Retriever&::convert_to_line ${w}] > } > > if {${line} == ""} { > error "Editor&::gotofile_cb empty line argument" > } > > set line [split ${line} \t] > set sym [lindex ${line} 0] > set cls [lindex ${line} 1] > set file [lindex ${line} 4] > set pos [lindex ${line} 5] > > #get scope and symbol name > get_key_and_scope ${sym} name scope > set name [string trim "${name} ${cls}"] > > #probably correct filename > set file [sn_convert_FileName ${file}] > > #add current position to history stack > ${topw} history_stack_add_point ${this} > > #if another file should be loaded and the actual > #file is modified, ask to use another window > if {${file} != $itk_option(-filename) && > $itk_option(-file_changed)} { > EditFile ${name} ${file} ${pos} > return > } else { > set answer 0 > } > > if {${answer} == 0} { > #load the file, if it's different > if {${file} != $itk_option(-filename)} { > editfile ${file} ${pos} revert > } else { > SetFondPos ${pos} 0 0 > } > } > > focus $itk_component(editor) > } > > method gotosymbol {{scope ""} {sym ""} {cls ""} {file ""} {from ""} > {type \ > ""} {prm ""} {to ""} {always 1}} { > > #verify if gotosymbol is disabled, this is required, because > #it can happen, that the editfile command is called twice. > global gotosymbol_active > if {[info exists gotosymbol_active] && ${gotosymbol_active} == 0} { > return 0 > } > > #add current position to prev positions list > ${topw} history_stack_add_point ${this} > > if {${file} != "" &&(${from} != "" || ${sym} == "")} { > if {${file} != $itk_option(-filename)} { > editfile ${file} ${from} > } \ > elseif {${from} != ""} { > SetFondPos ${from} 0 0 > } > return 1 > } > > #if something specified > if {"${scope}${sym}${cls}${file}" != ""} { > #if we are around the area, as example a class member > #and the gotosymbol is in this area, don't change > #your area > if {${always} == 0 && ${file} == "" && $itk_option(-symbols) != \ > ""} { > set txt [$itk_option(-symbols) cget -entrytext] > split_symbol $txt cc ss xscope > if {${scope} == "cl" && ${sym} == ${cc} || ${scope} == \ > ${xscope} && ${sym} == ${ss} && ${cls} == ${cc}} { > return 1 > } > } > if {${cls} != ""} { > set sym "${cls} ${sym}" > } > sn_retrieve_symbol ${sym} ${scope} ${file} \ > -exact 1 1 "${this} gotofile_cb" "" ${type} ${prm} > return 1 > } > return 0 > } > > #return selected text in a readable format > method Selection {} { > global sn_sep > set ranges [$itk_component(editor) tag ranges sel] > set pos [$itk_component(editor) index {insert wordstart}] > set off [find_offset] > > #make sure that the cursor doesn't stay in a header, when > #this is true, we have to accept the current position, > #NOT THE SELECTION > if {[points_to_header $itk_component(editor) ${pos}] == "" && > ${ranges} != ""} { > #grep can have added more than one selection region! > if {[llength ${ranges}] > 2} { > set ranges [lrange ${ranges} 0 1] > } > set txt [::eval $itk_component(editor) get ${ranges}] > #delete new lines from the selection > if {[string first \n ${txt}] != -1} { > set txt [lindex [split ${txt} \t] 0] > } > set txt [string trim ${txt}] > > set scope "" > set cls ${txt} > set sym "" > set from "" > set type "" > set prm "" > set to "" > > if {${txt} != ""} { > #if insert position points to a header, > #pass the filename also to the selection, not only this, > #also return the exact db position of the position. > if {[points_to_header $itk_component(editor) ${pos}] != ""} { > set file [getvalidfilename] > > #get current scope > set tg [find_tag] > split_symbol ${tg} dummy dummy scope > > #build pattern to look for > set pat [Retriever&::pattern ${txt}] > > #we have to return the exact position > set cnt [read_matched_from_db "" ${scope} \ > -exact ${pat} "" "" $itk_option(-filename) \ > -1 -1 0 ${off}] > if {${cnt} != ""} { > set cnt [split ${cnt} \t] > if {[string first ${sn_sep} ${pat}] != -1} { > set cls [lindex [split ${pat} ${sn_sep}] 0] > set sym [lindex [split ${pat} ${sn_sep}] 1] > } else { > set sym ${pat} > set cls "" > } > set type [lindex ${cnt} 2] > set prm [lindex ${cnt} 3] > set from [lindex ${cnt} 5] > set to [lindex ${cnt} 6] > } else { > set from ${pos} > set cls ${txt} > } > } else { > set file "" > } > return [list ${scope} ${sym} ${cls} ${file} ${from} ${type} \ > ${prm} ${to}] > } > } else { > set tg [find_tag] > if {${tg} != ""} { > split_symbol ${tg} cls sym scope > > #return the exact description of the symbol > set cnt [read_matched_from_db "" ${scope} \ > -exact [string trim "${cls}${sn_sep}${sym}" > ${sn_sep}] "" \ > "" $itk_option(-filename) \ > -1 -1 0 ${off}] > if {${cnt} != ""} { > set cnt [split ${cnt} \t] > set type [lindex ${cnt} 2] > set prm [lindex ${cnt} 3] > set from [lindex ${cnt} 5] > set to [lindex ${cnt} 6] > } else { > set type "" > set prm "" > set from ${pos} > set to "" > } > return [list ${scope} ${sym} ${cls} > $itk_option(-filename) ${from} \ > ${type} ${prm} ${to}] > } > } > > #nothing is selected, return file and it's position > return [list "" "" "" $itk_option(-filename) ${pos}] > } > > method clearselection {} { > $itk_component(editor) tag remove sel 0.0 end > } > > method Focus {} { > focus $itk_component(editor) > } > > #make a title for the Dump position, this is usefull > #for the views stack (prev/next) > method DumpTitle {{dump ""}} { > if {${dump} == ""} { > set dump [Dump] > } > set tg [find_tag] > if {${tg} != ""} { > split_symbol ${tg} cls sym scope > return "Edit [string trim "${sym}(${scope}) ${cls}"]" > } else { > return "Edit [lindex ${dump} 0] \[[lindex ${dump} 1]\]" > } > } > > method AddHistoryFromDump {dumpstr title} { > set tg [find_tag] > > foreach {key val} ${dumpstr} { > set dump(${key}) ${val} > } > if {$dump(offset) == ""} { > set dump(offset) 0 > } > > if {${tg} != ""} { > split_symbol ${tg} cls sym scope > if {${cls} != ""} { > set name [string trim "${cls} ${sym}"] > } else { > set name [string trim ${sym}] > } > #don't store the position in the file > #this makes alot of conflicts > set data [list ${scope} ${name} $dump(offset) $dump(file)] > set tt ${name} > } else { > set scope f > set data [list f $dump(file)] > set tt $dump(file) > } > > #Add position into history > sn_add_history ${scope} ${data} [sn_make_history_title edit > ${scope} \ > ${tt}] > } > > #return the important data to restore this widget > #in later time again (used by saving the project) > method Dump {} { > global sn_options > global tkText > > if {$itk_option(-filename) == $sn_options(noname_file)} { > #no dump for nonamed files > return "" > } > > set pos [$itk_component(editor) index insert] > set state [$itk_component(editor) cget -state] > set tabsize [$itk_component(editor) cget -tabsize] > set offset [find_offset] > > if {[info exists tkText($itk_component(editor),ovwrt)]} { > set ovwrt $tkText($itk_component(editor),ovwrt) > } else { > set ovwrt 0 > } > > #save settings as {key value} > return [list file $itk_option(-filename) pos ${pos} state > ${state} ovrwt \ > ${ovwrt} tabsize ${tabsize} offset ${offset}] > } > > #gets the result from the function "Dump" to > #restore the older state (used by restoring the project) > method Restore {str} { > global sn_options > > foreach {key val} ${str} { > set restdata(${key}) ${val} > } > if {! [info exists restdata(pos)]} { > #backward compatible > set restdata(file) [lindex ${str} 0] > set restdata(pos) [lindex ${str} 1] > set restdata(state) [lindex ${str} 2] > set restdata(ovwrt) [lindex ${str} 3] > set restdata(tabsize) [lindex ${str} 4] > } > > if {$restdata(file) != $itk_option(-filename)} { > editfile $restdata(file) -1 > } > > #don't set overwrite mode!! > #set_overwrite $editor $restdata(ovwrt) set > > #be sure, that we use tabsize, not tabs value, tabs value > #is in pixels and could be too large. > if {$restdata(tabsize) > 8 || $restdata(tabsize) < 2} { > set restdata(tabsize) $sn_options(def,edit-tabstop) > } > > #don't restore the state of the file > $itk_component(editor) config \ > -tabsize $restdata(tabsize) > > #Don't mark the position, just jump to it > SetFondPos $restdata(pos) 1 1 0 > > #set Focus to the widget!! > #Focus > } > > # This method is only ever called from MultiWindow&::Refresh_Yourself. > # It must be a no-op for an editor. We would never want to revert > # changes in an open editor or revert the contents of an editor > # to those on disk without the user's permission. > > method Refresh_Display {} { > } > > method Update_Layout {} { > global sn_options > > # Actual font size and colors. > $itk_component(editor) configure \ > -font $sn_options(def,edit-font) \ > -fg $sn_options(def,edit-fg) \ > -bg $sn_options(def,edit-bg) \ > -selectforeground $sn_options(def,select-fg) \ > -selectbackground $sn_options(def,select-bg) > > # Actual tab size. > set_tabsize $itk_component(editor) > > # Actualize tag colors. > init_tags $itk_component(editor) > > # Wrap. > set_wrap $itk_component(editor) > > # Overwrite flag. > set_overwrite $itk_component(editor) "" set > > #right mouse option menu > bind_right_mouse $itk_component(editor) > > #readonly-project > if {$sn_options(readonly)} { > set st disabled > } else { > set st normal > } > if {$itk_option(-editstate) != ${st}} { > set itk_option(-editstate) ${st} > $itk_component(editor) configure \ > -state $itk_option(-editstate) > } > } > > #this function copies all the information from src to > #dst, like contents, tags, .. > proc friend_copy {dst src} { > set sed [${src} editor] > set ded [${dst} editor] > > #delete existing buffer > ${ded} delete 0.0 end > > #Add the contents of the src editor > ${ded} insert 0.0 [${sed} get 0.0 end] > > #delete the last '\n' from the destination buffer > ${ded} delete {end-1c} end > > #set the same modified flag for the new buffer > ${dst} setmodified [${src} cget -file_changed] noerror > > #set same mtime for the view > ${dst} iset file_mtime [${src} cget -file_mtime] > } > > #called, when the widget should be closed > #mode=0: Ask if nessecary (no other buffer > # with the same filename > #mode=1: always close > method Close {{mode 0}} { > if {${mode} == 0 && $itk_option(-file_changed)} { > if {[Ask_For_Modified revert]} { > #can be closed > return 1 > } else { > return 0 > } > } > return 1 > } > > method whoami {} { > return edit > } > > # Old tag names > private variable old_off "" > private variable old_tg "" > > # Protected variables > protected variable editor "" > protected variable displayed 0 > protected variable gotosymbol_active 1 > > #mtime for the file to prove if it has been modified > #external during it is opened in SN. > public variable file_mtime 0 > > #common variables > common ".multiwindow-\[0-9\]*" > > #public variables > itk_option define -filename filename Filename $sn_options(noname_file) { > editfile $itk_option(-filename) -1 > } > > # public variable file_changed 0 > > itk_option define -file_changed file_changed File_Changed 0 > public variable highlight y > itk_option define -findcombo findcombo Findcombo "" > #for readonly-projects > public variable topw "" > > private variable edit_SearchNoCase > private variable edit_SearchMethod > private variable edit_SearchString > private variable edit_SearchDirection > private variable edit_ReplaceString >} > >proc wait_editor_end {procfd} { > set end [gets ${procfd} msg] > if {${end} < 0} { > catch {close ${procfd}} > } else { > sn_log "wait_editor_end: ${msg}" > } > update idletasks >} > >#bind tags to the editor >Editor&::EditorBindings > ># ># Choose the current editor to edit the files ># >proc sn_edit_file {symbol file {line ""} {search 1} {state ""}} { > global Switch_Is_Enabled > incr Switch_Is_Enabled -1 > > sn_log "edit file (${symbol}, ${file}, ${line}, ${search}, ${state})" > > set ret [Editor&::EditFile ${symbol} ${file} ${line} ${search} ${state}] > > incr Switch_Is_Enabled > > return ${ret} >} Syd Polk spolk@redhat.com Engineering Manager +1 408 543 9430 Red Hat, Inc.