#BUGFIX by stefan
authorStefan Vogel <sv@exept.de>
Tue, 12 Jul 2016 16:52:33 +0200
changeset 16728 90111a2e7304
parent 16726 d2f028e5a546
child 16729 087537207973
child 16730 d3a953901bf1
#BUGFIX by stefan class: EditFieldWithCompletion class definition comment/format in: #destroy #handleNonCommandKey: #handlesKeyPress:inView: #keyPress:x:y:view: changed:5 methods close options window when loosing focus. multi-screen support
EditFieldWithCompletion.st
--- a/EditFieldWithCompletion.st	Thu Jul 07 20:21:17 2016 +0200
+++ b/EditFieldWithCompletion.st	Tue Jul 12 16:52:33 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2006 by eXept Software AG
 	      All Rights Reserved
@@ -14,8 +16,8 @@
 "{ NameSpace: Smalltalk }"
 
 EditField subclass:#EditFieldWithCompletion
-	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow
-		focusEventsToIgnore hadFocus completionJob tabCompletionJob'
+	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow completionJob
+		tabCompletionJob'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-Text'
@@ -189,7 +191,6 @@
 !
 
 handleNonCommandKey: char
-
     super handleNonCommandKey: char.
     self startCompletion
 
@@ -197,42 +198,29 @@
 !
 
 handlesKeyPress:key inView:aView
-
     <resource: #keyboard (#CursorDown #CursorUp)>
 
-    ^aView == optionsView and:
-        [(#( #CursorDown #CursorUp ) includes: key) not].
+    ^ aView == optionsView and:[(#(CursorDown CursorUp) includes:key) not].
 
     "Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-hasKeyboardFocus:aBoolean
-    #todo. "/ @jan: please explain what you are doing here...
-
-    focusEventsToIgnore > 0 ifTrue:[
-        focusEventsToIgnore := focusEventsToIgnore - 1.
-        "
-        xxx == 0 ifTrue:[
-            Transcript showCR:'--> taking focus'.
-            self takeFocus.
-            self assert: self windowGroup focusView == self.
-            hadFocus := true.
-        ].
-        "            
-        ^self].
-
-    hadFocus == aBoolean ifTrue:[
-        ^self
+hasKeyboardFocus:gotFocusBoolean
+    hasKeyboardFocus == gotFocusBoolean ifTrue:[
+        "no change"
+        ^ self
     ].
 
-    aBoolean 
-        ifTrue:
-            [self selectAll]
-        ifFalse:
-            [self unselect.
-            self hideOptionsWindow].
-    hadFocus := aBoolean.
-    ^ super hasKeyboardFocus:aBoolean
+    gotFocusBoolean ifTrue:[
+        "position cursor behind of already typed chars"
+        self selectAll.
+    ] ifFalse:[
+        (self hasFocus not and:[optionsWindow notNil and:[optionsWindow hasFocus not]]) ifTrue:[
+            self unselect.
+            self hideOptionsWindow.
+        ].
+    ].
+    ^ super hasKeyboardFocus:gotFocusBoolean
 
     "Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
     "Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
@@ -243,15 +231,20 @@
     "Forward certain events to optionsView if any"
 
     <resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)>
-    
+
+    key isCharacter ifTrue:[
+        super keyPress:key x:x y:y.
+        ^ self.
+    ].
+
     (optionsView notNil 
      and:[#(CursorDown CursorUp) includesIdentical:key]) ifTrue:[
         optionsView keyPress:key x:x y:y.
         ^ self.
     ].
 
-    key == #Accept ifTrue:[self hideOptionsWindow].
-    key == #Return ifTrue:[self hideOptionsWindow].
+    key == #Accept ifTrue:[self hideOptionsWindow; accept].
+    key == #Return ifTrue:[self hideOptionsWindow; accept].
     key == #Escape ifTrue:[self hideOptionsWindow].
     (key == #BackSpace or:[key == #Delete or:[key == #Tab]]) ifTrue:[
         super keyPress:key x:x y:y.
@@ -263,7 +256,6 @@
         ^ self.
     ].
 
-    super keyPress:key x:x y:y
 
     "Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
     "Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
@@ -271,7 +263,6 @@
 !
 
 keyPress:key x:x y:y view:aView
-
     self keyPress: key x:x y:y
 
     "Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -308,7 +299,6 @@
 !EditFieldWithCompletion methodsFor:'initialization & release'!
 
 destroy
-
     self hideOptionsWindow.
     super destroy.
 
@@ -317,17 +307,15 @@
 !
 
 initialize
-
     super initialize.
     showOptions := true.
     optionsHolder := ValueHolder new.
-    focusEventsToIgnore := 0.
     
     completionJob := BackgroundJob 
                         named: 'Edit Field Completion Job'
                         on:[self doCompletion].
     tabCompletionJob := BackgroundJob 
-                        named: 'Edit Field Completion Job'
+                        named: 'Edit Field Tab Completion Job'
                         on:[self doTabCompletion].
 
     "Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
@@ -382,7 +370,7 @@
 hideOptionsWindow
     optionsWindow notNil ifTrue:[
         optionsWindow destroy.
-        optionsWindow := nil.
+        optionsView := optionsWindow := nil.
     ]
 
     "Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
@@ -391,7 +379,6 @@
 !
 
 showOptionsWindow
-
     | x y w |
 
     showOptions ifFalse:[^ self].
@@ -403,7 +390,7 @@
     optionsView := SelectionInListModelView new
                     textStartLeft: textStartLeft - 2;
                     listHolder: optionsHolder;
-                    action:[:value | value notNil ifTrue:[ self contents:value asString ] ];
+                    action:[:value | value notNil ifTrue:[self contents:value asString]];
                     doubleClickAction:[:index | 
                             self contents:(optionsView at:index) asString.
                             self hideOptionsWindow.
@@ -425,7 +412,7 @@
         bePopUpView;
         beSlave;        
         origin:x @ y
-        extent:(w min: (Screen current width - x)) @ (fontHeight * 10);
+        extent:(w min: ((Screen current monitorBoundsAt:(x@y)) corner x - x)) @ (fontHeight * 10);
         yourself.
 
     ScrollableView   
@@ -438,7 +425,6 @@
         corner:1.0@1.0 
         in:optionsWindow.
 
-    focusEventsToIgnore := 4.
     optionsWindow open.
 
     "Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"