EditFieldWithCompletion.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Feb 2017 11:35:03 +0100
changeset 17449 bc8bb3d474de
parent 17280 021d529b0397
child 17451 237cc69a5265
permissions -rw-r--r--
#BUGFIX by stefan class: EditFieldWithCompletion comment/format in: #absoluteLeft #absoluteTop changed: #showOptionsWindow fix for Windows - SelctionBox was always captionHeight too low
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
     1
"{ Encoding: utf8 }"
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
     2
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2006 by eXept Software AG
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	      All Rights Reserved
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libtool' }"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
    16
"{ NameSpace: Smalltalk }"
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
    17
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
EditField subclass:#EditFieldWithCompletion
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
    19
	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow completionJob
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
    20
		tabCompletionJob'
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	classVariableNames:''
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	category:'Views-Text'
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!EditFieldWithCompletion class methodsFor:'documentation'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
copyright
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 COPYRIGHT (c) 2006 by eXept Software AG
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	      All Rights Reserved
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 This software is furnished under a license and may be used
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 only in accordance with the terms of that license and with the
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 be provided or otherwise made available to, or used by, any
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 other person.  No title to or ownership of the software is
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 hereby transferred.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
17280
021d529b0397 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17206
diff changeset
    44
    an editfield, which does some completion on the Tab key.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    [author:]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
        Jan Vrany (janfrog@bruxa)
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    [instance variables:]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [class variables:]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [see also:]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
example_1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    |top field label value|
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    top := StandardSystemView new.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    top
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        extent:300 @ 300;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        label:'Live class completion field'.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    value := '' asValue.
17206
9ecd8e75182f #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 16982
diff changeset
    66
    field := self new
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
                origin:10 @ 135 corner:280 @ 165;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
                entryCompletionBlock:[:content | Smalltalk classnameCompletion:content ];
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
                model:value.
17206
9ecd8e75182f #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 16982
diff changeset
    70
    label := Label new
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                origin:10 @ 95 corner:280 @ 115;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
                labelChannel:value.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    top
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        add:field;
17206
9ecd8e75182f #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 16982
diff changeset
    75
        add:label;
9ecd8e75182f #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 16982
diff changeset
    76
        open
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
examples
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    Opens a LiveCompletionEditField on a class name
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
                                                        [exBegin]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    LiveCompletionEditField example_1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                                                        [exEnd]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
!EditFieldWithCompletion methodsFor:'accepting'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
accept
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    self unselect.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    super accept.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    "Created: / 27-07-2009 / 09:38:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    "Modified: / 12-02-2010 / 11:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
!EditFieldWithCompletion methodsFor:'accessing-behavior'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
showOptions
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    ^ showOptions
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
showOptions:aBoolean
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    showOptions := aBoolean.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!EditFieldWithCompletion methodsFor:'accessing-dimensions'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
absoluteLeft
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   112
    "answer the absolute left (x) coordinate (i.e. relative to the display)"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   114
    |absoluteLeft view|
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   115
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    absoluteLeft := 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    view := self.
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   118
    [ view notNil ] whileTrue:[
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   119
        absoluteLeft := absoluteLeft + view left - 1.
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   120
        view := view superView
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   121
    ].
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   122
    ^ absoluteLeft
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    "Created: / 08-08-2009 / 22:30:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
absoluteTop
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   128
    "answer the absolute top (y) coordinate (i.e. relative to the display)"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   130
    |absoluteTop view|
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   131
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    absoluteTop := 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    view := self.
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   134
    [ view notNil ] whileTrue:[
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   135
        absoluteTop := absoluteTop + view top - 1.
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   136
        view := view superView
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   137
    ].
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   138
    ^ absoluteTop
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    "Created: / 08-08-2009 / 22:30:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
!EditFieldWithCompletion methodsFor:'accessing-mvc'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
optionsHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    ^ optionsHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "Created: / 09-08-2009 / 08:14:02 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
optionsHolder:aValueHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    "set the 'options' value holder (automatically generated)"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    optionsHolder := aValueHolder.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "Created: / 09-08-2009 / 08:14:24 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
!EditFieldWithCompletion methodsFor:'event handling'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
completion:best options:options 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    |newContent oldContent|
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    "
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    oldContent := ((self contents ? '') asString).
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    newContent := ((best isNil or:[ best = oldContent ]) 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
                and:[ options isNilOrEmptyCollection not ]) 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
                    ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
                        options first
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                        ""options inject:options anyOne
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
                            into:[:shortest :each | 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
                                shortest asString size > each asString size ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
                                    each
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
                                ] ifFalse:[ shortest ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
                            ]""
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
                    ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
                    ifFalse:[ best ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    self contents:newContent asString.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    self cursorCol:oldContent size + 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    oldContent size < newContent size ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
        self 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
            selectFromLine:1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
            col:oldContent size + 1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
            toLine:1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
            col:newContent size
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   188
    true "options size > 1" ifTrue:[
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
        optionsHolder value:options.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
        self showOptionsWindow
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    "Created: / 08-08-2009 / 22:02:29 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    "Modified: / 09-08-2009 / 08:16:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    "Modified: / 13-02-2010 / 09:51:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
handleNonCommandKey: char
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    super handleNonCommandKey: char.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    self startCompletion
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    "Modified: / 26-07-2009 / 17:41:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
handlesKeyPress:key inView:aView
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   206
    <resource: #keyboard (#CursorDown #CursorUp)>
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   207
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   208
    ^ aView == optionsView and:[(#(CursorDown CursorUp) includes:key) not].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    "Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   213
hasKeyboardFocus:gotFocusBoolean
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   214
    hasKeyboardFocus == gotFocusBoolean ifTrue:[
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   215
        "no change"
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   216
        ^ self
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   219
    gotFocusBoolean ifTrue:[
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   220
        "position cursor behind of already typed chars"
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   221
        self selectAll.
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   222
    ] ifFalse:[
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   223
        (self hasFocus not and:[optionsWindow notNil and:[optionsWindow hasFocus not]]) ifTrue:[
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   224
            self unselect.
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   225
            self hideOptionsWindow.
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   226
        ].
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   227
    ].
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   228
    ^ super hasKeyboardFocus:gotFocusBoolean
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    "Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    "Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
keyPress:key x:x y:y 
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   236
    "Forward certain events to optionsView if any"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   238
    <resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)>
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   239
16982
4a80412feb9a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 16728
diff changeset
   240
    (key isCharacter or:[#(Paste Copy Cut) includesIdentical:key]) ifTrue:[
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   241
        super keyPress:key x:x y:y.
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   242
        ^ self.
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   243
    ].
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   244
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   245
    (optionsView notNil 
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   246
     and:[#(CursorDown CursorUp) includesIdentical:key]) ifTrue:[
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   247
        optionsView keyPress:key x:x y:y.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   248
        ^ self.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   249
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   251
    key == #Accept ifTrue:[self hideOptionsWindow; accept].
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   252
    key == #Return ifTrue:[self hideOptionsWindow; accept].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   253
    key == #Escape ifTrue:[self hideOptionsWindow].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   254
    (key == #BackSpace or:[key == #Delete or:[key == #Tab]]) ifTrue:[
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   255
        super keyPress:key x:x y:y.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   256
        key == #Tab ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   257
            self startTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   258
        ] ifFalse:[    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   259
            self startCompletion.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   260
        ].
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   261
        ^ self.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   262
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    "Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    "Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    "Modified: / 09-02-2010 / 20:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
keyPress:key x:x y:y view:aView
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    self keyPress: key x:x y:y
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   274
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   275
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   276
tabCompletion:best options:options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   277
    self updateContentsForLongest:best options:options.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   278
    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   279
    true "options size > 1" ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   280
        optionsHolder value:options.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   281
        self showOptionsWindow
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   282
    ].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   283
    "/ start another job, to update the list
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   284
    self doCompletion.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   285
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   286
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   287
updateContentsForLongest:best options:options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   288
    |newContent oldContent|
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   289
    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   290
    oldContent := ((self contents ? '') asString).
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   291
    newContent := best ? oldContent.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   292
    newContent ~= oldContent ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   293
        self contents:newContent asString.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   294
        self cursorCol:oldContent size + 1.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   295
        oldContent size < newContent size ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   296
            self 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   297
                selectFromLine:1 col:oldContent size + 1
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   298
                toLine:1 col:newContent size.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   299
            typeOfSelection := #paste
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   300
        ].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   301
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
!EditFieldWithCompletion methodsFor:'initialization & release'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
destroy
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    self hideOptionsWindow.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    super destroy.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    "Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
    "Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
initialize
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    super initialize.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
    showOptions := true.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
    optionsHolder := ValueHolder new.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   318
    
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   319
    completionJob := BackgroundJob 
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   320
                        named: 'Edit Field Completion Job'
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   321
                        on:[self doCompletion].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   322
    tabCompletionJob := BackgroundJob 
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   323
                        named: 'Edit Field Tab Completion Job'
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   324
                        on:[self doTabCompletion].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
    "Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
    "Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   328
    "Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
!EditFieldWithCompletion methodsFor:'private'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
doCompletion
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   334
    self doCompletionThenSend:#completion:options:
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   335
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   336
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   337
doCompletionThenSend:selector
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   338
    |oldContents completionInfo options best|
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    oldContents := (self contents ? '') asString.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   341
    completionInfo := self entryCompletionBlock 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   342
                    valueWithOptionalArgument:oldContents
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   343
                    and:self.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   344
    completionInfo isNil ifTrue:[
10885
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   345
        ^ self
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   346
    ].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   347
    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   348
    best := completionInfo first.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   349
    options := completionInfo second.
16715
78d44ccf2a1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 16433
diff changeset
   350
    best isNil ifTrue:[self halt ].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   351
"/    (options includes:best) ifFalse:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   352
"/        best := options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   353
"/                    detect:[:e | e asString startsWith:best asString ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   354
"/                    ifNone:[ best ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   355
"/    ].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   356
"/    options isSortedCollection ifFalse:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   357
"/        options := options asSortedCollection:[:a :b | a displayString < b displayString ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   358
"/    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
    self sensor 
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   360
        pushUserEvent:selector
10885
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   361
        for:self
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   362
        withArguments:(Array with:best with:options).
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    "Created: / 26-07-2009 / 17:45:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    "Modified: / 09-08-2009 / 02:51:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
10885
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   366
    "Modified: / 18-11-2011 / 14:33:56 / cg"
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   367
    "Modified (format): / 20-11-2011 / 09:42:25 / cg"
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   368
    "Modified: / 20-04-2012 / 18:20:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   371
doTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   372
    self doCompletionThenSend:#tabCompletion:options:
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   373
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   374
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
hideOptionsWindow
10913
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   376
    optionsWindow notNil ifTrue:[
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   377
        optionsWindow destroy.
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   378
        optionsView := optionsWindow := nil.
10913
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   379
    ]
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
    "Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
10913
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   383
    "Modified: / 29-11-2011 / 11:27:03 / cg"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
showOptionsWindow
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   387
    | x y w |
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   388
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
    showOptions ifFalse:[^ self].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   390
    optionsWindow notNil ifTrue:[ 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   391
        optionsWindow raise.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   392
        ^ self 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   393
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
    optionsView := SelectionInListModelView new
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
                    textStartLeft: textStartLeft - 2;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
                    listHolder: optionsHolder;
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   398
                    action:[:value | value notNil ifTrue:[self contents:value asString]];
10445
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   399
                    doubleClickAction:[:index | 
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   400
                            self contents:(optionsView at:index) asString.
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   401
                            self hideOptionsWindow.
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   402
                            self accept
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   403
                        ];
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
                    useIndex: false;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
                    " JV: Looks good to me "
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
                    highlightMode: #line;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
                    font:self font;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
                    backgroundColor:self backgroundColor;
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   409
                    delegate: self;
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   410
                    yourself.
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   411
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   412
    x := self absoluteLeft + 5" - optionsView textStartLeft".
17449
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   413
    y := self absoluteTop + self height + 1 + 5 - device captionHeight. "captionHeight > 0 on Win and added in StandardSystemView"
bc8bb3d474de #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 17280
diff changeset
   414
    w := (width * 2) "+ ((optionsView textStartLeft) * 2)".
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
    optionsWindow := StandardSystemView new
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
        bePopUpView;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        beSlave;        
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   419
        origin:x @ y
16728
90111a2e7304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 16715
diff changeset
   420
        extent:(w min: ((Screen current monitorBoundsAt:(x@y)) corner x - x)) @ (fontHeight * 10);
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   421
        yourself.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
    ScrollableView   
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
        forView:optionsView 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        hasHorizontalScrollBar:false 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
        hasVerticalScrollBar:true 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
        miniScrollerH:true 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
        miniScrollerV:false 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
        origin:0.0@0.0 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
        corner:1.0@1.0 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
        in:optionsWindow.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
    optionsWindow open.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
    "Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
    "Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
10913
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   437
    "Modified: / 29-11-2011 / 11:27:13 / cg"
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   438
    "Modified: / 04-04-2012 / 13:08:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
startCompletion
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   443
    completionJob restart.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    "Created: / 26-07-2009 / 17:41:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   446
    "Modified (format): / 03-08-2011 / 17:50:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   447
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   448
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   449
startTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   450
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   451
    tabCompletionJob restart.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
!EditFieldWithCompletion class methodsFor:'documentation'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
version_CVS
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   457
    ^ '$Header$'
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
version_SVN
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   461
    ^ '$Id$'
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
! !
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   463