Support for auto-completion of unambigous items (such as instvars)
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 18 Jan 2014 23:41:04 +0000
changeset 154 b96fbde91144
parent 153 b04d591c8788
child 155 d792aed09149
Support for auto-completion of unambigous items (such as instvars)
Make.proto
SmallSense__CompletionController.st
SmallSense__SettingsAppl.st
bc.mak
extensions.st
jv_smallsense.st
smallsense.rc
--- a/Make.proto	Sat Jan 18 22:56:44 2014 +0000
+++ b/Make.proto	Sat Jan 18 23:41:04 2014 +0000
@@ -34,7 +34,7 @@
 # add the path(es) here:,
 # ********** OPTIONAL: MODIFY the next lines ***
 # LOCALINCLUDES=-Ifoo -Ibar
-LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/goodies/refactoryBrowser/helpers -I$(INCLUDE_TOP)/stx/goodies/refactoryBrowser/lint -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libcomp -I$(INCLUDE_TOP)/stx/libhtml -I$(INCLUDE_TOP)/stx/libtool -I$(INCLUDE_TOP)/stx/libview -I$(INCLUDE_TOP)/stx/libview2 -I$(INCLUDE_TOP)/stx/libwidg -I$(INCLUDE_TOP)/stx/libwidg2
+LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/goodies/refactoryBrowser/helpers -I$(INCLUDE_TOP)/stx/goodies/refactoryBrowser/lint -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libcomp -I$(INCLUDE_TOP)/stx/libhtml -I$(INCLUDE_TOP)/stx/libtool -I$(INCLUDE_TOP)/stx/libview -I$(INCLUDE_TOP)/stx/libview2 -I$(INCLUDE_TOP)/stx/libwidg -I$(INCLUDE_TOP)/stx/libwidg2
 
 
 # if you need any additional defines for embedded C code,
@@ -137,6 +137,7 @@
 	cd $(TOP)/libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd $(TOP)/libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd $(TOP)/goodies/refactoryBrowser/browser && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
+	cd $(TOP)/goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd $(TOP)/libwidg && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd $(TOP)/goodies/refactoryBrowser/lint && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd $(TOP)/libhtml && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
--- a/SmallSense__CompletionController.st	Sat Jan 18 22:56:44 2014 +0000
+++ b/SmallSense__CompletionController.st	Sat Jan 18 23:41:04 2014 +0000
@@ -3,7 +3,7 @@
 "{ NameSpace: SmallSense }"
 
 EditTextViewCompletionSupport subclass:#CompletionController
-	instanceVariableNames:'support seqno'
+	instanceVariableNames:'support seqno completeIfUnambiguous'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core'
@@ -123,10 +123,11 @@
     "/ please change as required (and remove this comment)
     "/ support := nil.
     seqno := 0.
+    completeIfUnambiguous := UserPreferences current smallSenseCompleteIfUnambiguous.
 
     "/ super initialize.   -- commented since inherited method does nothing
 
-    "Modified: / 03-10-2013 / 07:11:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-01-2014 / 23:10:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionController methodsFor:'private'!
@@ -166,23 +167,39 @@
 !
 
 updateSelection
+    "Updates selection in completion view based on
+     currently typed partial text. Return true if
+     the complection window should be closed or false
+     if it shall be kept open."
 
     | matches word |
 
     word := support wordBeforeCursor.
     matches := completionView list select:[:po | po stringToComplete startsWith: word ].
     matches notEmptyOrNil ifTrue:[
-        completionView selection: (matches inject: matches anElement into:[:mostrelevant :each |
-            each relevance > mostrelevant relevance 
-                ifTrue:[each]
-                ifFalse:[mostrelevant]
-        ]).
+        matches size == 1 ifTrue:[
+            completionView selection:  matches anElement.
+            completeIfUnambiguous ifTrue:[
+                self complete.
+                ^ true
+            ]
+        ] ifFalse:[
+            | selection |
+
+            selection := matches inject: matches anElement into:[:mostrelevant :each |
+                each relevance > mostrelevant relevance 
+                    ifTrue:[each]
+                    ifFalse:[mostrelevant]
+            ].
+            completionView selection: selection.
+        ]
     ] ifFalse:[
         completionView selection: nil.
     ].
+    ^ false.
 
     "Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-01-2014 / 22:51:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 18-01-2014 / 23:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionController methodsFor:'private-API'!
@@ -258,8 +275,9 @@
         ].
         topView origin:movePos.
 "/        topView resizeToFit.
-        self updateSelection.
-        topView open.
+        self updateSelection ifFalse:[
+            topView open.
+        ].
     ] ifFalse:[
         completionView list:list.
         self updateSelection.
@@ -271,7 +289,7 @@
     ].
 
     "Created: / 27-09-2013 / 14:01:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-01-2014 / 22:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-01-2014 / 23:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 updateCompletions: completionResult sequence: sequence
--- a/SmallSense__SettingsAppl.st	Sat Jan 18 22:56:44 2014 +0000
+++ b/SmallSense__SettingsAppl.st	Sat Jan 18 23:41:04 2014 +0000
@@ -4,7 +4,8 @@
 
 AbstractSettingsApplication subclass:#SettingsAppl
 	instanceVariableNames:'smallSenseBackgroundTypingEnabled smallSenseBackgroundLintEnabled
-		smallSenseEnabled smallSenseElectricEditSupportEnabled'
+		smallSenseEnabled smallSenseElectricEditSupportEnabled
+		smallSenseCompleteIfUnambiguous'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core-Interface'
@@ -67,9 +68,9 @@
      the UIPainter may not be able to read the specification."
 
     "
-     UIPainter new openOnClass:SmallSenseSettingsAppl andSelector:#windowSpec
-     SmallSenseSettingsAppl new openInterface:#windowSpec
-     SmallSenseSettingsAppl open
+     UIPainter new openOnClass:SmallSense::SettingsAppl andSelector:#windowSpec
+     SmallSense::SettingsAppl new openInterface:#windowSpec
+     SmallSense::SettingsAppl open
     "
 
     <resource: #canvas>
@@ -135,6 +136,12 @@
                    translateLabel: true
                    extent: (Point 536 22)
                  )
+                (CheckBoxSpec
+                   label: 'Auto-complete when Completion is Unambiguous'
+                   name: 'CheckBox4'
+                   model: smallSenseCompleteIfUnambiguous
+                   extent: (Point 536 22)
+                 )
                 )
               
              )
@@ -189,6 +196,27 @@
     "Modified: / 04-02-2012 / 21:48:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+smallSenseCompleteIfUnambiguous
+    <resource: #uiAspect>
+
+    "automatically generated by UIPainter ..."
+
+    "*** the code below creates a default model when invoked."
+    "*** (which may not be the one you wanted)"
+    "*** Please change as required and accept it in the browser."
+    "*** (and replace this comment by something more useful ;-)"
+
+    smallSenseCompleteIfUnambiguous isNil ifTrue:[
+        smallSenseCompleteIfUnambiguous := true asValue.
+"/ if your app needs to be notified of changes, uncomment one of the lines below:
+"/       smallSenseBackgroundLintEnabled addDependent:self.
+       smallSenseCompleteIfUnambiguous onChangeSend:#updateModifiedChannel to:self.
+    ].
+    ^ smallSenseCompleteIfUnambiguous.
+
+    "Created: / 18-01-2014 / 23:36:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 smallSenseElectricEditSupportEnabled
     <resource: #uiAspect>
 
@@ -241,10 +269,11 @@
        smallSenseBackgroundLintEnabled
        smallSenseBackgroundTypingEnabled
        smallSenseElectricEditSupportEnabled
+       smallSenseCompleteIfUnambiguousa
 
     )
 
-    "Modified: / 26-07-2013 / 12:41:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-01-2014 / 23:36:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 basicReadSettings
--- a/bc.mak	Sat Jan 18 22:56:44 2014 +0000
+++ b/bc.mak	Sat Jan 18 23:41:04 2014 +0000
@@ -34,7 +34,7 @@
 
 
 
-LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\goodies\refactoryBrowser\helpers -I$(INCLUDE_TOP)\stx\goodies\refactoryBrowser\lint -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libcomp -I$(INCLUDE_TOP)\stx\libhtml -I$(INCLUDE_TOP)\stx\libtool -I$(INCLUDE_TOP)\stx\libview -I$(INCLUDE_TOP)\stx\libview2 -I$(INCLUDE_TOP)\stx\libwidg -I$(INCLUDE_TOP)\stx\libwidg2
+LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\goodies\refactoryBrowser\helpers -I$(INCLUDE_TOP)\stx\goodies\refactoryBrowser\lint -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libcomp -I$(INCLUDE_TOP)\stx\libhtml -I$(INCLUDE_TOP)\stx\libtool -I$(INCLUDE_TOP)\stx\libview -I$(INCLUDE_TOP)\stx\libview2 -I$(INCLUDE_TOP)\stx\libwidg -I$(INCLUDE_TOP)\stx\libwidg2
 LOCALDEFINES=
 
 STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES)  -varPrefix=$(LIBNAME)
@@ -60,6 +60,7 @@
 	pushd ..\..\stx\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\..\stx\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\..\stx\goodies\refactoryBrowser\browser & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
+	pushd ..\..\stx\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\..\stx\libwidg & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\..\stx\goodies\refactoryBrowser\lint & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\..\stx\libhtml & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
--- a/extensions.st	Sat Jan 18 22:56:44 2014 +0000
+++ b/extensions.st	Sat Jan 18 23:41:04 2014 +0000
@@ -512,6 +512,30 @@
 
 !UserPreferences methodsFor:'accessing-SmallSense'!
 
+smallSenseCompleteIfUnambiguous
+
+    ^self at:#smallSenseCompleteIfUnambiguous ifAbsent:[false]
+
+    "Created: / 18-01-2014 / 23:08:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!UserPreferences methodsFor:'accessing-SmallSense'!
+
+smallSenseCompleteIfUnambiguous: aBoolean
+
+    ^self at:#smallSenseCompleteIfUnambiguous put: aBoolean.
+
+    "
+    UserPreferences current smallSenseCompleteIfUnambiguous
+    UserPreferences current smallSenseCompleteIfUnambiguous: true.
+    UserPreferences current smallSenseCompleteIfUnambiguous: false.
+    "
+
+    "Created: / 18-01-2014 / 23:08:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!UserPreferences methodsFor:'accessing-SmallSense'!
+
 smallSenseEnabled
     "Return true if SmallSense is enabled"
 
--- a/jv_smallsense.st	Sat Jan 18 22:56:44 2014 +0000
+++ b/jv_smallsense.st	Sat Jan 18 23:41:04 2014 +0000
@@ -46,6 +46,7 @@
     ^ #(
         #'stx:goodies/refactoryBrowser/helpers'    "BrowserEnvironment - superclass of SmallSense::SmalltalkUnacceptedMethodEnvironment "
         #'stx:goodies/refactoryBrowser/lint'    "RBLintRule - extended "
+        #'stx:goodies/sunit'    "TestAsserter - superclass of SmallSense::TestCase "
         #'stx:libbasic'    "Autoload - superclass of SmallSense::BaseTestClass "
         #'stx:libcomp'    "AbstractSyntaxHighlighter - superclass of SmallSense::SmalltalkParser "
         #'stx:libhtml'    "HTMLDocumentFrame - extended "
@@ -265,6 +266,8 @@
         #'Tools::NewSystemBrowser' smallSenseSearchCompletionEntryForClass:showPrefix:
         #'Tools::NewSystemBrowser' smallSenseSearchCompletionNewForClass:
         PrimitiveNode inferedType
+        UserPreferences smallSenseCompleteIfUnambiguous
+        UserPreferences smallSenseCompleteIfUnambiguous:
     )
 ! !
 
--- a/smallsense.rc	Sat Jan 18 22:56:44 2014 +0000
+++ b/smallsense.rc	Sat Jan 18 23:41:04 2014 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\0"
       VALUE "ProductName", "Smalltalk/X\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Sat, 18 Jan 2014 22:53:24 GMT\0"
+      VALUE "ProductDate", "Sat, 18 Jan 2014 23:39:25 GMT\0"
     END
 
   END