| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : fusearch.tcl |
|---|
| 3 | # PURPOSE : This file contains a namespace called funcSearch with its |
|---|
| 4 | # functions. It's for creating a form that allows to look for a |
|---|
| 5 | # function giving some parameters: name, grammar, parameters, |
|---|
| 6 | # description, etc. |
|---|
| 7 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | # TESTING |
|---|
| 12 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 13 | # Put if {1} for testing this file. |
|---|
| 14 | if {0} { |
|---|
| 15 | package require Tk |
|---|
| 16 | package require BWidget |
|---|
| 17 | # force BWidget autoload |
|---|
| 18 | Bitmap::use |
|---|
| 19 | set toltk_script_path [file dirname [info script]] |
|---|
| 20 | set toltk_images_path [file join ${toltk_script_path} images] |
|---|
| 21 | if { [lsearch $Bitmap::path $toltk_images_path] == -1 } { |
|---|
| 22 | lappend Bitmap::path [file join $toltk_script_path images] |
|---|
| 23 | } |
|---|
| 24 | package require msgcat |
|---|
| 25 | namespace import msgcat::* |
|---|
| 26 | ::msgcat::mclocale es |
|---|
| 27 | ::msgcat::mcload [file join $toltk_script_path msgs] |
|---|
| 28 | |
|---|
| 29 | source [file join $toltk_script_path "mclistbox.tcl"] |
|---|
| 30 | namespace import ::mclistbox::* |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | package require blistboxplus |
|---|
| 34 | package require beditselector |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 38 | namespace eval funcSearch { |
|---|
| 39 | # |
|---|
| 40 | # PURPOSE: The purpose of this namespace is organize code and functions. |
|---|
| 41 | # It also stotres a special namespace is created for each instance |
|---|
| 42 | # of funcSearch. |
|---|
| 43 | # VARIABLES: |
|---|
| 44 | # tmpOpt -> array with information functions search |
|---|
| 45 | # grammars,PRO -> procedure created for grammar editSelector |
|---|
| 46 | # var,grammars -> grammars of searched function |
|---|
| 47 | # var,name -> name's substring of searched function |
|---|
| 48 | # var,numPars -> numbers of params of searched function |
|---|
| 49 | # var,desc -> description's substring of searched function |
|---|
| 50 | # var,par$i,grammar -> grammar of any param of searched function |
|---|
| 51 | # var,par$i,name -> name's substring of any param of searched function |
|---|
| 52 | # widget,res -> mclistbox path where results are shown |
|---|
| 53 | # iniconfig -> name of funcSearch in ini file |
|---|
| 54 | # widget -> contains the widget |
|---|
| 55 | # widget(fr) -> Main frame of the document |
|---|
| 56 | # sensitive -> has a value 1 if the user has selected case sensitive search |
|---|
| 57 | # |
|---|
| 58 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | variable tmpOpt |
|---|
| 60 | variable widget |
|---|
| 61 | variable sensitive |
|---|
| 62 | variable iniconfig |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 67 | proc ::funcSearch::Show {} { |
|---|
| 68 | # |
|---|
| 69 | # PURPOSE: Shows the function search dialog |
|---|
| 70 | # |
|---|
| 71 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 72 | variable widget |
|---|
| 73 | if { [info exist widget(document)] && [winfo exists $widget(document)] } { |
|---|
| 74 | if { [$widget(document) cget -state] eq "minimized" } { |
|---|
| 75 | $widget(document) restore |
|---|
| 76 | } |
|---|
| 77 | $widget(document) raise |
|---|
| 78 | } else { |
|---|
| 79 | Create |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 85 | proc ::funcSearch::Create {} { |
|---|
| 86 | # |
|---|
| 87 | # PURPOSE: Creates the function search dialog |
|---|
| 88 | # |
|---|
| 89 | # PARAMETERS: |
|---|
| 90 | # path: path of dialgo's parent |
|---|
| 91 | # |
|---|
| 92 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 93 | global toltk_options |
|---|
| 94 | variable tmpOpt |
|---|
| 95 | variable widget |
|---|
| 96 | variable sensitive |
|---|
| 97 | variable iniconfig |
|---|
| 98 | |
|---|
| 99 | # Name of function search's section in ini file |
|---|
| 100 | set iniconfig "FunctionSearch" |
|---|
| 101 | |
|---|
| 102 | # Create the widget |
|---|
| 103 | set widget(document) [::project::CreateForm \ |
|---|
| 104 | -iniconfig $iniconfig -title [mc "Functions Search"] \ |
|---|
| 105 | -helpkey "Tb4Fus" -closecmd [list ::funcSearch::Destroy]] |
|---|
| 106 | set widget(fr) [$widget(document) getframe] |
|---|
| 107 | |
|---|
| 108 | label $widget(fr).limg -image [::Bitmap::get search] |
|---|
| 109 | label $widget(fr).lfind -text [mc "Search functions"]... \ |
|---|
| 110 | -font $toltk_options(fonts,Title1) |
|---|
| 111 | |
|---|
| 112 | # Obtain the complete list of grammars |
|---|
| 113 | set lst [::tol::info grammars] |
|---|
| 114 | set txt [mc "of grammars"]: |
|---|
| 115 | # Beditselector of grammars |
|---|
| 116 | set tmpOpt(grammars,PRO) [beditselector $widget(fr).bes -label $txt \ |
|---|
| 117 | -list $lst -width 30 -readonly false -readonly true ] |
|---|
| 118 | set lgra [$tmpOpt(grammars,PRO) get label] |
|---|
| 119 | set egra [$tmpOpt(grammars,PRO) get entry] |
|---|
| 120 | set bgra [$tmpOpt(grammars,PRO) get button] |
|---|
| 121 | |
|---|
| 122 | # Criteria search by name |
|---|
| 123 | label $widget(fr).lname -text [mc "whose name contains"]: |
|---|
| 124 | entry $widget(fr).ename -width 18 -textvariable ::funcSearch::tmpOpt(var,name) |
|---|
| 125 | bind $widget(fr).ename <Return> [list ::funcSearch::Search] |
|---|
| 126 | bind $widget(fr).ename <Control-g> [list ::funcSearch::Search] |
|---|
| 127 | |
|---|
| 128 | # Criteria search by description |
|---|
| 129 | label $widget(fr).ldesc -text [mc "whose description contains"]: |
|---|
| 130 | entry $widget(fr).edesc -width 18 -textvariable ::funcSearch::tmpOpt(var,desc) |
|---|
| 131 | bind $widget(fr).edesc <Return> [list ::funcSearch::Search ] |
|---|
| 132 | bind $widget(fr).edesc <Control-g> [list ::funcSearch::Search ] |
|---|
| 133 | |
|---|
| 134 | # Case sensitive search |
|---|
| 135 | checkbutton $widget(fr).cs -text [mc "Case sensitive"] \ |
|---|
| 136 | -variable ::funcSearch::sensitive |
|---|
| 137 | |
|---|
| 138 | # Scrolled window for criteria search by params. NOT IMPLEMENTED |
|---|
| 139 | if {0} { |
|---|
| 140 | set sw [ScrolledWindow $widget(fr).sw] |
|---|
| 141 | #set sf [ScrollableFrame $w.sw.fr -constrainedwidth 1 -height 80 -width 560] |
|---|
| 142 | set sf [ScrollableFrame $widget(fr).sw.fr -constrainedwidth 0 -height 80 -width 560] |
|---|
| 143 | $sw setwidget $sf |
|---|
| 144 | set fr [$sf getframe] |
|---|
| 145 | label $widget(fr).lpars -text [mc "and with at least"] |
|---|
| 146 | frame $widget(fr).fg |
|---|
| 147 | set widget(spinbox) [SpinBox $widget(fr).fg.sbpars -range {0 8} -width 4 \ |
|---|
| 148 | -justify right -editable false\ |
|---|
| 149 | -textvariable ::funcSearch::tmpOpt(var,numPars) \ |
|---|
| 150 | -modifycmd [list ::funcSearch::CheckPar $fr]] |
|---|
| 151 | label $widget(fr).fg.lpars -text [mc "parameters"] |
|---|
| 152 | #grid $w.fg.sbpars $w.fg.lpars -sticky nw -padx 2 |
|---|
| 153 | } |
|---|
| 154 | # Button box with |
|---|
| 155 | set widget(bbox) \ |
|---|
| 156 | [ButtonBox $widget(fr).bb -orient horizontal -spacing 10 \ |
|---|
| 157 | -padx 0 -pady 0 -homogeneous false] |
|---|
| 158 | $widget(bbox) add -text [mc "Find"] -relief link \ |
|---|
| 159 | -helptext "[mc "Find"] (Ctrl+G)" -image [::Bitmap::get bfind] \ |
|---|
| 160 | -compound left -padx 5 -pady 1 -command [list ::funcSearch::Search] |
|---|
| 161 | $widget(bbox) add -relief link -helptext [mc "Cancel"] \ |
|---|
| 162 | -image [::Bitmap::get cancelx] -text [mc Cancel] \ |
|---|
| 163 | -compound left -padx 5 -pady 1 -command [list ::funcSearch::Destroy] |
|---|
| 164 | |
|---|
| 165 | Separator $widget(fr).sep -orient horizontal -relief ridge |
|---|
| 166 | |
|---|
| 167 | # Grid of results |
|---|
| 168 | set f [frame $widget(fr).fres -bd 2] |
|---|
| 169 | |
|---|
| 170 | scrollbar $f.sy -command "$f.mclbres yview" |
|---|
| 171 | scrollbar $f.sx -orient horizontal -command "$f.mclbres xview" |
|---|
| 172 | set name [mc "Name"] |
|---|
| 173 | set content [mc "Content"] |
|---|
| 174 | set path [mc "Path"] |
|---|
| 175 | set description [mc "Description"] |
|---|
| 176 | |
|---|
| 177 | set tmpOpt(widget,res) [blistboxplus $f.mclbres \ |
|---|
| 178 | -cols "$name $content $path $description"\ |
|---|
| 179 | -background white -yscrollcommand "$f.sy set" \ |
|---|
| 180 | -xscrollcommand "$f.sx set" -selectmode multiple -background white \ |
|---|
| 181 | -highlightthickness 0 -borderwidth 2 -linewidth 2 \ |
|---|
| 182 | -exportselection false -border 0 -height 0 -readonly true \ |
|---|
| 183 | -colkeypress $name] |
|---|
| 184 | |
|---|
| 185 | set lb $tmpOpt(widget,res) |
|---|
| 186 | set lbMenu [$lb getMenu] |
|---|
| 187 | |
|---|
| 188 | $lbMenu insert 0 separator |
|---|
| 189 | $lbMenu insert 0 command -label [mc "View definition"] \ |
|---|
| 190 | -command [list ::funcSearch::ViewDefinition] -accelerator CTRL+W |
|---|
| 191 | |
|---|
| 192 | # binds of listboxplus |
|---|
| 193 | #@ anteriormente era una llamada a un método bind |
|---|
| 194 | bind $tmpOpt(widget,res) <Control-KeyRelease> \ |
|---|
| 195 | +[list ::funcSearch::OnControlKey $tmpOpt(widget,res) %K %k] |
|---|
| 196 | |
|---|
| 197 | # blisboxplus auto-adjust width of columns without configured width |
|---|
| 198 | #$lb column configure [mc "Name"] -width [expr 18*7] |
|---|
| 199 | #$lb column configure [mc "Content"] -width [expr 35*7] |
|---|
| 200 | $lb column configure [mc "Path"] -width [expr 15*7] |
|---|
| 201 | |
|---|
| 202 | grid $f.mclbres -sticky news |
|---|
| 203 | |
|---|
| 204 | grid columnconfigure $f 0 -weight 1 |
|---|
| 205 | grid rowconfigure $f 0 -weight 1 |
|---|
| 206 | |
|---|
| 207 | frame $widget(fr).f -width 25 |
|---|
| 208 | grid $widget(fr).limg $widget(fr).lfind - - - -sticky nw -pady 5 |
|---|
| 209 | grid ^ $widget(fr).f $widget(fr).bes - - -sticky nw -pady 0 -padx 1 |
|---|
| 210 | grid ^ ^ $widget(fr).lname $widget(fr).ename - -sticky nw -pady 1 |
|---|
| 211 | grid ^ ^ $widget(fr).ldesc $widget(fr).edesc - -sticky nw -pady 1 |
|---|
| 212 | grid ^ ^ $widget(fr).cs - - -sticky nw -pady 1 |
|---|
| 213 | grid ^ ^ $widget(bbox) - - -sticky nws |
|---|
| 214 | grid $widget(fr).sep - - - - -sticky new -pady 5 |
|---|
| 215 | grid $widget(fr).fres - - - - -sticky news |
|---|
| 216 | |
|---|
| 217 | grid columnconfigure $widget(fr) 4 -weight 1 |
|---|
| 218 | grid rowconfigure $widget(fr) 7 -weight 1 |
|---|
| 219 | |
|---|
| 220 | # establish initial focus |
|---|
| 221 | focus $widget(fr).ename |
|---|
| 222 | |
|---|
| 223 | ::funcSearch::ReadIni |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 228 | proc ::funcSearch::OnControlKey {_lb keysym keycode } { |
|---|
| 229 | # |
|---|
| 230 | # PURPOSE: Control of the binds of accelerator keys of listbox |
|---|
| 231 | # |
|---|
| 232 | # PARAMETERS: _lb -> self |
|---|
| 233 | # keysym -> The keysym corresponding to the event, |
|---|
| 234 | # substituted as a textual string |
|---|
| 235 | # keycode -> The keycode field from the event |
|---|
| 236 | # |
|---|
| 237 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 238 | switch [string toupper $keysym] { |
|---|
| 239 | G { |
|---|
| 240 | ::funcSearch::Search |
|---|
| 241 | } |
|---|
| 242 | W { |
|---|
| 243 | ::funcSearch::ViewDefinition |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 249 | proc ::funcSearch::ViewDefinition { } { |
|---|
| 250 | # |
|---|
| 251 | # PURPOSE: Show the file and function selected on results listbox. It works |
|---|
| 252 | # only when an unique function has been selected. |
|---|
| 253 | # |
|---|
| 254 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 255 | variable tmpOpt |
|---|
| 256 | |
|---|
| 257 | set lb $tmpOpt(widget,res) |
|---|
| 258 | set lbMenu [$lb getMenu] |
|---|
| 259 | # rows selected |
|---|
| 260 | set lbrow [$lb selection get] |
|---|
| 261 | # verifies that only a column has been selected |
|---|
| 262 | if {[llength $lbrow] == 1 } { |
|---|
| 263 | set selected [$lb get $lbrow] ;# get his content |
|---|
| 264 | set objName [lindex $selected 0] ;# name of function |
|---|
| 265 | set path [lindex $selected 2] ;# path of function |
|---|
| 266 | # verifies if that function has path |
|---|
| 267 | if {$path != ""} { |
|---|
| 268 | # the grammar is the first element of column content |
|---|
| 269 | set grammar [lindex [lindex $selected 1] 0] |
|---|
| 270 | # call to ViewDefinition |
|---|
| 271 | ::TolInspector::ViewDefinition $objName $path $grammar |
|---|
| 272 | } else { |
|---|
| 273 | tk_messageBox -type ok -icon warning\ |
|---|
| 274 | -message [mc "Object %1\$s is not defined in a tol file" $objName]\ |
|---|
| 275 | -parent $tmpOpt(widget,res) -title [mc Warning] |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 282 | proc ::funcSearch::Search {} { |
|---|
| 283 | # |
|---|
| 284 | # PURPOSE: Looks for all functions that matches the criteriums introduced in |
|---|
| 285 | # search dialog, shows the results and hides the dialog. |
|---|
| 286 | # |
|---|
| 287 | # PARAMETERS: |
|---|
| 288 | # dialog: Functions search path |
|---|
| 289 | # |
|---|
| 290 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 291 | variable tmpOpt |
|---|
| 292 | variable sensitive |
|---|
| 293 | variable widget |
|---|
| 294 | |
|---|
| 295 | set search 0 |
|---|
| 296 | set tmpOpt(var,grammars) [$tmpOpt(grammars,PRO) cget -sel] |
|---|
| 297 | |
|---|
| 298 | # Verify that the search can be made |
|---|
| 299 | if { $tmpOpt(var,grammars) == "" } { |
|---|
| 300 | set search 1 ;# There isn't grammars where search |
|---|
| 301 | } |
|---|
| 302 | if { ($tmpOpt(var,name) == "") && ($tmpOpt(var,desc) == "") } { |
|---|
| 303 | set search 2 ;# There aren't sufficient criteria search |
|---|
| 304 | } |
|---|
| 305 | if { [ catch { regexp "(.*)$tmpOpt(var,name)(.*)" "dummysrting" } ] } { |
|---|
| 306 | set search 3 ;# Criteria search for the name are incorrect |
|---|
| 307 | } |
|---|
| 308 | if { [ catch { regexp "(.*)$tmpOpt(var,desc)(.*)" "dummysrting" } ] } { |
|---|
| 309 | set search 4 ;# Criteria search for the description are incorrect |
|---|
| 310 | } |
|---|
| 311 | if {$search == 0} { ;# The search can be made |
|---|
| 312 | . configure -cursor watch |
|---|
| 313 | update |
|---|
| 314 | if {$sensitive} { ;# Case sensitive search |
|---|
| 315 | # Verify grammars and names of functions |
|---|
| 316 | foreach gra $tmpOpt(var,grammars) { |
|---|
| 317 | set result($gra) [::tol::info functions $gra] |
|---|
| 318 | foreach f $result($gra) { |
|---|
| 319 | if {![regexp "(.*)$tmpOpt(var,name)(.*)" $f]} { |
|---|
| 320 | set pos [lsearch $result($gra) $f] |
|---|
| 321 | set result($gra) [lreplace $result($gra) $pos $pos] |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | # Verify if the functions are in the included files |
|---|
| 326 | set resultIncluded [::tol::info var Code] |
|---|
| 327 | foreach f $resultIncluded { |
|---|
| 328 | set fU [string toupper $f] |
|---|
| 329 | if {![regexp "(.*)$tmpOpt(var,name)(.*)" $f]} { |
|---|
| 330 | set pos [lsearch $resultIncluded $f] |
|---|
| 331 | set resultIncluded [lreplace $resultIncluded $pos $pos] |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | # discard duplicated functions |
|---|
| 335 | set resultIncludedNoDup "" |
|---|
| 336 | foreach func $resultIncluded { |
|---|
| 337 | set dup 0 ;# no duplicated |
|---|
| 338 | foreach gra $tmpOpt(var,grammars) { |
|---|
| 339 | if { [lsearch -exact $result($gra) $func] != -1 } { |
|---|
| 340 | set dup 1 |
|---|
| 341 | } |
|---|
| 342 | } |
|---|
| 343 | if {$dup == 0} { ;# it is inserted if it isn't duplicate |
|---|
| 344 | lappend resultIncludedNoDup $func |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | # Look for in the description and I keep name, content, path |
|---|
| 348 | # and description |
|---|
| 349 | set funcs "" |
|---|
| 350 | foreach gra [array names result] { |
|---|
| 351 | foreach f $result($gra) { |
|---|
| 352 | set inf [TclInfoFun $gra $f] |
|---|
| 353 | # Verify description |
|---|
| 354 | if {[regexp "(.*)$tmpOpt(var,desc)(.*)" [lindex $inf 3]]} { |
|---|
| 355 | lappend funcs \ |
|---|
| 356 | [list $f [lindex $inf 5] [lindex $inf 1] [lindex $inf 3]] |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | # For the functions on inluded files, search in the description, |
|---|
| 361 | # I verify the type of the function, and keep name, content, path |
|---|
| 362 | # and description |
|---|
| 363 | set funcsIncluded "" |
|---|
| 364 | foreach f $resultIncludedNoDup { |
|---|
| 365 | set inf [::tol::info var [list Code $f]] |
|---|
| 366 | #puts "funcSearch::Search: inf = $inf" |
|---|
| 367 | if { [ContentCodeGrammar [array names result] [lindex $inf 2] ] } { |
|---|
| 368 | if {[regexp "(.*)$tmpOpt(var,desc)(.*)" [lindex $inf 4]]} { |
|---|
| 369 | lappend funcsIncluded \ |
|---|
| 370 | [list $f [lindex $inf 2] [lindex $inf 3] [lindex $inf 4]] |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | # No case sensitive search |
|---|
| 375 | } else { |
|---|
| 376 | set tU "[string toupper $tmpOpt(var,grammars) ]" |
|---|
| 377 | # Verify grammars and names of functions |
|---|
| 378 | foreach gra $tmpOpt(var,grammars) { |
|---|
| 379 | set result($gra) [::tol::info functions $gra] |
|---|
| 380 | foreach f $result($gra) { |
|---|
| 381 | set rU [string toupper $result($gra)] |
|---|
| 382 | set fU [string toupper $f] |
|---|
| 383 | set tU [string toupper $tmpOpt(var,name)] |
|---|
| 384 | if {![regexp "(.*)${tU}(.*)" $fU]} { |
|---|
| 385 | set pos [lsearch $result($gra) $f] |
|---|
| 386 | set result($gra) [lreplace $result($gra) $pos $pos] |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | # Verify if the functions are in the included archives |
|---|
| 392 | set resultIncluded [::tol::info var Code] |
|---|
| 393 | foreach f $resultIncluded { |
|---|
| 394 | set fU [string toupper $f] |
|---|
| 395 | if {![regexp "(.*)${tU}(.*)" $fU]} { |
|---|
| 396 | set pos [lsearch $resultIncluded $f] |
|---|
| 397 | set resultIncluded [lreplace $resultIncluded $pos $pos] |
|---|
| 398 | } |
|---|
| 399 | } |
|---|
| 400 | # discard duplicated functions |
|---|
| 401 | set resultIncludedNoDup "" |
|---|
| 402 | foreach func $resultIncluded { |
|---|
| 403 | set dup 0 ;# no duplicated |
|---|
| 404 | foreach gra $tmpOpt(var,grammars) { |
|---|
| 405 | if { [lsearch -exact $result($gra) $func] != -1 } { |
|---|
| 406 | set dup 1 |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | if {$dup == 0} { ;# it is inserted if it isn't duplicate |
|---|
| 410 | lappend resultIncludedNoDup $func |
|---|
| 411 | } |
|---|
| 412 | } |
|---|
| 413 | # Look for in the description and I keep name, content, path |
|---|
| 414 | # and description |
|---|
| 415 | set funcs "" |
|---|
| 416 | foreach gra [array names result] { |
|---|
| 417 | foreach f $result($gra) { |
|---|
| 418 | set inf [TclInfoFun $gra $f] |
|---|
| 419 | set iU [string toupper $inf] |
|---|
| 420 | set tU [string toupper $tmpOpt(var,desc)] |
|---|
| 421 | if {[regexp "(.*)${tU}(.*)" [lindex $iU 3]]} { |
|---|
| 422 | #Tolcon_Trace "Content: [lindex $inf 0]" |
|---|
| 423 | lappend funcs \ |
|---|
| 424 | [list $f [lindex $inf 5] [lindex $inf 1] [lindex $inf 3]] |
|---|
| 425 | } |
|---|
| 426 | } |
|---|
| 427 | } |
|---|
| 428 | # For the functions on inluded files, search in the description, |
|---|
| 429 | # I verify the type of the function, and keep name, content, path |
|---|
| 430 | # and description |
|---|
| 431 | set funcsIncluded "" |
|---|
| 432 | foreach f $resultIncludedNoDup { |
|---|
| 433 | set inf [::tol::info var [list Code $f]] |
|---|
| 434 | #puts "funcSearch::Search: inf = $inf" |
|---|
| 435 | set iU [string toupper $inf] |
|---|
| 436 | set tU [string toupper $tmpOpt(var,desc)] |
|---|
| 437 | if { [ContentCodeGrammar [array names result] [lindex $inf 2] ] } { |
|---|
| 438 | if {[regexp "(.*)${tU}(.*)" [lindex $iU 4]]} { |
|---|
| 439 | lappend funcs \ |
|---|
| 440 | [list $f [lindex $inf 2] [lindex $inf 3] [lindex $inf 4]] |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | } |
|---|
| 445 | . configure -cursor "" |
|---|
| 446 | update |
|---|
| 447 | set some [ShowResults $funcs $funcsIncluded] |
|---|
| 448 | if { $some eq 0 } { |
|---|
| 449 | tk_messageBox -type ok -icon info\ |
|---|
| 450 | -message [mc "Has not been any coincident result"]\ |
|---|
| 451 | -parent $tmpOpt(widget,res) -title [mc Message] |
|---|
| 452 | } |
|---|
| 453 | } else { |
|---|
| 454 | # Show the error messages |
|---|
| 455 | switch -exact -- $search { |
|---|
| 456 | 1 { |
|---|
| 457 | tk_messageBox -type ok -icon warning\ |
|---|
| 458 | -message [mc "There isn't grammars where search"]\ |
|---|
| 459 | -parent $tmpOpt(widget,res) -title [mc Warning] |
|---|
| 460 | } |
|---|
| 461 | 2 { |
|---|
| 462 | tk_messageBox -type ok -icon warning\ |
|---|
| 463 | -message [mc "There aren't sufficient criteria search"]\ |
|---|
| 464 | -parent $tmpOpt(widget,res) -title [mc Warning] |
|---|
| 465 | } |
|---|
| 466 | 3 { |
|---|
| 467 | tk_messageBox -type ok -icon warning\ |
|---|
| 468 | -message [mc "Criteria search for the name are incorrect"]\ |
|---|
| 469 | -parent $tmpOpt(widget,res) -title [mc Warning] |
|---|
| 470 | } |
|---|
| 471 | 4 { |
|---|
| 472 | tk_messageBox -type ok -icon warning\ |
|---|
| 473 | -message [mc "Criteria search for the description are incorrect"]\ |
|---|
| 474 | -parent $tmpOpt(widget,res) -title [mc Warning] |
|---|
| 475 | } |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 483 | proc ::funcSearch::ContentCodeGrammar {gr content} { |
|---|
| 484 | # |
|---|
| 485 | # PURPOSE: Return if a description of a grammar is of the type indicated |
|---|
| 486 | # in a list of grammars |
|---|
| 487 | # |
|---|
| 488 | # PARAMETERS: |
|---|
| 489 | # gr : List of grammars |
|---|
| 490 | # content: Description of function. His first word will be the grammar. |
|---|
| 491 | # |
|---|
| 492 | # RETURN: Return 1 if the first word in content is of the list of grammar. |
|---|
| 493 | # |
|---|
| 494 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 495 | set hasit 0 |
|---|
| 496 | set grammarContent [lindex $content 0] |
|---|
| 497 | foreach g $gr { |
|---|
| 498 | if {$g == $grammarContent} { |
|---|
| 499 | set hasit 1 |
|---|
| 500 | } |
|---|
| 501 | } |
|---|
| 502 | return $hasit |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 507 | proc ::funcSearch::ShowResults {funcs funcsIncluded} { |
|---|
| 508 | # |
|---|
| 509 | # PURPOSE: |
|---|
| 510 | # |
|---|
| 511 | # PARAMETERS: |
|---|
| 512 | # funcs: List of functions of Tol grammars that match the search criteriums |
|---|
| 513 | # funcsIncluded: List of functions of included files that match the search |
|---|
| 514 | # criteriums |
|---|
| 515 | # RETURN: 1 if has been some result, 0 in opposite case |
|---|
| 516 | # |
|---|
| 517 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 518 | variable tmpOpt |
|---|
| 519 | set some 0 |
|---|
| 520 | set lb $tmpOpt(widget,res) |
|---|
| 521 | $lb clear |
|---|
| 522 | foreach funInfo $funcs { |
|---|
| 523 | $lb insert end $funInfo |
|---|
| 524 | set some 1 |
|---|
| 525 | } |
|---|
| 526 | foreach funInfo $funcsIncluded { |
|---|
| 527 | $lb insert end $funInfo |
|---|
| 528 | set some 1 |
|---|
| 529 | } |
|---|
| 530 | return $some |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 535 | proc ::funcSearch::Destroy {} { |
|---|
| 536 | # |
|---|
| 537 | # PURPOSE: Hides functions search document. |
|---|
| 538 | # |
|---|
| 539 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 540 | variable widget |
|---|
| 541 | variable tmpOpt |
|---|
| 542 | ::funcSearch::WriteIni |
|---|
| 543 | array unset tmpOpt |
|---|
| 544 | destroy $widget(document) |
|---|
| 545 | array unset widget |
|---|
| 546 | return 1 |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 551 | proc ::funcSearch::CheckPar {f} { |
|---|
| 552 | # |
|---|
| 553 | # PURPOSE: Function that checks that a certain fuction has at least a number |
|---|
| 554 | # of parameters. NOT IMPLEMENTED. |
|---|
| 555 | # |
|---|
| 556 | # PARAMETERS: |
|---|
| 557 | # f: Function to evaluate. |
|---|
| 558 | # |
|---|
| 559 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 560 | variable tmpOpt |
|---|
| 561 | variable widget |
|---|
| 562 | |
|---|
| 563 | set lst [::tol::info grammars] |
|---|
| 564 | #puts "lst: $lst" |
|---|
| 565 | set num $tmpOpt(var,numPars) |
|---|
| 566 | #puts "num: $num" |
|---|
| 567 | # NO funciona correctamente |
|---|
| 568 | # for {set i 1} {$i <= [expr $num+1]} {incr i} { |
|---|
| 569 | # destroy $f.f$i $f.lt$i $f.lb$i $f.lc$i $f.e$i |
|---|
| 570 | # } |
|---|
| 571 | # destruimos los elementos hasta el maximo de elementos que pueda contener |
|---|
| 572 | #puts " rango: [lindex [$widget(spinbox) cget -range] 1]" |
|---|
| 573 | for {set i 1} {$i <= [lindex [$widget(spinbox) cget -range] 1]} {incr i} { |
|---|
| 574 | destroy $f.f$i $f.lt$i $f.lb$i $f.lc$i $f.e$i |
|---|
| 575 | } |
|---|
| 576 | for {set i 1} {$i <= $num} {incr i} { |
|---|
| 577 | frame $f.f$i -width 15 |
|---|
| 578 | label $f.lt$i -text [mc "in which one is of type"]: |
|---|
| 579 | ComboBox $f.lb$i -values $lst -width 12 -height 5\ |
|---|
| 580 | -textvariable ::funcSearch::tmpOpt(var,par$i,grammar) |
|---|
| 581 | label $f.lc$i -text " [mc {and whose name contains}]:" |
|---|
| 582 | entry $f.e$i -width 18 -textvariable ::funcSearch::tmpOpt(var,par$i,name) |
|---|
| 583 | grid $f.f$i $f.lt$i $f.lb$i $f.lc$i $f.e$i -sticky nw -pady 2 |
|---|
| 584 | } |
|---|
| 585 | grid columnconfigure $f 4 -weight 1 |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 590 | proc ::funcSearch::WriteIni {} { |
|---|
| 591 | # |
|---|
| 592 | # PURPOSE: Write in ini file the grammars selected |
|---|
| 593 | # |
|---|
| 594 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 595 | variable iniconfig |
|---|
| 596 | variable tmpOpt |
|---|
| 597 | set wini ::iniFile::Write |
|---|
| 598 | $wini $iniconfig grammars [$tmpOpt(grammars,PRO) curselection] |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 602 | proc ::funcSearch::ReadIni {} { |
|---|
| 603 | # |
|---|
| 604 | # PURPOSE: Read from ini file the grammars selected. If don't read any |
|---|
| 605 | # selected grammar, selects all grammars by default |
|---|
| 606 | # |
|---|
| 607 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 608 | variable iniconfig |
|---|
| 609 | variable tmpOpt |
|---|
| 610 | # read saved grammars |
|---|
| 611 | set rini ::iniFile::Read |
|---|
| 612 | set grammars [$rini $iniconfig grammars ""] |
|---|
| 613 | if {[llength $grammars] eq 0} { |
|---|
| 614 | # selects all grammars |
|---|
| 615 | $tmpOpt(grammars,PRO) selectAll |
|---|
| 616 | } else { |
|---|
| 617 | # gets the loaded grammars |
|---|
| 618 | $tmpOpt(grammars,PRO) configure -sel $grammars |
|---|
| 619 | } |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 624 | proc ::funcSearch::SearchWord { word } { |
|---|
| 625 | # |
|---|
| 626 | # PURPOSE: Performs a search of a word by name of functions |
|---|
| 627 | # |
|---|
| 628 | # PARAMETERS: |
|---|
| 629 | # dialog -> Mdi child of function search |
|---|
| 630 | # word -> Word to search |
|---|
| 631 | # |
|---|
| 632 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 633 | variable tmpOpt |
|---|
| 634 | |
|---|
| 635 | set tmpOpt(var,name) $word |
|---|
| 636 | ::funcSearch::Search |
|---|
| 637 | } |
|---|