EditFieldWithCompletion.st
changeset 16728 90111a2e7304
parent 16715 78d44ccf2a1c
child 16729 087537207973
child 16982 4a80412feb9a
equal deleted inserted replaced
16726:d2f028e5a546 16728:90111a2e7304
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 2006 by eXept Software AG
     4  COPYRIGHT (c) 2006 by eXept Software AG
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    12 "{ Package: 'stx:libtool' }"
    14 "{ Package: 'stx:libtool' }"
    13 
    15 
    14 "{ NameSpace: Smalltalk }"
    16 "{ NameSpace: Smalltalk }"
    15 
    17 
    16 EditField subclass:#EditFieldWithCompletion
    18 EditField subclass:#EditFieldWithCompletion
    17 	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow
    19 	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow completionJob
    18 		focusEventsToIgnore hadFocus completionJob tabCompletionJob'
    20 		tabCompletionJob'
    19 	classVariableNames:''
    21 	classVariableNames:''
    20 	poolDictionaries:''
    22 	poolDictionaries:''
    21 	category:'Views-Text'
    23 	category:'Views-Text'
    22 !
    24 !
    23 
    25 
   187     "Modified: / 09-08-2009 / 08:16:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
   189     "Modified: / 09-08-2009 / 08:16:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
   188     "Modified: / 13-02-2010 / 09:51:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   190     "Modified: / 13-02-2010 / 09:51:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   189 !
   191 !
   190 
   192 
   191 handleNonCommandKey: char
   193 handleNonCommandKey: char
   192 
       
   193     super handleNonCommandKey: char.
   194     super handleNonCommandKey: char.
   194     self startCompletion
   195     self startCompletion
   195 
   196 
   196     "Modified: / 26-07-2009 / 17:41:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
   197     "Modified: / 26-07-2009 / 17:41:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
   197 !
   198 !
   198 
   199 
   199 handlesKeyPress:key inView:aView
   200 handlesKeyPress:key inView:aView
   200 
       
   201     <resource: #keyboard (#CursorDown #CursorUp)>
   201     <resource: #keyboard (#CursorDown #CursorUp)>
   202 
   202 
   203     ^aView == optionsView and:
   203     ^ aView == optionsView and:[(#(CursorDown CursorUp) includes:key) not].
   204         [(#( #CursorDown #CursorUp ) includes: key) not].
       
   205 
   204 
   206     "Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   205     "Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   207 !
   206 !
   208 
   207 
   209 hasKeyboardFocus:aBoolean
   208 hasKeyboardFocus:gotFocusBoolean
   210     #todo. "/ @jan: please explain what you are doing here...
   209     hasKeyboardFocus == gotFocusBoolean ifTrue:[
   211 
   210         "no change"
   212     focusEventsToIgnore > 0 ifTrue:[
   211         ^ self
   213         focusEventsToIgnore := focusEventsToIgnore - 1.
   212     ].
   214         "
   213 
   215         xxx == 0 ifTrue:[
   214     gotFocusBoolean ifTrue:[
   216             Transcript showCR:'--> taking focus'.
   215         "position cursor behind of already typed chars"
   217             self takeFocus.
   216         self selectAll.
   218             self assert: self windowGroup focusView == self.
   217     ] ifFalse:[
   219             hadFocus := true.
   218         (self hasFocus not and:[optionsWindow notNil and:[optionsWindow hasFocus not]]) ifTrue:[
       
   219             self unselect.
       
   220             self hideOptionsWindow.
   220         ].
   221         ].
   221         "            
   222     ].
   222         ^self].
   223     ^ super hasKeyboardFocus:gotFocusBoolean
   223 
       
   224     hadFocus == aBoolean ifTrue:[
       
   225         ^self
       
   226     ].
       
   227 
       
   228     aBoolean 
       
   229         ifTrue:
       
   230             [self selectAll]
       
   231         ifFalse:
       
   232             [self unselect.
       
   233             self hideOptionsWindow].
       
   234     hadFocus := aBoolean.
       
   235     ^ super hasKeyboardFocus:aBoolean
       
   236 
   224 
   237     "Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
   225     "Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
   238     "Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
   226     "Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
   239     "Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   227     "Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   240 !
   228 !
   241 
   229 
   242 keyPress:key x:x y:y 
   230 keyPress:key x:x y:y 
   243     "Forward certain events to optionsView if any"
   231     "Forward certain events to optionsView if any"
   244 
   232 
   245     <resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)>
   233     <resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)>
   246     
   234 
       
   235     key isCharacter ifTrue:[
       
   236         super keyPress:key x:x y:y.
       
   237         ^ self.
       
   238     ].
       
   239 
   247     (optionsView notNil 
   240     (optionsView notNil 
   248      and:[#(CursorDown CursorUp) includesIdentical:key]) ifTrue:[
   241      and:[#(CursorDown CursorUp) includesIdentical:key]) ifTrue:[
   249         optionsView keyPress:key x:x y:y.
   242         optionsView keyPress:key x:x y:y.
   250         ^ self.
   243         ^ self.
   251     ].
   244     ].
   252 
   245 
   253     key == #Accept ifTrue:[self hideOptionsWindow].
   246     key == #Accept ifTrue:[self hideOptionsWindow; accept].
   254     key == #Return ifTrue:[self hideOptionsWindow].
   247     key == #Return ifTrue:[self hideOptionsWindow; accept].
   255     key == #Escape ifTrue:[self hideOptionsWindow].
   248     key == #Escape ifTrue:[self hideOptionsWindow].
   256     (key == #BackSpace or:[key == #Delete or:[key == #Tab]]) ifTrue:[
   249     (key == #BackSpace or:[key == #Delete or:[key == #Tab]]) ifTrue:[
   257         super keyPress:key x:x y:y.
   250         super keyPress:key x:x y:y.
   258         key == #Tab ifTrue:[
   251         key == #Tab ifTrue:[
   259             self startTabCompletion
   252             self startTabCompletion
   261             self startCompletion.
   254             self startCompletion.
   262         ].
   255         ].
   263         ^ self.
   256         ^ self.
   264     ].
   257     ].
   265 
   258 
   266     super keyPress:key x:x y:y
       
   267 
   259 
   268     "Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
   260     "Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
   269     "Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
   261     "Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
   270     "Modified: / 09-02-2010 / 20:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   262     "Modified: / 09-02-2010 / 20:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   271 !
   263 !
   272 
   264 
   273 keyPress:key x:x y:y view:aView
   265 keyPress:key x:x y:y view:aView
   274 
       
   275     self keyPress: key x:x y:y
   266     self keyPress: key x:x y:y
   276 
   267 
   277     "Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   268     "Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   278 !
   269 !
   279 
   270 
   306 ! !
   297 ! !
   307 
   298 
   308 !EditFieldWithCompletion methodsFor:'initialization & release'!
   299 !EditFieldWithCompletion methodsFor:'initialization & release'!
   309 
   300 
   310 destroy
   301 destroy
   311 
       
   312     self hideOptionsWindow.
   302     self hideOptionsWindow.
   313     super destroy.
   303     super destroy.
   314 
   304 
   315     "Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
   305     "Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
   316     "Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
   306     "Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
   317 !
   307 !
   318 
   308 
   319 initialize
   309 initialize
   320 
       
   321     super initialize.
   310     super initialize.
   322     showOptions := true.
   311     showOptions := true.
   323     optionsHolder := ValueHolder new.
   312     optionsHolder := ValueHolder new.
   324     focusEventsToIgnore := 0.
       
   325     
   313     
   326     completionJob := BackgroundJob 
   314     completionJob := BackgroundJob 
   327                         named: 'Edit Field Completion Job'
   315                         named: 'Edit Field Completion Job'
   328                         on:[self doCompletion].
   316                         on:[self doCompletion].
   329     tabCompletionJob := BackgroundJob 
   317     tabCompletionJob := BackgroundJob 
   330                         named: 'Edit Field Completion Job'
   318                         named: 'Edit Field Tab Completion Job'
   331                         on:[self doTabCompletion].
   319                         on:[self doTabCompletion].
   332 
   320 
   333     "Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
   321     "Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
   334     "Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
   322     "Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
   335     "Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   323     "Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   380 !
   368 !
   381 
   369 
   382 hideOptionsWindow
   370 hideOptionsWindow
   383     optionsWindow notNil ifTrue:[
   371     optionsWindow notNil ifTrue:[
   384         optionsWindow destroy.
   372         optionsWindow destroy.
   385         optionsWindow := nil.
   373         optionsView := optionsWindow := nil.
   386     ]
   374     ]
   387 
   375 
   388     "Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
   376     "Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
   389     "Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
   377     "Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
   390     "Modified: / 29-11-2011 / 11:27:03 / cg"
   378     "Modified: / 29-11-2011 / 11:27:03 / cg"
   391 !
   379 !
   392 
   380 
   393 showOptionsWindow
   381 showOptionsWindow
   394 
       
   395     | x y w |
   382     | x y w |
   396 
   383 
   397     showOptions ifFalse:[^ self].
   384     showOptions ifFalse:[^ self].
   398     optionsWindow notNil ifTrue:[ 
   385     optionsWindow notNil ifTrue:[ 
   399         optionsWindow raise.
   386         optionsWindow raise.
   401     ].
   388     ].
   402 
   389 
   403     optionsView := SelectionInListModelView new
   390     optionsView := SelectionInListModelView new
   404                     textStartLeft: textStartLeft - 2;
   391                     textStartLeft: textStartLeft - 2;
   405                     listHolder: optionsHolder;
   392                     listHolder: optionsHolder;
   406                     action:[:value | value notNil ifTrue:[ self contents:value asString ] ];
   393                     action:[:value | value notNil ifTrue:[self contents:value asString]];
   407                     doubleClickAction:[:index | 
   394                     doubleClickAction:[:index | 
   408                             self contents:(optionsView at:index) asString.
   395                             self contents:(optionsView at:index) asString.
   409                             self hideOptionsWindow.
   396                             self hideOptionsWindow.
   410                             self accept
   397                             self accept
   411                         ];
   398                         ];
   423 
   410 
   424     optionsWindow := StandardSystemView new
   411     optionsWindow := StandardSystemView new
   425         bePopUpView;
   412         bePopUpView;
   426         beSlave;        
   413         beSlave;        
   427         origin:x @ y
   414         origin:x @ y
   428         extent:(w min: (Screen current width - x)) @ (fontHeight * 10);
   415         extent:(w min: ((Screen current monitorBoundsAt:(x@y)) corner x - x)) @ (fontHeight * 10);
   429         yourself.
   416         yourself.
   430 
   417 
   431     ScrollableView   
   418     ScrollableView   
   432         forView:optionsView 
   419         forView:optionsView 
   433         hasHorizontalScrollBar:false 
   420         hasHorizontalScrollBar:false 
   436         miniScrollerV:false 
   423         miniScrollerV:false 
   437         origin:0.0@0.0 
   424         origin:0.0@0.0 
   438         corner:1.0@1.0 
   425         corner:1.0@1.0 
   439         in:optionsWindow.
   426         in:optionsWindow.
   440 
   427 
   441     focusEventsToIgnore := 4.
       
   442     optionsWindow open.
   428     optionsWindow open.
   443 
   429 
   444     "Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
   430     "Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
   445     "Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
   431     "Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
   446     "Modified: / 29-11-2011 / 11:27:13 / cg"
   432     "Modified: / 29-11-2011 / 11:27:13 / cg"