code completion for instance creation messages to a global
authorClaus Gittinger <cg@exept.de>
Mon, 16 Oct 2006 11:13:06 +0200
changeset 7409 07a631439e06
parent 7408 028111416d25
child 7410 c85762b2a733
code completion for instance creation messages to a global
NewSystemBrowser.st
Tools__NewSystemBrowser.st
--- a/NewSystemBrowser.st	Fri Oct 13 18:26:56 2006 +0200
+++ b/NewSystemBrowser.st	Mon Oct 16 11:13:06 2006 +0200
@@ -37728,13 +37728,56 @@
     ].
 
     node isVariable ifTrue:[
+        nm := node name.
+
+        "/ if we are behind the variable and a space has already been entered,
+        "/ the user is probably looking for a message selector.
+        "/ If the variable represents a global, present its instance creation messages
+        crsrPos := codeView characterPositionOfCursor.
+        char := codeView characterAtCharacterPosition:crsrPos-1.
+        char isSeparator ifTrue:[
+            nodeVal := self currentClass nameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
+            nodeVal isBehavior ifTrue:[
+                |methods menu exitKey idx|
+
+                methods := nodeVal class methodDictionary values
+                                select:[:m | |cat|
+                                    cat := m category asLowercase.
+                                    cat = 'instance creation'
+                                ].
+
+                menu := PopUpMenu labels:(methods collect:[:each | each selector]).
+                menu hideOnKeyFilter:[:key | |hide|
+                        hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
+                        hide ifTrue:[
+                            exitKey := key.
+                        ].
+                        hide].
+
+                idx := menu startUp.
+                idx == 0 ifTrue:[ 
+                    exitKey notNil ifTrue:[
+                        codeView keyPress:exitKey x:0 y:0.
+                    ].
+                    ^ self
+                ].
+                best := (methods at:idx) selector.
+                codeView
+                    undoableDo:[ 
+                        codeView insertString:best atCharacterPosition:crsrPos.
+                        codeView cursorToCharacterPosition:crsrPos+best size.
+                        ]
+                    info:'completion'.
+                ^ self.
+            ].
+        ].
+
         (node parent notNil and:[node parent isMessage]) ifTrue:[
             node == node parent receiver ifTrue:[
                 selectorOfMessageToNode := node parent selector
             ]
         ].
 
-        nm := node name.
         nm isUppercaseFirst ifTrue:[
             globalFactor := 2.
             localFactor := 1.
@@ -38085,7 +38128,7 @@
     ].
 
     "Modified: / 04-07-2006 / 18:48:26 / fm"
-    "Modified: / 12-09-2006 / 13:33:46 / cg"
+    "Modified: / 15-10-2006 / 14:05:34 / cg"
 !
 
 codeInfoVisibilityChanged
@@ -39628,7 +39671,7 @@
 !NewSystemBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1086 2006-10-13 12:09:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1087 2006-10-16 09:13:06 cg Exp $'
 ! !
 
 NewSystemBrowser initialize!
--- a/Tools__NewSystemBrowser.st	Fri Oct 13 18:26:56 2006 +0200
+++ b/Tools__NewSystemBrowser.st	Mon Oct 16 11:13:06 2006 +0200
@@ -37728,13 +37728,56 @@
     ].
 
     node isVariable ifTrue:[
+        nm := node name.
+
+        "/ if we are behind the variable and a space has already been entered,
+        "/ the user is probably looking for a message selector.
+        "/ If the variable represents a global, present its instance creation messages
+        crsrPos := codeView characterPositionOfCursor.
+        char := codeView characterAtCharacterPosition:crsrPos-1.
+        char isSeparator ifTrue:[
+            nodeVal := self currentClass nameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
+            nodeVal isBehavior ifTrue:[
+                |methods menu exitKey idx|
+
+                methods := nodeVal class methodDictionary values
+                                select:[:m | |cat|
+                                    cat := m category asLowercase.
+                                    cat = 'instance creation'
+                                ].
+
+                menu := PopUpMenu labels:(methods collect:[:each | each selector]).
+                menu hideOnKeyFilter:[:key | |hide|
+                        hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
+                        hide ifTrue:[
+                            exitKey := key.
+                        ].
+                        hide].
+
+                idx := menu startUp.
+                idx == 0 ifTrue:[ 
+                    exitKey notNil ifTrue:[
+                        codeView keyPress:exitKey x:0 y:0.
+                    ].
+                    ^ self
+                ].
+                best := (methods at:idx) selector.
+                codeView
+                    undoableDo:[ 
+                        codeView insertString:best atCharacterPosition:crsrPos.
+                        codeView cursorToCharacterPosition:crsrPos+best size.
+                        ]
+                    info:'completion'.
+                ^ self.
+            ].
+        ].
+
         (node parent notNil and:[node parent isMessage]) ifTrue:[
             node == node parent receiver ifTrue:[
                 selectorOfMessageToNode := node parent selector
             ]
         ].
 
-        nm := node name.
         nm isUppercaseFirst ifTrue:[
             globalFactor := 2.
             localFactor := 1.
@@ -38085,7 +38128,7 @@
     ].
 
     "Modified: / 04-07-2006 / 18:48:26 / fm"
-    "Modified: / 12-09-2006 / 13:33:46 / cg"
+    "Modified: / 15-10-2006 / 14:05:34 / cg"
 !
 
 codeInfoVisibilityChanged
@@ -39628,7 +39671,7 @@
 !NewSystemBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1086 2006-10-13 12:09:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1087 2006-10-16 09:13:06 cg Exp $'
 ! !
 
 NewSystemBrowser initialize!