SystemBrowser.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Sep 1999 14:15:54 +0200
changeset 2409 656eeb7197fa
parent 2398 8cefc3c21f40
child 2412 5d341024ea25
permissions -rw-r--r--
checkin from browser

"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

ApplicationModel subclass:#SystemBrowser
	instanceVariableNames:'currentClass currentMethodCategory currentMethod currentSelector
		showInstance actualClasslastMethodCategory aspect lockUpdates
		autoSearch myLabel acceptClass'
	classVariableNames:'CheckForInstancesWhenRemovingClasses'
	poolDictionaries:''
	category:'Interface-Browsers'
!

!SystemBrowser class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    this class implements all kinds of class browsers.
    Typically, it is started with 'SystemBrowser open', but there are many other 
    startup messages, to launch special browsers.
    See the categories 'startup' and 'special search startup' in the classes
    protocol.

    Alse, see the extra document 'doc/misc/sbrowser.doc' or the HTML online doc
    for how to use the browser.

    written winter 89 by claus.

    Notice: SystemBrowser is currently being rewritten to be an instance
    of ApplicationModel - this transition is not yet complete and you see
    here an intermediate version. The instance variables defined here are NOT
    currently used - instead, everything is really done in the BrowserView
    which (currently) keeps the real state of the browser.
    This will certainly change ...

    [author:]
        Claus Gittinger

"
! !

!SystemBrowser class methodsFor:'initialization'!

initialize
    "Browser configuration;
     (values can be changed from your private startup file)"

"/    self classResources.

    "
     setting this to false, the removeClass function will remove
     classes WITHOUT checking for instances. Otherwise,
     it will check and let you confirm in case there are instances.
     Checking for instances may be a bit time consuming, though.
     The default is true - therefore, it will check
    "
    CheckForInstancesWhenRemovingClasses := true

    "
     CheckForInstancesWhenRemovingClasses := true
     CheckForInstancesWhenRemovingClasses := false

     SystemBrowser initialize
    "
! !

!SystemBrowser class methodsFor:'instance creation'!

open
    "launch a standard browser"

    ^ self openOnDevice:(Screen current) 

    "
     SystemBrowser open
    "
!

openInClass:aClass
    "launch a standard browser which immediately switches
     to aClass"

    ^ self openInClass:aClass selector:nil

    "
     SystemBrowser openInClass:Object
    "

    "Created: 30.4.1996 / 14:43:45 / cg"
!

openInClass:aClass selector:aSelector
    "launch a standard browser which immediately switches
     to aClass>>aSelector."

    |brwsr cls|

    brwsr := self openOnDevice:(Screen current).
    brwsr waitUntilVisible.

    cls := aClass.
    cls notNil ifTrue:[
        cls isMeta ifTrue:[
            cls := aClass soleInstance
        ].
        aClass isMeta ifTrue:[
            brwsr instanceProtocol:false
        ].
        aClass isJavaClass ifTrue:[
            brwsr switchToClassNamed:aClass fullName. 
        ] ifFalse:[
            brwsr switchToClassNamed:aClass name. 
        ].
"/        brwsr updateClassCategoryList.

"/        brwsr updateMethodCategoryList.
"/        brwsr updateVariableList.
        brwsr classSelectionChanged.
        aSelector notNil ifTrue:[
            brwsr switchToMethodNamed:aSelector.
        ]
    ].
    ^ brwsr

    "
     SystemBrowser openInClass:Object selector:#at:put:
     SystemBrowser openInClass:Object selector:nil
     SystemBrowser openInClass:nil selector:nil
    "

    "Created: / 22.11.1995 / 21:04:50 / cg"
    "Modified: / 14.10.1998 / 15:31:52 / cg"
!

openOnDevice:aDisplay
    "launch a standard browser on another display."

    ^ self newWithLabel:(self classResources string:'System Browser')
	     setupBlock:[:browser | browser setupForAll]
	      onDevice:aDisplay

    "|d|

     d := XWorkstation new initializeFor:'porty:0'.
     d startDispatch.
     SystemBrowser openOnDevice:d
    "
! !

!SystemBrowser class methodsFor:'ST-80 compatibility'!

newOnClass:aClass
    ^ self browseClass:aClass

    "Created: / 27.10.1997 / 20:10:39 / cg"
! !

!SystemBrowser class methodsFor:'interface specs'!

metaSpec
        "UIPainter new openOnClass: self andSelector: #metaSpec"

        <resource: #canvas>
        ^#(#FullSpec 
                #window: 
                #(#WindowSpec 
                        #label: 'Unlabeled Canvas' 
                        #bounds: #(#Rectangle 27 249 325 334 ) ) 
                #component: 
                #(#SpecCollection 
                        #collection: #(
                                #(#RadioButtonSpec 
                                        #layout: #(#LayoutFrame 0 0 4 0 -1 0.575 20 0 ) 
                                        #name: #instanceSwitch 
                                        #model: #metaHolder 
                                        #callbacksSpec: 
                                        #(#UIEventCallbackSubSpec 
                                                #requestValueChangeSelector: #changeRequest ) 
                                        #label: 'instance' 
                                        #select: false ) 
                                #(#RadioButtonSpec 
                                        #layout: #(#LayoutFrame 1 0.575 4 0 -1 1 20 0 ) 
                                        #name: #classSwitch 
                                        #model: #metaHolder 
                                        #callbacksSpec: 
                                        #(#UIEventCallbackSubSpec 
                                                #requestValueChangeSelector: #changeRequest ) 
                                        #label: 'class' 
                                        #select: true ) ) ) )

    "Created: / 30.10.1997 / 19:07:29 / cg"
!

methodMoveDialogSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:SystemBrowser andSelector:#methodMoveDialogSpec
     SystemBrowser new openDialogInterface:#methodMoveDialogSpec
    "

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'move method'
              #'bounds:' #(#Rectangle 0 0 279 118)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#HorizontalPanelViewSpec
                    #'name:' 'horizontalPanelView'
                    #'layout:' #(#LayoutFrame 0 0.0 -35 1.0 0 1.0 -2 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#ActionButtonSpec
                              #'name:' 'actionButton2'
                              #'label:' 'cancel'
                              #'tabable:' true
                              #'model:' #cancel
                              #'extent:' #(#Point 133 27)
                          )
                           #(#ActionButtonSpec
                              #'name:' 'actionButton1'
                              #'label:' 'move'
                              #'tabable:' true
                              #'isDefault:' true
                              #'model:' #accept
                              #'extent:' #(#Point 134 27)
                          )
                        )
                    )
                    #'level:' 0
                    #'horizontalLayout:' #fitSpace
                    #'verticalLayout:' #center
                    #'horizontalSpace:' 4
                    #'verticalSpace:' 4
                )
                 #(#LabelSpec
                    #'name:' 'label'
                    #'layout:' #(#LayoutFrame 2 0 2 0 -2 1.0 25 0)
                    #'label:' 'move current method to which class:'
                    #'style:' 
                     #(#Font
                        'helvetica' 'medium'
                        'roman' 12
                    )
                    #'foregroundColor:' #(#Color 0.0 0.0 0.0)
                    #'backgroundColor:' #(#Color 66.9993 66.9993 66.9993)
                    #'adjust:' #left
                )
                 #(#ComboBoxSpec
                    #'name:' 'comboBox1'
                    #'layout:' #(#LayoutFrame 2 0 29 0 -2 1.0 51 0)
                    #'tabable:' true
                    #'model:' #className
                    #'comboList:' #classList
                )
              )
          )
      )

    "Created: 25.6.1997 / 13:45:20 / cg"
    "Modified: 25.6.1997 / 13:46:44 / cg"
! !

!SystemBrowser class methodsFor:'private helpers'!

showNoneFound
    super warn:(self classResources string:'None found.').
!

showNoneFound:what
    |rs|

    rs := self classResources.
    super information:((rs string:what) , (rs string:'...\\... none found.')) withCRs.
! !

!SystemBrowser class methodsFor:'private instance creation'!

newWithLabel:aString setupBlock:aBlock
    "common helper method for all creation methods"

    ^ self newWithLabel:aString setupBlock:aBlock onDevice:Screen current
!

newWithLabel:aString setupBlock:aBlock onDevice:aWorkstation
    "common helper method for all creation methods"

    |newBrowser|

    newBrowser := BrowserView onDevice:aWorkstation.
    newBrowser title:aString.
    aBlock value:newBrowser.

    newBrowser open.
    ^ newBrowser
!

newWithLabel:aString setupSelector:aSymbol arg:arg
    "common helper method for all creation methods"

    ^ self newWithLabel:aString setupSelector:aSymbol arg:arg onDevice:Screen current 
!

newWithLabel:aString setupSelector:aSymbol arg:arg onDevice:aWorkstation
    "common helper method for all creation methods"

    |newBrowser|

    newBrowser := BrowserView onDevice:aWorkstation.
    newBrowser title:aString.
    newBrowser perform:aSymbol with:arg.
    newBrowser open.
    ^ newBrowser
! !

!SystemBrowser class methodsFor:'special search startup'!

allCallsOn:aSelectorString
    "return a collection of methods which send aSelector."

    ^ self allCallsOn:#at:put: in:(Smalltalk allClasses)

    "
     SystemBrowser allCallsOn:#at:put:
    "

    "Created: 24.1.1997 / 19:42:57 / cg"
!

allCallsOn:aSelectorString in:aCollectionOfClasses
    "return a collection of methods which send aSelector.
     Methods from classes in aCollectionOfClasses are searched only."

    |sel searchBlock|

    ((aSelectorString ~= '*') 
     and:[aSelectorString includesMatchCharacters]) ifTrue:[
        "/ a matchString - need string matching procedure

        searchBlock := [:class :method :s |
                            |src|

                            method isLazyMethod ifTrue:[
                                src := method source.
                                (src notNil and:[src includesMatchString:aSelectorString]) ifTrue:[
                                    method makeRealMethod.
                                    (method literalsDetect:[:aLiteral|
                                        (aLiteral isMemberOf:Symbol) 
                                          and:[aSelectorString match:aLiteral]
                                    ] ifNone:nil) notNil
                                ] ifFalse:[
                                    false
                                ]
                            ] ifFalse:[
                                (method literalsDetect:[:aLiteral|
                                    (aLiteral isMemberOf:Symbol) 
                                      and:[aSelectorString match:aLiteral]
                                ] ifNone:nil) notNil
                            ]
                       ].
    ] ifFalse:[
        (aSelectorString = '*') ifTrue:[
            searchBlock := [:class :method :s | true].
        ] ifFalse:[
            "/ no matchString - can do it much faster

            sel := aSelectorString asSymbolIfInterned.
            sel isNil ifTrue:[
                ^ nil     "/ none
            ].
            searchBlock := [:class :method :s |
                                |src|

                                method isLazyMethod ifTrue:[
                                    src := method source.
                                    (src notNil and:[src includesString:sel]) ifTrue:[
                                        method makeRealMethod.
                                        method sends:sel.
                                    ] ifFalse:[
                                        false
                                    ]
                                ] ifFalse:[
                                    method sends:sel
                                ]
                           ].
        ]
    ].
    ^ self allMethodsIn:aCollectionOfClasses where:searchBlock

    "
     SystemBrowser allCallsOn:#at:put: in:(Smalltalk allClasses)
    "

    "Modified: 18.4.1997 / 10:32:50 / cg"
!

allMethodsIn:aCollectionOfClasses inst:wantInst class:wantClass where:aBlock
    "return a collection of methods which pass the given test.
     wantInst/wantClass control if instMethods and/or classMethods are to be
     considered.
     Only classes in aCollectionOfClasses are inspected in the search"

    |list|

    "
     since this may take a long time, lower my priority ...
    "
    Processor activeProcess 
        withPriority:Processor activePriority-1 to:Processor activePriority
    do:[
        |checkedClasses checkBlock|

        checkedClasses := IdentitySet new.
        list := OrderedCollection new.

        checkBlock := [:cls |
            (checkedClasses includes:cls) ifFalse:[
                cls isObsolete ifTrue:[
                    Transcript showCR:'skipping obsolete class: ' , cls displayString
                ] ifFalse:[
                    cls methodDictionary keysAndValuesDo:[:sel :method |
                        (aBlock value:cls value:method value:sel) ifTrue:[
                            list add:method "/ (cls name , ' ' , sel)
                        ]
                    ].
                    checkedClasses add:cls.
                ]
            ]
        ].

        aCollectionOfClasses do:[:aClass |
            "
             output disabled - it slows down things too much (when searching for
             implementors or senders)
            "
            wantInst ifTrue:[
"/                Transcript show:'searching '; show:aClass name; showCR:' ...'; endEntry.
                checkBlock value:aClass
            ].
            wantClass ifTrue:[
"/                Transcript show:'searching '; show:aClass class name; showCR:' ...'; endEntry.
                checkBlock value:(aClass class)
            ].
            Processor yield
        ]
    ].
    ^ list

    "Created: 24.1.1997 / 19:41:12 / cg"
!

allMethodsIn:aCollectionOfClasses where:aBlock
    "return a collection of methods which pass the given test.
     Only classes in aCollectionOfClasses are inspected in the search"

    ^ self
        allMethodsIn:aCollectionOfClasses 
        inst:true 
        class:true
        where:aBlock

    "Created: 24.1.1997 / 19:41:49 / cg"
!

aproposSearch:aString
    "browse all methods, which have aString in their selector or
     in the methods comment.
     This is relatively slow, since all source must be processed."

    ^ self aproposSearch:aString in:(Smalltalk allClasses)

!

aproposSearch:aString in:aCollectionOfClasses
    "browse all methods, which have aString in their selector or
     in the methods comment.
     This is relatively slow, since all source must be processed."

    |matchString list s searchBlock browser|

    matchString := '*' , aString , '*'.

    list := OrderedCollection new.

    (aString includesMatchCharacters) ifTrue:[
        s := '*' , aString , '*'.
        "a matchString"
        searchBlock := [:text | (text asCollectionOfLinesfindFirst:[:line | s match:line]) ~~ 0].
    ] ifFalse:[
        searchBlock := [:source | (source findString:aString) ~~ 0]
    ].

    browser := self browseMethodsIn:aCollectionOfClasses 
                     where:[:class :method :sel |
                                |comment|

                                Processor yield.
                                (searchBlock value:sel) ifTrue:[
                                    true
                                ] ifFalse:[
                                    comment := method comment.
                                    comment notNil 
                                    and:[searchBlock value:method comment]
                                ].
                           ]
                     title:(ClassResources string:'apropos: %1' with:aString).

    browser notNil ifTrue:[
        browser autoSearch:aString 
    ].
    ^ browser

    "
     SystemBrowser aproposSearch:'append' in:(Collection withAllSubclasses)
     SystemBrowser aproposSearch:'add'    in:(Collection withAllSubclasses)
     SystemBrowser aproposSearch:'sort'   in:(Collection withAllSubclasses)
     SystemBrowser aproposSearch:'[Aa]bsent' in:(Collection withAllSubclasses)
    "

    "Created: 9.12.1995 / 18:02:36 / cg"
!

browseAllCallsOn:aSelectorString
    "launch a browser for all senders of aSelector"

    ^ self browseAllCallsOn:aSelectorString in:(Smalltalk allClasses)

    "
     SystemBrowser browseAllCallsOn:#+
    "

    "Created: 9.12.1995 / 18:00:41 / cg"
    "Modified: 10.7.1996 / 10:26:15 / cg"
!

browseAllCallsOn:aSelectorString in:aSetOfClasses
    "launch a browser for all senders of aSelector"

    ^ self
        browseAllCallsOn:aSelectorString 
        in:aSetOfClasses
        title:(self classResources string:'senders of: %1' with:aSelectorString)

    "
     SystemBrowser browseAllCallsOn:#+ in:(Number withAllSubclasses)
    "

    "Created: 10.7.1996 / 10:25:49 / cg"
    "Modified: 24.1.1997 / 19:49:34 / cg"
!

browseAllCallsOn:aSelectorString in:aCollectionOfClasses title:title
    "launch a browser for all senders of aSelector in aCollectionOfClasses"

    |browser|

    browser := self
                browseMethods:(self allCallsOn:aSelectorString in:aCollectionOfClasses)
                title:title.

    browser notNil ifTrue:[
        |s|

        "
         kludge for now, if its a multipart selector,
         no easy search is (as yet) possible
        "
        s := aSelectorString.
        (s includes:$:) ifTrue:[
            s := s copyTo:(s indexOf:$:)
        ].
        browser autoSearch:s 
    ].
    ^ browser

    "
     SystemBrowser
        browseAllCallsOn:#+ 
        in:(Number withAllSubclasses) 
        title:'just a test'
    "

    "Modified: 24.1.1997 / 19:48:54 / cg"
!

browseCallsOn:aSelectorString under:aClass
    "launch a browser for all senders of aSelector in aClass and subclasses"

    ^ self 
        browseAllCallsOn:aSelectorString
                      in:(aClass withAllSubclasses)
                   title:(self classResources 
                                string:'senders of: %1 (in and below %2)'
                                with:aSelectorString 
                                with:aClass name)

    "
     SystemBrowser browseCallsOn:#+ under:Number
    "

    "Created: 9.12.1995 / 17:59:57 / cg"
    "Modified: 24.1.1997 / 19:50:33 / cg"
!

browseClassRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly
    "launch a browser for all methods in aClass where the classVar named
     aString is referenced; if modsOnly is true, browse only methods where the
     classvar is modified"

    ^ self browseRefsTo:aString classVars:true in:aCollectionOfClasses modificationsOnly:modsOnly
!

browseClassRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title
    "launch a browser for all methods in aCollectionOfClasses,
     where the classVar named aString is referenced; 
     if modsOnly is true, browse only methods where the classvar is modified"

    ^ self browseRefsTo:varName classVars:true in:aCollectionOfClasses modificationsOnly:modsOnly title:title
!

browseClassRefsTo:aString under:aClass modificationsOnly:modsOnly
    "launch a browser for all methods in aClass and subclasses
     where the classVar named aString is referenced; 
     if modsOnly is true, browse only methods where the classvar is modified"

    ^ self browseClassRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly

!

browseForResource:aResourceSymbol containing:item in:aCollectionOfClasses title:title
    "launch a browser for all methods which have a particular (or any, ifNil)
     resource in aCollectionOfClasses.
     If aKey is nonNil, only methods which have aKey in the (any) resourceSpec
     are parsed.
     I.e. to find all methods, which access the styleSheets, use:
        browseForResource:#style containing:nil in:... title:...
     to find methods which access the 'arrowButtonDownForm' styleSheet entry, use:
        browseForResource:#style containing:'arrowButtonDownForm' in:... title:..."

    |browser searchBlock|

    "/ search for any resource can be done without looking
    "/ at the source ...
    (aResourceSymbol isNil and:[item isNil]) ifTrue:[
        searchBlock := [:class :method :s | method hasResource]
    ] ifFalse:[
        searchBlock := [:class :method :s |
                            |rsrc val found|

                            found := false.
                            method hasResource ifTrue:[
                                rsrc := method resources.
                                rsrc notNil ifTrue:[
                                    aResourceSymbol isNil ifTrue:[
                                        item isNil ifTrue:[
                                            found := true
                                        ] ifFalse:[
                                            rsrc isCollection ifTrue:[
                                                rsrc keysAndValuesDo:[:rsrc :val |
                                                    val isCollection ifTrue:[
                                                        val do:[:v |
                                                            found := item match:v printString 
                                                        ]
                                                    ] ifFalse:[
                                                        found := item match:val printString 
                                                    ]
                                                ]
                                            ] ifFalse:[
                                                found := item match:rsrc printString
                                            ]
                                        ]
                                    ] ifFalse:[
                                        (rsrc includesKey:aResourceSymbol) ifTrue:[
                                            item isNil ifTrue:[
                                                found := true
                                            ] ifFalse:[
                                                rsrc isCollection ifTrue:[
                                                    val := rsrc at:aResourceSymbol.
                                                    val isCollection ifTrue:[
                                                        val do:[:v |
                                                            found := item match:v printString 
                                                        ]
                                                    ] ifFalse:[
                                                        found := item match:val printString 
                                                    ]
                                                ] ifFalse:[
                                                    found := item match:rsrc printString
                                                ]
                                            ]
                                        ]
                                    ]
                                ].
                            ].
                            found
                       ].
    ].

    browser := self browseMethodsIn:aCollectionOfClasses
                              where:searchBlock
                              title:title.
    browser notNil ifTrue:[
        browser autoSearch:'resource:' 
    ].
    ^ browser

    "
     SystemBrowser
        browseForResource:nil
        in:Smalltalk allClasses
        title:'methods with a resource'
    "
    "
     SystemBrowser
        browseForResource:#style
        containing:nil
        in:Smalltalk allClasses
        title:'methods with a #style resource'
    "
    "
     SystemBrowser
        browseForResource:#style
        containing:'arrowButton*'
        in:Smalltalk allClasses
        title:'methods with a #style resource'
    "

    "Modified: / 22.4.1998 / 10:29:20 / cg"
!

browseForResource:aResourceSymbol in:aCollectionOfClasses title:title
    "launch a browser for all methods which have a particular (or any, ifNil)
     resource in aCollectionOfClasses"

    ^ self
        browseForResource:aResourceSymbol
        containing:nil
        in:aCollectionOfClasses 
        title:title

    "
     SystemBrowser
        browseForResource:#style
        in:Smalltalk allClasses
        title:'methods accessing styleSheet values'
    "
    "
     SystemBrowser
        browseForResource:#keyboard
        in:Smalltalk allClasses
        title:'methods handling keyboard events'
    "
    "
     SystemBrowser
        browseForResource:nil
        in:Smalltalk allClasses
        title:'methods with a resource'
    "

    "Modified: 9.1.1997 / 12:44:38 / cg"
!

browseForString:aString
    "launch a browser for all methods containing a string in their source.
     This may be slow, since source-code has to be scanned."

    ^ self browseForString:aString in:(Smalltalk allClasses) ignoreCase:false

    "Modified: / 18.6.1998 / 16:42:39 / cg"
!

browseForString:aString in:aCollectionOfClasses
    "launch a browser for all methods in aCollectionOfClasses  
     containing a string in their source.
     This may be slow, since source-code has to be scanned."

    ^ self
        browseForString:aString 
        in:aCollectionOfClasses 
        ignoreCase:false

    "
     SystemBrowser browseForString:'all'      in:(Array with:Object)
     SystemBrowser browseForString:'should'   in:(Array with:Object)
     SystemBrowser browseForString:'[eE]rror' in:(Array with:Object)
    "

    "Created: / 9.12.1995 / 18:03:12 / cg"
    "Modified: / 18.6.1998 / 16:43:27 / cg"
!

browseForString:aString in:aCollectionOfClasses ignoreCase:ignoreCase
    "launch a browser for all methods in aCollectionOfClasses  
     containing a string in their source.
     This may be slow, since source-code has to be scanned."

    |browser searchBlock title s|

    title := self classResources string:'methods containing: %1' with:aString displayString.

    (aString includesMatchCharacters
    or:[ignoreCase]) ifTrue:[
        s := '*' , aString , '*'.
        "a matchString"
        searchBlock := [:c :m :sel | 
                            |src|       
                            src := m source.
                            src isNil ifTrue:[
                                ('Browser [info]: no source for ' , m printString) infoPrintCR.
                                false
                            ] ifFalse:[
                                s match:src ignoreCase:ignoreCase
                            ]
                       ]
    ] ifFalse:[
        searchBlock := [:c :m :sel | 
                            |src|

                            src := m source.
                            src isNil ifTrue:[
                                ('Browser [info]: no source for ' , m printString) infoPrintCR.
                                false
                            ] ifFalse:[
                                (src findString:aString) ~~ 0
                            ]
                       ]
    ].
    browser := self browseMethodsIn:aCollectionOfClasses where:searchBlock title:title.

    browser notNil ifTrue:[
        browser autoSearch:aString ignoreCase:ignoreCase
    ].
    ^ browser

    "
     SystemBrowser browseForString:'all'      in:(Array with:Object)
     SystemBrowser browseForString:'should'   in:(Array with:Object)
     SystemBrowser browseForString:'[eE]rror' in:(Array with:Object)
    "

    "Created: / 18.6.1998 / 16:42:50 / cg"
    "Modified: / 18.6.1998 / 16:51:25 / cg"
!

browseForSymbol:aSymbol
    "launch a browser for all methods referencing aSymbol"

    ^ self 
        browseForSymbol:aSymbol 
        title:(self classResources string:'users of: %1' with:aSymbol) 
        warnIfNone:true

    "Created: 9.12.1995 / 18:04:34 / cg"
    "Modified: 10.7.1996 / 10:35:34 / cg"
!

browseForSymbol:aSymbol in:aSetOfClasses title:title warnIfNone:doWarn
    "launch a browser for all methods referencing aSymbol"

    |browser searchBlock sym|

    (aSymbol includesMatchCharacters) ifTrue:[
        "a matchString"
        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (aLiteral isMemberOf:Symbol) 
                                  and:[aSymbol match:aLiteral]
                            ] ifNone:nil) notNil
                       ].
    ] ifFalse:[
        "
         can do a faster search
        "
        sym := aSymbol asSymbolIfInterned.
        sym isNil ifTrue:[
            self showNoneFound:title.
            ^ nil
        ].

        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (sym == aLiteral) 
                            ] ifNone:nil) notNil
                       ].
    ].
    doWarn ifFalse:[
        WarningSignal ignoreIn:[
            browser := self browseMethodsIn:aSetOfClasses where:searchBlock title:title.
        ]
    ] ifTrue:[
        browser := self browseMethodsIn:aSetOfClasses where:searchBlock title:title.
    ].
    browser notNil ifTrue:[
        browser autoSearch:aSymbol
    ].
    ^ browser

    "Modified: 24.6.1996 / 14:39:07 / stefan"
    "Modified: 30.6.1996 / 16:45:25 / cg"
    "Created: 10.7.1996 / 10:36:36 / cg"
!

browseForSymbol:aSymbol in:aSetOfClasses title:title warnIfNone:doWarn searchFor:searchString
    "launch a browser for all methods referencing aSymbol"

    |browser searchBlock sym|

    (aSymbol includesMatchCharacters) ifTrue:[
        "a matchString"
        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (aLiteral isMemberOf:Symbol) 
                                  and:[aSymbol match:aLiteral]
                            ] ifNone:nil) notNil
                       ].
    ] ifFalse:[
        "
         can do a faster search
        "
        sym := aSymbol asSymbolIfInterned.
        sym isNil ifTrue:[
            self showNoneFound:title.
            ^ nil
        ].

        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (sym == aLiteral) 
                            ] ifNone:nil) notNil
                       ].
    ].
    doWarn ifFalse:[
        WarningSignal ignoreIn:[
            browser := self browseMethodsIn:aSetOfClasses where:searchBlock title:title.
        ]
    ] ifTrue:[
        browser := self browseMethodsIn:aSetOfClasses where:searchBlock title:title.
    ].

    (browser notNil 
    and:[searchString notNil]) ifTrue:[
        browser autoSearch:searchString
    ].
    ^ browser

    "Modified: 24.6.1996 / 14:39:07 / stefan"
    "Modified: 30.6.1996 / 16:45:25 / cg"
    "Created: 31.10.1996 / 14:57:30 / cg"
!

browseForSymbol:aSymbol title:title ifNone:actionIfNoneFound searchFor:searchString
    "launch a browser for all methods referencing aSymbol"

    |browser searchBlock sym|

    (aSymbol includesMatchCharacters) ifTrue:[
        "a matchString"
        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (aLiteral isMemberOf:Symbol) 
                                  and:[aSymbol match:aLiteral]
                            ] ifNone:nil) notNil
                       ].
    ] ifFalse:[
        "
         can do a faster search
        "
        sym := aSymbol asSymbolIfInterned.
        sym isNil ifTrue:[
            actionIfNoneFound value.
            ^ nil
        ].

        searchBlock := [:c :m :s |
                            (m literalsDetect:[:aLiteral|
                                (sym == aLiteral) 
                            ] ifNone:nil) notNil
                       ].
    ].

    WarningSignal ignoreIn:[
        InformationSignal ignoreIn:[
            browser := self browseMethodsWhere:searchBlock title:title.
        ]
    ].
    browser isNil ifTrue:[
        actionIfNoneFound value
    ].

    (browser notNil 
    and:[searchString notNil]) ifTrue:[
        browser autoSearch:searchString
    ].
    ^ browser

    "Modified: 24.6.1996 / 14:39:07 / stefan"
    "Created: 31.10.1996 / 14:45:08 / cg"
    "Modified: 31.10.1996 / 14:46:07 / cg"
!

browseForSymbol:aSymbol title:title warnIfNone:doWarn
    "launch a browser for all methods referencing aSymbol"

    ^ self
        browseForSymbol:aSymbol 
        title:title 
        warnIfNone:doWarn 
        searchFor:aSymbol

    "Modified: 31.10.1996 / 14:45:38 / cg"
!

browseForSymbol:aSymbol title:title warnIfNone:doWarn searchFor:searchString
    "launch a browser for all methods referencing aSymbol"

    ^ self
        browseForSymbol:aSymbol 
        title:title 
        ifNone:(doWarn ifTrue:[[self showNoneFound:title]] ifFalse:nil) 
        searchFor:searchString
!

browseImplementorsOf:aSelectorString
    "launch a browser for all implementors of aSelector"

    ^ self browseImplementorsOf:aSelectorString in:(Smalltalk allClasses)

    "
     SystemBrowser browseImplementorsOf:#+
    "

    "Created: 9.12.1995 / 18:01:18 / cg"
    "Modified: 10.7.1996 / 10:21:26 / cg"
!

browseImplementorsOf:aSelectorString in:aSetOfClasses
    "launch a browser for all implementors of aSelector"

    ^ self browseImplementorsOf:aSelectorString
                             in:aSetOfClasses
                          title:(self classResources string:'implementors of: %1' with:aSelectorString)

    "
     SystemBrowser browseImplementorsOf:#+ in:(Number withAllSubclasses)
    "

    "Created: 10.7.1996 / 10:20:59 / cg"
    "Modified: 10.7.1996 / 10:21:49 / cg"
!

browseImplementorsOf:aSelectorString in:aCollectionOfClasses title:title
    "launch a browser for all implementors of aSelector in
     the classes contained in aCollectionOfClasses and its metaclasses"

    |list sel srchST srchJava|

    list := IdentitySet new.

    ((aSelectorString ~= '*') and:[aSelectorString includesMatchCharacters]) ifTrue:[
        "a matchString"

        srchST := [:aSelector :aMethod |
                        (aSelectorString match:aSelector) ifTrue:[
                            list add:aMethod
                        ]
                  ].
        srchJava := [:aSelector :aMethod |
                        (aMethod name match:aSelector) ifTrue:[
                            list add:aMethod
                        ]
                  ].

        aCollectionOfClasses do:[:aClass |
            |srchBlock|

            aClass isObsolete ifFalse:[
                aClass isJavaClass ifTrue:[
                    srchBlock := srchJava
                ] ifFalse:[
                    srchBlock := srchST
                ].
                aClass methodDictionary keysAndValuesDo:srchBlock.
                aClass isMeta ifFalse:[
                    aClass class methodDictionary keysAndValuesDo:srchBlock
                ]
            ]
        ]
    ] ifFalse:[
        "can do a faster search"

        sel := aSelectorString asSymbolIfInterned.
        sel isNil ifTrue:[
            self showNoneFound:title.
            ^ nil
        ].

        srchJava := [:aSelector :aMethod |
                        "/ allow search for signature AND
                        "/ search for plain name
                        ((aMethod name = sel)
                        or:[aSelector == sel]) ifTrue:[
                            list add:aMethod
                        ]
                  ].

        aCollectionOfClasses do:[:aClass |
            |mthd|

            aClass isObsolete ifFalse:[
                aClass isJavaClass ifTrue:[
                    aClass methodDictionary keysAndValuesDo:srchJava.
                    aClass isMeta ifFalse:[
                        aClass class methodDictionary keysAndValuesDo:srchJava
                    ]
                ] ifFalse:[
                    mthd := aClass compiledMethodAt:sel ifAbsent:nil.
                    mthd notNil ifTrue:[
                        list add:mthd
                    ].
                    aClass isMeta ifFalse:[
                        mthd := aClass class compiledMethodAt:sel ifAbsent:nil.
                        mthd notNil ifTrue:[
                            list add:mthd
                        ]
                    ]
                ]
            ]
        ]
    ].
    ^ self browseMethods:list asOrderedCollection title:title

    "
     SystemBrowser browseImplementorsOf:#+
                                     in:(Array with:Number
                                               with:Float
                                               with:SmallInteger)
                                  title:'some implementors of +'
    "

    "Modified: / 4.9.1995 / 17:33:39 / claus"
    "Modified: / 19.6.1996 / 14:19:02 / stefan"
    "Modified: / 16.10.1998 / 13:16:29 / cg"
!

browseImplementorsOf:aSelectorString under:aClass
    "launch a browser for all implementors of aSelector in aClass
     and its subclasses"

    ^ self browseImplementorsOf:aSelectorString
                             in:(aClass withAllSubclasses)
                          title:(self classResources string:'implementors of: %1 (in and below %2)' 
                                                with:aSelectorString
                                                with:aClass name)

    "
     SystemBrowser browseImplementorsOf:#+ under:Integer
    "

    "Created: 9.12.1995 / 18:06:09 / cg"
    "Modified: 9.12.1995 / 18:11:38 / cg"
!

browseInstRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly
    "launch a browser for all methods in aClass where the instVar named
     aString is referenced; if modsOnly is true, browse only methods where the
     instvar is modified"

    ^ self browseRefsTo:aString classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly
!

browseInstRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title
    "launch a browser for all methods in aClass where the instVar named
     varName is referenced; if modsOnly is true, browse only methods where the
     instvar is modified"

    ^ self browseRefsTo:varName classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly title:title
!

browseInstRefsTo:aString under:aClass modificationsOnly:modsOnly
    "launch a browser for all methods in aClass and subclasses
     where the instVar named aString is referenced; 
     if modsOnly is true, browse only methods where the instvar is modified"

    ^ self browseInstRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly
!

browseReferendsOf:aGlobalName
    "launch a browser for all methods referencing a global
     named aGlobalName. The argument may be a symbol, a string or
     a matchPattern.
    "

    ^ self browseReferendsOf:aGlobalName warnIfNone:true 

   "
    Browser browseReferendsOf:#Transcript
    Browser browseReferendsOf:'Tr*'
   "

    "Modified: / 30.10.1997 / 23:45:52 / cg"
!

browseReferendsOf:aGlobalName ifNone:actionIfNone
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    ^ self
        browseReferendsOf:aGlobalName 
        title:(self classResources string:'users of: %1' with:aGlobalName)
        ifNone:actionIfNone

    "Modified: / 31.10.1997 / 15:42:05 / cg"


!

browseReferendsOf:aGlobalName in:aSetOfClasses
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    ^ self browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:true 

   "
    Browser browseReferendsOf:#Transcript
   "

    "Created: 10.7.1996 / 10:37:30 / cg"
!

browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:doWarn
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    |globalsPlainName idx|

    globalsPlainName := aGlobalName.
    (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
        globalsPlainName := globalsPlainName copyFrom:idx+1
    ].

    ^ self browseForSymbol:aGlobalName
                        in:aSetOfClasses
                     title:(self classResources string:'users of: %1' with:aGlobalName) 
                warnIfNone:doWarn
                 searchFor:globalsPlainName

    "Created: 10.7.1996 / 10:37:02 / cg"
    "Modified: 31.10.1996 / 14:56:38 / cg"
!

browseReferendsOf:aGlobalName title:title ifNone:actionIfNone
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    |globalsPlainName idx|

    globalsPlainName := aGlobalName.
    (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
        globalsPlainName := globalsPlainName copyFrom:idx+1.
        (globalsPlainName size == 0
        or:[globalsPlainName = '*']) ifTrue:[
            globalsPlainName := aGlobalName
        ]
    ].

    ^ self browseForSymbol:aGlobalName 
                     title:title 
                    ifNone:actionIfNone
                 searchFor:globalsPlainName

    "Modified: / 31.10.1996 / 14:47:48 / cg"
    "Created: / 31.10.1997 / 15:41:28 / cg"


!

browseReferendsOf:aGlobalName title:title warnIfNone:doWarn
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    ^ self
        browseReferendsOf:aGlobalName 
        title:title 
        ifNone:(doWarn ifTrue:[[self showNoneFound:title]] ifFalse:nil)

!

browseReferendsOf:aGlobalName warnIfNone:doWarn
    "launch a browser for all methods referencing a global
     named aGlobalName.
    "

    ^ self
        browseReferendsOf:aGlobalName 
        title:(self classResources string:'users of: %1' with:aGlobalName)
        warnIfNone:doWarn

    "Modified: / 31.10.1997 / 15:42:05 / cg"
!

browseRefsTo:aString classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly
    "launch a browser for all methods in aClass where the instVar/classVar named
     aString is referenced; if modsOnly is true, browse only methods where the
     instvar is modified"

    |title|

    modsOnly ifTrue:[
        title := 'modifications of: %1'
    ] ifFalse:[
        title := 'references to: %1 '
    ].
    ^ self 
        browseRefsTo:aString 
        classVars:classVars 
        in:aCollectionOfClasses 
        modificationsOnly:modsOnly 
        title:(self classResources string:title with:aString)

    "Created: 9.12.1995 / 18:07:05 / cg"
    "Modified: 9.12.1995 / 18:11:49 / cg"
!

browseRefsTo:varName classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly title:title
    "launch a browser for all methods in aClass where the instVar/classVar named
     varName is referenced; if modsOnly is true, browse only methods where the
     instvar is modified"

    |filter browser pattern|

    filter := self filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly.
    browser := self browseMethodsIn:aCollectionOfClasses 
			inst:true class:classVars where:filter title:title.

    browser notNil ifTrue:[
	modsOnly ifTrue:[
	    pattern := varName , ' :='
	] ifFalse:[
	    pattern := varName
	].
	browser autoSearch:pattern 
    ].
    ^ browser
!

browseSuperCallsIn:aCollectionOfClasses title:title
    "launch a browser for all super sends in aCollectionOfClasses"

    |browser searchBlock|

    searchBlock := [:class :method :s | 
        |src parser|

        src := method source.
        (src notNil and:[src findString:'super']) ~~ 0 ifTrue:[
            parser := Parser 
                        parseMethod:src 
                        in:class 
                        ignoreErrors:true 
                        ignoreWarnings:true.

            parser notNil and:[parser usesSuper]
        ] ifFalse:[
            false
        ]
    ].

    browser := self browseMethodsIn:aCollectionOfClasses
                              where:searchBlock
                              title:title.

    browser notNil ifTrue:[
        browser autoSearch:'super' 
    ].
    ^ browser

    "
     SystemBrowser
         browseSuperCallsIn:(Array with:SortedCollection)
                      title:'superSends in SortedCollection'
    "

    "Created: 23.11.1995 / 14:08:55 / cg"
    "Modified: 24.4.1996 / 13:25:31 / cg"
!

browseSuperCallsUnder:aClass
    "launch a browser for all supersends in aClass and subclasses"

    ^ self browseSuperCallsIn:(aClass withAllSubclasses)
                        title:(self classResources string:'supersends (in and below %1)' with:aClass name)

    "
     SystemBrowser browseSuperCallsUnder:Number
    "

    "Created: 23.11.1995 / 12:06:06 / cg"
    "Modified: 9.12.1995 / 18:11:59 / cg"
!

browseUsesOf:aClass
    |dict owners offsets
     sz  "{ Class: SmallInteger }"
     n   "{ Class: SmallInteger }"
     removeSet newDict|

    owners := ObjectMemory whoReferencesInstancesOf:aClass.

    "
     collect set of offsets in dict; key is class
    "
    dict := IdentityDictionary new.
    owners do:[:someObject |
	|cls create|

	someObject isContext ifFalse:[
	    "
	     someObject refers to an instance of aClass;
	     find out, which instVar(s)
	    "
	    cls := someObject class.
	    cls ~~ Array ifTrue:[
		n := cls instSize.
		create := [|s| s := Set new. dict at:cls put:s. s].

		1 to:n do:[:i |
		    |ref|

		    ref := someObject instVarAt:i.
		    (ref isMemberOf:aClass) ifTrue:[
			offsets := dict at:cls ifAbsent:create.
			offsets add:i.
		    ]
		].
		cls isVariable ifTrue:[
		    cls isPointers ifTrue:[
			| idx "{ Class: SmallInteger }" |

			sz := someObject basicSize.
			idx := 1.
			[idx <= sz] whileTrue:[
			    |ref|

			    ref := someObject basicAt:idx.
			    (ref isMemberOf:aClass) ifTrue:[
				offsets := dict at:cls ifAbsent:create.
				offsets add:0.
				idx := sz
			    ].
			    idx := idx + 1
			]
		    ]        
		]
	    ]
	]
    ].

    "
     merge with superclass refs
    "
    dict keysAndValuesDo:[:cls :set |
	cls allSuperclasses do:[:aSuperclass |
	    |superSet|

	    superSet := dict at:aSuperclass ifAbsent:[].
	    superSet notNil ifTrue:[
		|removeSet|

		superSet := dict at:aSuperclass.
		removeSet := Set new.
		set do:[:offset |
		    (superSet includes:offset) ifTrue:[
			removeSet add:offset
		    ]
		].
		set removeAll:removeSet
	    ]
	]
    ].

    "
     remove empty ones
    "
    removeSet := Set new.
    dict keysAndValuesDo:[:cls :set |
	set isEmpty ifTrue:[
	    removeSet add:cls
	]
    ].
    removeSet do:[:cls |
	dict removeKey:cls
    ].

    "
     replace the indices by real names
    "
    newDict := IdentityDictionary new.
    dict keysAndValuesDo:[:cls :set |
	|newSet names|

	names := cls allInstVarNames.
	newSet := set collect:[:index | 
		index == 0 ifTrue:['*indexed*'] ifFalse:[names at:index].
	].
	newDict at:cls put:newSet
    ].

    newDict inspect


!

filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly
    "return a searchblock for variable references"

    |searchBlock|

    searchBlock := [:c :m :s |
        |src result parser vars needMatch|

        needMatch := varName includesMatchCharacters.

        src := m source.
        src isNil ifTrue:[
            result := false
        ] ifFalse:[
            needMatch ifFalse:[
                "
                 before doing a slow parse, quickly scan the
                 methods source for the variables name ...
                "
                result := (src findString:varName) ~~ 0.
            ] ifTrue:[
                result := true.
            ].
            result ifTrue:[
                result := false.
                parser := Parser
                                parseMethod:src 
                                in:c 
                                ignoreErrors:true 
                                ignoreWarnings:true.

                (parser notNil and:[parser ~~ #Error]) ifTrue:[
                    classVars ifFalse:[
                        modsOnly ifTrue:[
                            vars := parser modifiedInstVars
                        ] ifFalse:[
                            vars := parser usedInstVars
                        ].
                    ] ifTrue:[    
                        modsOnly ifTrue:[
                            vars := parser modifiedClassVars
                        ] ifFalse:[
                            vars := parser usedClassVars
                        ].
                    ].
                    vars size > 0 ifTrue:[
                        needMatch ifTrue:[
                            vars do:[:cv |
                                (varName match:cv) ifTrue:[result := true]
                            ]
                        ] ifFalse:[
                            result := vars includes:varName
                        ]
                    ]
                ].
            ].
        ].
        Processor yield.
        result
    ].
    ^ searchBlock

    "Modified: 19.6.1997 / 18:27:57 / cg"
! !

!SystemBrowser class methodsFor:'startup'!

browseAllSelect:aBlock
    "launch a browser for all methods where aBlock returns true.
     The block is called with 3 arguments, class, method and selector."

    ^ self 
        browseMethodsWhere:aBlock 
        title:'selected messages'

    "
     SystemBrowser browseAllSelect:[:aClass :aMethod :selector | selector numArgs == 3]
    "

    "Modified: 24.1.1997 / 19:45:05 / cg"
!

browseClass:aClass
    "launch a browser for aClass"

    ^ self 
        newWithLabel:aClass name
        setupSelector:#setupForClass:
        arg:aClass

    "
     SystemBrowser browseClass:Object
    "

    "Modified: 24.1.1997 / 19:45:16 / cg"
!

browseClass:aClass methodCategory:aCategory
    "launch a browser for all methods under aCategory in aClass"

    ^ self newWithLabel:(aClass name , ' ' , aCategory)
          setupBlock:[:browser | browser setupForClass:aClass methodCategory:aCategory]

    "
     SystemBrowser browseClass:String methodCategory:'copying'
    "

    "Modified: 24.1.1997 / 19:45:23 / cg"
!

browseClass:aClass selector:selector
    "launch a browser for the method at selector in aClass"

    ^ self 
	newWithLabel:(aClass name , ' ' , selector , ' ' , selector)
	setupBlock:[:newBrowser | newBrowser setupForClass:aClass selector:selector]

    "
     SystemBrowser browseClass:Object selector:#printString
    "
!

browseClassCategory:aClassCategory
    "launch a browser for all classes under aCategory"

    ^ self 
        newWithLabel:aClassCategory
        setupSelector:#setupForClassCategory:
        arg:aClassCategory

    "
     SystemBrowser browseClassCategory:'Kernel-Objects'
    "

    "Modified: 24.1.1997 / 19:45:32 / cg"
!

browseClassHierarchy:aClass
    "launch a browser for aClass and all its superclasses.
     this is different from the fullProtocol browser."

    ^ self 
	newWithLabel:(aClass name , '-' , 'hierarchy')
	setupSelector:#setupForClassHierarchy:
	arg:aClass

    "
     SystemBrowser browseClassHierarchy:Number
    "
!

browseClasses:aList title:title
    "launch a browser for all classes in aList"

    ^ self 
        newWithLabel:title
        setupBlock:[:b | b setupForClassList:aList sort:true]

    "
     SystemBrowser browseClasses:(Array with:Object
                                        with:Float)
                           title:'two classes'
    "

    "Modified: 28.5.1996 / 13:52:25 / cg"
!

browseClasses:aList title:title sort:doSort
    "launch a browser for all classes in aList"

    ^ self 
        newWithLabel:title
        setupBlock:[:b | b setupForClassList:aList sort:doSort]

    "
     SystemBrowser browseClasses:(Array with:Object
                                        with:Float)
                           title:'two classes'
    "

    "Created: 28.5.1996 / 13:52:09 / cg"
!

browseFullClassProtocol:aClass
    "launch a browser for aClasses full protocol.
     This is different from hierarchy browsing."

    ^ self 
	newWithLabel:(aClass name , '-' , 'full protocol')
	setupSelector:#setupForFullClassProtocol:
	arg:aClass

    "
     SystemBrowser browseFullClassProtocol:Number
    "
!

browseFullClasses
    "launch a browser showing all methods at once"

    ^ self 
	newWithLabel:'Full Class Browser'
	setupBlock:[:newBrowser | newBrowser setupForFullClass]

    "SystemBrowser browseFullClasses"
!

browseInstMethodsFrom:aClass where:aBlock title:title
    "launch a browser for all instance methods in aClass and all subclasses
     where aBlock evaluates to true"

    ^ self      
        browseMethodsIn:(aClass withAllSubclasses) 
        inst:true 
        class:false 
        where:aBlock 
        title:title

    "Modified: 24.1.1997 / 19:44:45 / cg"
!

browseInstMethodsIn:aCollectionOfClasses where:aBlock title:title
    "launch a browser for all instance methods of all classes in
     aCollectionOfClasses where aBlock evaluates to true"

    ^ self 
        browseMethodsIn:aCollectionOfClasses 
        inst:true class:false 
        where:aBlock title:title

    "Modified: 24.1.1997 / 19:43:41 / cg"
!

browseInstMethodsOf:aClass where:aBlock title:title
    "launch a browser for all instance methods in aClass
     where aBlock evaluates to true"

    ^ self 
        browseMethodsIn:(Array with:aClass) 
        inst:true 
        class:false 
        where:aBlock title:title

    "Modified: 24.1.1997 / 19:43:50 / cg"
!

browseMethodCategory:aCategory
    "launch a browser for all methods where category = aCategory"

    |searchBlock|

    aCategory includesMatchCharacters ifTrue:[
	searchBlock := [:c :m :s | aCategory match:m category].
    ] ifFalse:[
	searchBlock := [:c :m :s | m category = aCategory]
    ].

    self browseMethodsWhere:searchBlock title:('all methods with category of ' , aCategory)

    "
     SystemBrowser browseMethodCategory:'printing & storing'
     SystemBrowser browseMethodCategory:'print*'
    "
!

browseMethods:aList title:aString
    "launch a browser for an explicit list of class/selectors.
     Each entry in the list can be either a method, or a string
     consisting of the classes name and the selector, separated by spaces. 
     For class methods, the string ' class' must be appended to the classname."

    ^ self
        browseMethods:aList
        title:aString
        sort:true


    "
     SystemBrowser 
        browseMethods:#('Object printOn:' 'Collection add:')
        title:'some methods'

     SystemBrowser 
        browseMethods:#('Behavior new:' 'Setclass new:')
        title:'some new: methods'

     SystemBrowser 
        browseMethods:(Array with:(Object compiledMethodAt:#printOn:)
                             with:(Collection compiledMethodAt:#add:)
                             with:(Object class compiledMethodAt:#initialize))
        title:'some methods'

    "

    "Modified: 1.11.1996 / 16:30:17 / cg"
!

browseMethods:aList title:aString sort:doSort
    "launch a browser for an explicit list of class/selectors.
     Each entry in the list can be either a method, or a string
     consisting of the classes name and the selector, separated by spaces. 
     For class methods, the string ' class' must be appended to the classname."

    |l|

    (aList size == 0) ifTrue:[
        self showNoneFound:aString.
        ^ nil
    ].
    l := aList asOrderedCollection.
    l := l collect:[:entry |
        |who cls clsName|

        entry isString ifTrue:[
            entry
        ] ifFalse:[
            who := entry who.
            who isNil ifTrue:[
                '??? unbound'
            ] ifFalse:[
                cls := who methodClass.
                cls isNil ifTrue:[
                    '??? unbound'
                ] ifFalse:[
                    cls isJavaClass ifTrue:[
                        clsName := 'JAVA::' , cls fullName 
                    ] ifFalse:[
                        clsName := cls name
                    ].
                    clsName
                    , ' ' 
                    , (entry printStringForBrowserWithSelector:(who methodSelector))
                ]
            ]
        ]
      ].
        
    doSort ifTrue:[l sort].

    ^ self 
        newWithLabel:aString
        setupSelector:#setupForList:
        arg:l 

    "
     SystemBrowser 
        browseMethods:#('Object printOn:' 'Collection add:')
        title:'some methods'

     SystemBrowser 
        browseMethods:#('Behavior new:' 'Setclass new:')
        title:'some new: methods'

     SystemBrowser 
        browseMethods:(Array with:(Object compiledMethodAt:#printOn:)
                             with:(Collection compiledMethodAt:#add:)
                             with:(Object class compiledMethodAt:#initialize))
        title:'some methods'

    "

    "Modified: / 17.6.1996 / 17:07:46 / stefan"
    "Modified: / 17.10.1998 / 11:25:53 / cg"
!

browseMethodsFrom:aClass where:aBlock title:title
    "launch a browser for all instance- and classmethods in aClass
     and all its subclasses where aBlock evaluates to true.
     The block is called with 3 arguments, class, method and seelctor."

    ^ self 
        browseMethodsIn:(aClass withAllSubclasses) 
        where:aBlock 
        title:title

    "Modified: 24.1.1997 / 19:44:00 / cg"
!

browseMethodsIn:aCollectionOfClasses inst:wantInst class:wantClass where:aBlock title:title
    "launch a browser for all instance- (if wantInst is true) and/or
     classmethods (if wantClass is true) from classes in aCollectionOfClasses,
     where aBlock evaluates to true.
     The block is called with 3 arguments, class, method and selector."

    |list|

    "
     since this may take a long time, lower my priority ...
    "
    Processor activeProcess 
        withPriority:Processor activePriority-1 to:Processor activePriority
    do:[
        |checkedClasses checkBlock|

        checkedClasses := IdentitySet new.
        list := OrderedCollection new.

        checkBlock := [:cls |
            (checkedClasses includes:cls) ifFalse:[
                cls isObsolete ifTrue:[
                    Transcript showCR:'skipping obsolete class: ' , cls displayString
                ] ifFalse:[
                    cls methodDictionary keysAndValuesDo:[:sel :method |
                        (aBlock value:cls value:method value:sel) ifTrue:[
                            list add:method "/ (cls name , ' ' , sel)
                        ]
                    ].
                    checkedClasses add:cls.
                ]
            ]
        ].

        aCollectionOfClasses do:[:aClass |
            aClass isObsolete ifFalse:[
                "
                 output disabled - it slows down things too much (when searching for
                 implementors or senders)
                "
                wantInst ifTrue:[
"/                Transcript show:'searching '; show:aClass name; showCR:' ...'; endEntry.
                    checkBlock value:aClass
                ].
                wantClass ifTrue:[
"/                Transcript show:'searching '; show:aClass class name; showCR:' ...'; endEntry.
                    checkBlock value:(aClass class)
                ].
                Processor yield
            ]
        ]
    ].
    ^ self browseMethods:list title:title

    "Created: 10.12.1995 / 15:34:57 / cg"
    "Modified: 7.6.1996 / 08:47:54 / stefan"
    "Modified: 15.7.1996 / 11:48:10 / cg"
!

browseMethodsIn:aCollectionOfClasses where:aBlock title:title
    "launch a browser for all instance- and classmethods from 
     all classes in aCollectionOfClasses where aBlock evaluates to true.
     The block is called with 3 arguments, class, method and seelctor."

    ^ self 
        browseMethodsIn:aCollectionOfClasses 
        inst:true 
        class:true 
        where:aBlock 
        title:title

    "Modified: 24.1.1997 / 19:44:17 / cg"
!

browseMethodsOf:aClass where:aBlock title:title
    "launch a browser for all instance- and classmethods in aClass 
     where aBlock evaluates to true.
     The block is called with 3 arguments, class, method and seelctor."

    ^ self browseMethodsIn:(Array with:aClass) where:aBlock title:title
!

browseMethodsWhere:aBlock title:title
    "launch a browser for all methods where aBlock returns true.
     The block is called with 3 arguments, class, method and seelctor."

    ^ self 
        browseMethodsIn:(Smalltalk allClasses) 
        where:aBlock 
        title:title

    "Modified: 24.1.1997 / 19:44:30 / cg"
! !

!SystemBrowser class methodsFor:'startup with query'!

askThenBrowseClass
    self getClassThenPerform:#browseClass:

    "
     SystemBrowser askThenBrowseClass
    "
!

askThenBrowseClassHierarchy
    self getClassThenPerform:#browseClassHierarchy:

    "
     SystemBrowser askThenBrowseClassHierarchy
    "
!

askThenBrowseFullClassProtocol
    self getClassThenPerform:#browseFullClassProtocol:

    "
     SystemBrowser askThenBrowseFullClassProtocol
    "
!

getClassThenPerform:aSelector
    |enterBox|

    enterBox := EnterBox title:(self classResources at:'Browse which class:') withCRs.
    enterBox okText:(ClassResources at:'browse').
    enterBox entryCompletionBlock:[:contents |
	|s what m|

	s := contents withoutSpaces.
	what := Smalltalk classnameCompletion:s.
	enterBox contents:what first.
    ].
    enterBox action:[:className |
	|cls|

	cls := Smalltalk classNamed:className.
	cls isNil ifTrue:[
	    self warn:(ClassResources at:'no such class').
	] ifFalse:[
	    self perform:aSelector with:cls  
	]
    ].
    enterBox showAtPointer

    "
     SystemBrowser getClassThenPerform:#browseClass:
    "
! !

!SystemBrowser class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.94 1999-09-23 12:15:54 cg Exp $'
! !
SystemBrowser initialize!