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