#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 10 May 2018 12:24:31 +0200
changeset 6317 162eab34215c
parent 6316 9c60c63d8333
child 6318 8cf42e7015f5
#FEATURE by cg class: Workspace added: #browseClassesContainingInName #browseClassesContainingInName: #browseClassesContainingItInName #browseMethodsContainingInSource #browseMethodsContainingInSource: #browseMethodsContainingItInSource #browseReferencesTo #browseReferencesTo: comment/format in: #browseReferencesToIt changed: #editMenu
Workspace.st
--- a/Workspace.st	Wed May 09 19:38:12 2018 +0200
+++ b/Workspace.st	Thu May 10 12:24:31 2018 +0200
@@ -1593,6 +1593,45 @@
     "Modified: / 26.9.2001 / 17:37:35 / cg"
 !
 
+browseClassesContainingInName
+    "ask for a piece of text and 
+     open a browser on all classes where that piece is contained in the name"
+
+    |pieceOfText|
+
+    pieceOfText := Dialog request:'Browse classes containing in name:'.
+    pieceOfText isEmptyOrNil ifTrue:[^ self].
+
+    self browseClassesContainingInName:pieceOfText
+!
+
+browseClassesContainingInName:pieceOfText
+    "open a browser on all classes where that piece is contained in the name"
+
+    |classes|
+
+    classes := Smalltalk allClasses 
+                select:[:cls | cls name includesString:pieceOfText caseSensitive:false].
+
+    SystemBrowser default
+        openOnClassesForWhich:[:cls | cls name includesString:pieceOfText caseSensitive:false]
+        label:('Classes with "%1" in name' bindWith:pieceOfText)
+!
+
+browseClassesContainingItInName
+    "open a browser on all classes where the selected text is contained in the name"
+
+    |selectedText|
+
+    selectedText := self selectedTextOrSyntaxElement.
+    selectedText notEmptyOrNil ifTrue:[
+        selectedText := selectedText withoutSeparators.
+        selectedText notEmpty ifTrue:[
+            self browseClassesContainingInName:selectedText.
+        ]
+    ].
+!
+
 browseImplementorsOfIt
     "open a browser on the implementors of the selected text,
      or - if I support syntax elements, on the syntax element at the cursor position"
@@ -1809,87 +1848,143 @@
     "Modified: / 26.9.2001 / 17:38:06 / cg"
 !
 
-browseReferencesToIt
+browseMethodsContainingInSource
+    "ask for a piece of text and 
+     open a browser on all methods where that piece is contained in the source"
+
+    |pieceOfText|
+
+    pieceOfText := Dialog request:'Browse methods containing in source:'.
+    pieceOfText isEmptyOrNil ifTrue:[^ self].
+
+    self browseMethodsContainingInSource:pieceOfText
+!
+
+browseMethodsContainingInSource:pieceOfText
+    "open a browser on all methods where that piece is contained in the source"
+
+    (SystemBrowser default
+        browseMethodsForWhich:[:m | 
+            (m source ? '') includesString:pieceOfText caseSensitive:false 
+        ]
+        title:('Methods containing "%1"' bindWith:pieceOfText)
+    ) autoSearch:pieceOfText ignoreCase:true 
+!
+
+browseMethodsContainingItInSource
+    "open a browser on all methods where the selected text is contained in the source"
+
+    |selectedText|
+
+    selectedText := self selectedTextOrSyntaxElement.
+    selectedText notEmptyOrNil ifTrue:[
+        selectedText := selectedText withoutSeparators.
+        selectedText notEmpty ifTrue:[
+            self browseMethodsContainingInSource:selectedText.
+        ]
+    ].
+!
+
+browseReferencesTo
+    "ask for a name and 
+     open a browser on all references to the selected global, poolvar or namespace class"
+
+    |nameOfVariable|
+
+    nameOfVariable := Dialog request:'Browse references to:'.
+    nameOfVariable isEmptyOrNil ifTrue:[^ self].
+
+    self browseReferencesTo:nameOfVariable
+!
+
+browseReferencesTo:nameOfVariable
     "open a browser on all references to the selected global, poolvar or namespace class"
 
-    |nameOfVariable browserClass sym cls|
-
-    nameOfVariable := self selectedTextOrSyntaxElement.
-    nameOfVariable notEmptyOrNil ifTrue:[
-        nameOfVariable := nameOfVariable string asString.
-        nameOfVariable := nameOfVariable asSingleByteStringIfPossible.
-
-        browserClass := SystemBrowser default.
-        self windowGroup withWaitCursorDo:[
-            |nonMeta privateClass|
-
-            (nameOfVariable startsWith:'#') ifTrue:[
-                sym := (nameOfVariable copyFrom:2) asSymbolIfInterned.
-                browserClass browseForSymbol:sym.
-            ] ifFalse:[
-                "/ is it a class variable?
-                ((cls := self editedClass) notNil
-                and:[ ((nonMeta := cls theNonMetaclass) allClassVarNames includes:nameOfVariable) ]) ifTrue:[
-                    nonMeta isSharedPool ifTrue:[
-                        "/ class is a pool - browse all references to it.
-                        browserClass browseReferendsOf:(nonMeta name,':',nameOfVariable)
-                    ] ifFalse:[
-                        browserClass
-                            browseRefsTo:nameOfVariable
-                            classVars:true
-                            in:(nonMeta whichClassDefinesClassVar:nameOfVariable) withAllSubclasses
-                            modificationsOnly:false.
-                    ].
+    |browserClass sym cls|
+
+    browserClass := SystemBrowser default.
+    self windowGroup withWaitCursorDo:[
+        |nonMeta privateClass|
+
+        (nameOfVariable startsWith:'#') ifTrue:[
+            sym := (nameOfVariable copyFrom:2) asSymbolIfInterned.
+            browserClass browseForSymbol:sym.
+        ] ifFalse:[
+            "/ is it a class variable?
+            ((cls := self editedClass) notNil
+            and:[ ((nonMeta := cls theNonMetaclass) allClassVarNames includes:nameOfVariable) ]) ifTrue:[
+                nonMeta isSharedPool ifTrue:[
+                    "/ class is a pool - browse all references to it.
+                    browserClass browseReferendsOf:(nonMeta name,':',nameOfVariable)
                 ] ifFalse:[
-                    "/ is it a private class?
-                    (cls notNil
-                    and:[ (privateClass := cls theNonMetaclass privateClassNamed:nameOfVariable) notNil ]) ifTrue:[
-                        browserClass browseReferendsOf:(privateClass name)
+                    browserClass
+                        browseRefsTo:nameOfVariable
+                        classVars:true
+                        in:(nonMeta whichClassDefinesClassVar:nameOfVariable) withAllSubclasses
+                        modificationsOnly:false.
+                ].
+            ] ifFalse:[
+                "/ is it a private class?
+                (cls notNil
+                and:[ (privateClass := cls theNonMetaclass privateClassNamed:nameOfVariable) notNil ]) ifTrue:[
+                    browserClass browseReferendsOf:(privateClass name)
+                ] ifFalse:[
+                    |pool nsClass|
+
+                    "/ is it a pool variable?
+                    cls notNil ifTrue:[
+                        pool := cls theNonMetaclass sharedPools
+                                detect:[:pool | pool classVarNames includes:nameOfVariable]
+                                ifNone:nil.
+                    ].
+                    pool notNil ifTrue:[
+                        browserClass browseReferendsOf:(pool name,':',nameOfVariable)
                     ] ifFalse:[
-                        |pool nsClass|
-
-                        "/ is it a pool variable?
-                        cls notNil ifTrue:[
-                            pool := cls theNonMetaclass sharedPools
-                                    detect:[:pool | pool classVarNames includes:nameOfVariable]
-                                    ifNone:nil.
-                        ].
-                        pool notNil ifTrue:[
-                            browserClass browseReferendsOf:(pool name,':',nameOfVariable)
+                        (cls notNil
+                          and:[ cls nameSpace notNil
+                          and:[ cls nameSpace isNameSpace            
+                          and:[ nameOfVariable knownAsSymbol  
+                          and:[ (cls nameSpace name,'::',nameOfVariable) "nameOfVariable" knownAsSymbol  
+                          and:[ (nsClass := cls nameSpace at:nameOfVariable asSymbol) notNil
+                          and:[ nsClass isBehavior
+                        ]]]]]]) ifTrue:[
+                            "/ a namespace class?
+                            browserClass browseReferendsOf:nsClass name
                         ] ifFalse:[
-                            (cls notNil
-                              and:[ cls nameSpace notNil
-                              and:[ cls nameSpace isNameSpace            
-                              and:[ nameOfVariable knownAsSymbol  
-                              and:[ (cls nameSpace name,'::',nameOfVariable) "nameOfVariable" knownAsSymbol  
-                              and:[ (nsClass := cls nameSpace at:nameOfVariable asSymbol) notNil
-                              and:[ nsClass isBehavior
-                            ]]]]]]) ifTrue:[
-                                "/ a namespace class?
-                                browserClass browseReferendsOf:nsClass name
+                            "/ an instvar?
+                            (cls notNil and:[cls allInstVarNames includes:nameOfVariable]) ifTrue:[
+                                browserClass 
+                                    browseInstRefsTo:nameOfVariable 
+                                    under:(cls whichClassDefinesInstVar:nameOfVariable) 
+                                    modificationsOnly:false
                             ] ifFalse:[
-                                "/ an instvar?
-                                (cls notNil and:[cls allInstVarNames includes:nameOfVariable]) ifTrue:[
-                                    browserClass 
-                                        browseInstRefsTo:nameOfVariable 
-                                        under:(cls whichClassDefinesInstVar:nameOfVariable) 
-                                        modificationsOnly:false
-                                ] ifFalse:[
-                                    "/ no, assume global
-                                    browserClass browseReferendsOf:nameOfVariable
-                                ]
+                                "/ no, assume global
+                                browserClass browseReferendsOf:nameOfVariable
                             ]
                         ]
                     ]
                 ]
             ]
-        ].
+        ]
     ].
 
     "Created: / 05-11-2001 / 17:32:23 / cg"
     "Modified: / 01-09-2017 / 14:24:09 / cg"
 !
 
+browseReferencesToIt
+    "open a browser on all references to the selected global, poolvar or namespace class"
+
+    |nameOfVariable|
+
+    nameOfVariable := self selectedTextOrSyntaxElement.
+    nameOfVariable isEmptyOrNil ifTrue:[^ self].
+
+    nameOfVariable := nameOfVariable string asString.
+    nameOfVariable := nameOfVariable asSingleByteStringIfPossible.
+    self browseReferencesTo:nameOfVariable
+!
+
 browseSendersOfIt
     "open a browser on the senders of the selected text"
 
@@ -1963,22 +2058,39 @@
         "
          workspaces support #browse, implementors etc. add them after paste.
         "
-        sub
-            addItemList:#(
-                ('-'                                                                        )
-                ('Browse It'                    browseIt                BrowseIt            )
-                ('Browse Pool'                  browseSharedPoolOfIt                        )
-                ('Senders of It'                browseSendersOfIt                           )
-                ('Implementors of It'           browseImplementorsOfIt  ImplementorsOfIt    )
-                ('References to It'             browseReferencesToIt                        )
-"/                ('Classes Containing It in Name'    browseClassesContainingItInName           )
-"/                ('Methods ContanĂ­ning It in Name'   browseMethodsContainingItInName           )
-"/                ('Methods ContanĂ­ning It in Source' browseMethodsContainingItInSource         )
-                ('-'                                                                )
-                ('TimeIt'               timeIt                                      )
-                ('SpyOnIt'              spyOnIt                                     ))
-          resources:resources
-          after:#gotoLine.
+        self hasSelection ifTrue:[
+            sub
+                addItemList:#(
+                    ('-'                                                                        )
+                    ('Browse It'                        browseIt                BrowseIt            )
+                    ('Browse Pool'                      browseSharedPoolOfIt                        )
+                    ('Senders of It'                    browseSendersOfIt                           )
+                    ('Implementors of It'               browseImplementorsOfIt  ImplementorsOfIt    )
+                    ('References to It'                 browseReferencesToIt                        )
+                    ('Classes Containing It in Name'    browseClassesContainingItInName           )
+                    ('Methods Containing It in Source'  browseMethodsContainingItInSource         )
+                    ('-'                                                                )
+                    ('TimeIt'               timeIt                                      )
+                    ('SpyOnIt'              spyOnIt                                     ))
+              resources:resources
+              after:#gotoLine.
+        ] ifFalse:[
+            sub
+                addItemList:#(
+                    ('-'                                                                        )
+                    ('Browse It'                        browseIt                BrowseIt            )
+                    ('Browse Pool'                      browseSharedPoolOfIt                        )
+                    ('Senders of...'                    browseSendersOf                           )
+                    ('Implementors of...'               browseImplementorsOf   ImplementorsOf       )
+                    ('References to...'                 browseReferencesTo                          )
+                    ('Classes Containing in Name...'    browseClassesContainingInName           )
+                    ('Methods Containing in Source...'  browseMethodsWithString         )
+                    ('-'                                                                )
+                    ('TimeIt'               timeIt                                      )
+                    ('SpyOnIt'              spyOnIt                                     ))
+              resources:resources
+              after:#gotoLine.
+        ].
 
         subsub := sub subMenuAt:#tools.
         subsub notNil ifTrue:[