Tools__CodeCompletionService.st
changeset 9981 eae0ede9097e
child 10075 9678631201b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tools__CodeCompletionService.st	Fri Jul 01 15:20:28 2011 +0200
@@ -0,0 +1,158 @@
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+	      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.
+"
+"{ Package: 'stx:libtool' }"
+
+"{ NameSpace: Tools }"
+
+CodeViewService subclass:#CodeCompletionService
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-CodeView'
+!
+
+!CodeCompletionService class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+	      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.
+"
+! !
+
+!CodeCompletionService class methodsFor:'accessing'!
+
+label
+
+    "Answers short label - for UI"
+
+    ^'Code Completion'
+
+    "Created: / 07-03-2010 / 14:00:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CodeCompletionService class methodsFor:'testing'!
+
+isAvailable
+
+    "CodeCompletionService is superseded by SmallSense"
+
+    ^(Smalltalk at:#SmallSenseService) isNil
+
+    "Created: / 03-04-2011 / 23:08:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CodeCompletionService methodsFor:'event handling'!
+
+keyPress: key x:x y:y in: view
+
+    "Handles an event in given view (a subview of codeView).
+     If the method returns true, the event will not be processed
+     by the view."
+
+    (view == textView and:[key == #'CodeCompletion']) ifTrue:
+        [self complete. ^true].
+    ^false
+
+    "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CodeCompletionService methodsFor:'private'!
+
+complete
+    |cls 
+"/     crsrPos interval node checkedNode
+"/     char start stop selectorSoFar matchingSelectors
+    |
+
+    codeView languageHolder value == SmalltalkLanguage instance   
+        ifFalse:[^self].
+
+    cls := codeView classHolder value.
+    cls isNil ifTrue:[
+        self showInfo:'No class'.
+        ^ self.
+    ].
+    UserInformation handle:[:ex |
+        codeView showInfo:(ex messageText).
+        ex proceed.
+    ] do:[
+        codeView withWaitCursorDo:[
+            DoWhatIMeanSupport codeCompletionForClass:cls codeView:textView.
+        ]
+    ].
+    ^ self.
+
+"/
+"/    interval := self selectedInterval.
+"/    interval isEmpty ifTrue:[
+"/        crsrPos := codeView characterPositionOfCursor - 1.
+"/        char := codeView characterUnderCursor.
+"/        [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
+"/            crsrPos := crsrPos - 1.
+"/            char := codeView characterAtCharacterPosition:crsrPos.
+"/        ].
+"/        interval := crsrPos to:crsrPos.
+"/    ].
+"/
+"/    node := self findNodeForInterval:interval allowErrors:true.
+"/    [node isNil] whileTrue:[
+"/        "/ expand to the left ...
+"/        interval start > 1 ifFalse:[
+"/            self showInfo:'No parseNode found'.
+"/            ^ self.
+"/        ].
+"/        interval start:(interval start - 1).
+"/        node := self findNodeForInterval:interval allowErrors:true.
+"/    ].
+"/
+"/    node isVariable ifTrue:[
+"/        self codeCompletionForVariable:node inClass:cls.
+"/        ^ self.
+"/    ].
+"/
+"/    checkedNode := node.
+"/    [checkedNode notNil] whileTrue:[
+"/        checkedNode isMessage ifTrue:[
+"/            self codeCompletionForMessage:checkedNode inClass:cls.
+"/            ^ self
+"/        ].
+"/        checkedNode isMethod ifTrue:[
+"/            self codeCompletionForMethod:checkedNode inClass:cls.
+"/            ^ self.
+"/        ].
+"/        checkedNode := checkedNode parent.
+"/    ].
+"/
+"/    self showInfo:'Node is neither variable nor message.'.
+
+    "Modified: / 04-07-2006 / 18:48:26 / fm"
+    "Modified: / 20-11-2006 / 12:30:59 / cg"
+    "Created: / 07-03-2010 / 09:37:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CodeCompletionService class methodsFor:'documentation'!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeCompletionService.st,v 1.1 2011-07-01 13:20:28 cg Exp $'
+!
+
+version_SVN
+    ^ '§Id: Tools__CodeCompletionService.st 7695 2011-04-04 20:09:17Z vranyj1 §'
+! !