BrowserView.st
changeset 2588 4d59125b5f59
parent 2586 486646cca84c
child 2590 bc4befd23834
--- a/BrowserView.st	Mon Feb 07 12:17:12 2000 +0100
+++ b/BrowserView.st	Mon Feb 07 12:34:49 2000 +0100
@@ -797,6 +797,98 @@
     "Modified: / 28.5.1998 / 12:22:58 / cg"
 ! !
 
+!BrowserView class methodsFor:'utilities'!
+
+extractClassAndSelectorFrom:aString into:aBlock
+    "given a string which can be either 'class>>sel' or
+     'class sel', extract className and selector, and call aBlock with
+     the result.
+     Useful to open browser on a method as selected in some documentation."
+
+    |sel clsName isMeta sep s|
+
+    sel := aString.
+    sel notNil ifTrue:[
+        sel := sel asString withoutSeparators.
+        ('*>>*' match:sel) ifTrue:[
+            sep := $>
+        ] ifFalse:[
+            ('* *' match:sel) ifTrue:[
+                sep := Character space
+            ]
+        ].
+        sep notNil ifTrue:[
+            "
+             extract class/sel from selection
+            "
+            s := ReadStream on:sel.
+            clsName := s upTo:sep.
+            [s peek == sep] whileTrue:[s next].
+            sel := s upToEnd.
+
+            (clsName endsWith:' class') ifTrue:[
+                isMeta := true.
+                clsName := clsName copyWithoutLast:6 "copyTo:(clsName size - 5)"
+            ] ifFalse:[
+                isMeta := false
+            ].
+        ]
+    ].
+    aBlock value:clsName value:sel value:isMeta
+
+    "Modified: / 17.6.1996 / 16:52:14 / stefan"
+    "Created: / 6.2.2000 / 00:51:51 / cg"
+    "Modified: / 6.2.2000 / 00:56:43 / cg"
+!
+
+extractSelectorFrom:aString
+    "given an arbitrary string, try to extract a useful selector.
+     Useful to open browser on a selected code fragment."
+
+    |s sel t|
+
+    aString isNil ifTrue:[^ nil].
+
+    s := aString asString string.
+    s := s withoutSeparators.
+    sel := s.
+    sel knownAsSymbol ifTrue:[
+        "/ might be already correct ...
+        ^ sel
+    ].
+    (sel startsWith:'#') ifTrue:[
+        t := Symbol readFrom:sel.
+        t knownAsSymbol ifTrue:[
+            ^ t
+        ]
+    ].
+
+    t := Parser selectorInExpression:sel.
+    t notNil ifTrue:[
+        sel := t
+    ].
+    (sel = s or:[sel isNil or:[t == #>>]]) ifTrue:[
+        "oops - thats probably not what we want here ..."
+        self extractClassAndSelectorFrom:s into:[:c :s :m |
+            sel := s
+        ]
+    ].
+    ^ sel
+
+    "
+     self extractSelectorFrom:'at:put:'      
+     self extractSelectorFrom:'#at:put:'                       
+     self extractSelectorFrom:'at:something put:someValue'     
+     self extractSelectorFrom:'self at:something put:someValue'
+     self extractSelectorFrom:'(self at:something put:someValue)' 
+     self extractSelectorFrom:'[self at:something put:someValue] value' 
+     self extractSelectorFrom:'Array>>at:put:' 
+    "
+
+    "Created: / 6.2.2000 / 00:49:44 / cg"
+    "Modified: / 6.2.2000 / 00:57:08 / cg"
+! !
+
 !BrowserView methodsFor:'change & update'!
 
 delayedUpdate:something with:someArgument from:changedObject
@@ -6494,7 +6586,7 @@
     "Modified: 28.6.1997 / 15:00:18 / cg"
 ! !
 
-!BrowserView methodsFor:'initialize / release'!
+!BrowserView methodsFor:'initialization & release'!
 
 autoSearch:aString
     "used with class-method list browsing. If true,
@@ -11980,47 +12072,35 @@
 
     sel := codeView selection.
     sel notNil ifTrue:[
-	sel := sel asString string.
-	sel withoutSeparators knownAsSymbol ifTrue:[
-	    "/ might be already correct ...
-	] ifFalse:[
-	    t := Parser selectorInExpression:sel.
-	    t notNil ifTrue:[
-		sel := t
-	    ].
-	    sel := sel withoutSpaces.
-	    sel == #>> ifTrue:[
-		"oops - thats probably not what we want here ..."
-		self extractClassAndSelectorFromSelectionInto:[:c :s :m |
-		    sel := s
-		]
-	    ]
-	]
+        t := BrowserView extractSelectorFrom:sel.
+        t notNil ifTrue:[
+            sel := t.
+        ].
     ] ifFalse:[
-	methodListView notNil ifTrue:[
-	    methodListView selection notNil ifTrue:[
+        methodListView notNil ifTrue:[
+            methodListView selection notNil ifTrue:[
 sel := selectorList at:(methodListView selection).
 "/                sel := methodListView selectionValue string
-	    ]
-	] ifFalse:[
-	    classMethodListView notNil ifTrue:[
-		classMethodListView selection notNil ifTrue:[
-		    sel := classMethodListView selectionValue string.
-		].
-		sel notNil ifTrue:[
-		    sel := self selectorFromClassMethodString:sel
-		]
-	    ]
-	].
-	sel notNil ifTrue:[
-	    sel := sel withoutSpaces upTo:(Character space)
-	] ifFalse:[
-	    sel := ''
-	]
+            ]
+        ] ifFalse:[
+            classMethodListView notNil ifTrue:[
+                classMethodListView selection notNil ifTrue:[
+                    sel := classMethodListView selectionValue string.
+                ].
+                sel notNil ifTrue:[
+                    sel := self selectorFromClassMethodString:sel
+                ]
+            ]
+        ].
+        sel notNil ifTrue:[
+            sel := sel withoutSpaces upTo:(Character space)
+        ] ifFalse:[
+            sel := ''
+        ]
     ].
     ^ sel string
 
-    "Modified: / 31.7.1998 / 15:26:18 / cg"
+    "Modified: / 6.2.2000 / 00:59:20 / cg"
 !
 
 setAcceptActionForClass
@@ -13737,6 +13817,6 @@
 !BrowserView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/BrowserView.st,v 1.592 2000-02-05 14:30:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/BrowserView.st,v 1.593 2000-02-07 11:34:49 cg Exp $'
 ! !
 BrowserView initialize!