EditFieldWithCompletion.st
author Claus Gittinger <cg@exept.de>
Wed, 29 Jun 2016 18:44:06 +0200
changeset 16715 78d44ccf2a1c
parent 16433 1d9bd92bc6a7
child 16716 12ac8455e023
child 16728 90111a2e7304
permissions -rw-r--r--
#UI_ENHANCEMENT by cg class: EditFieldWithCompletion changed: #doCompletionThenSend: #showOptionsWindow optionswindow does a deselect, which passes a nil. Ignore this. Try with: "GUIBrow" - select "GuiBrowser" then type a colon.
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
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
    18
		focusEventsToIgnore hadFocus completionJob 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
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    documentation to be added.
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
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    |top field label value|
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    top := StandardSystemView new.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    top
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        extent:300 @ 300;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        label:'Live class completion field'.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    value := '' asValue.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    field := (EditFieldWithCompletion new)
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
                origin:10 @ 135 corner:280 @ 165;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
                entryCompletionBlock:[:content | Smalltalk classnameCompletion:content ];
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
                model:value.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    label := (Label new)
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
                origin:10 @ 95 corner:280 @ 115;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                labelChannel:value.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    top
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
        add:field;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        add:label.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    top open
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
examples
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    Opens a LiveCompletionEditField on a class name
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
                                                        [exBegin]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    LiveCompletionEditField example_1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
                                                        [exEnd]
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
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!EditFieldWithCompletion methodsFor:'accepting'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
accept
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    self unselect.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    super accept.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    "Created: / 27-07-2009 / 09:38:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    "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
    96
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
!EditFieldWithCompletion methodsFor:'accessing-behavior'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
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
    ^ showOptions
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
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
    showOptions := aBoolean.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
!EditFieldWithCompletion methodsFor:'accessing-dimensions'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
absoluteLeft
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    | absoluteLeft view |
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    absoluteLeft := 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    view := self.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    [ view notNil ] whileTrue:
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        [absoluteLeft := absoluteLeft + view left - 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
        view := view superView].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    ^absoluteLeft
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    "Created: / 08-08-2009 / 22:30:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
absoluteTop
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    | absoluteTop view |
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    absoluteTop := 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    view := self.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    [ view notNil ] whileTrue:
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
        [absoluteTop := absoluteTop + view top - 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
        view := view superView].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    ^absoluteTop
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    "Created: / 08-08-2009 / 22:30:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
!EditFieldWithCompletion methodsFor:'accessing-mvc'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
optionsHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    ^ optionsHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "Created: / 09-08-2009 / 08:14:02 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
!
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:aValueHolder
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "set the 'options' value holder (automatically generated)"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    optionsHolder := aValueHolder.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "Created: / 09-08-2009 / 08:14:24 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!EditFieldWithCompletion methodsFor:'event handling'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
completion:best options:options 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    |newContent oldContent|
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    oldContent := ((self contents ? '') asString).
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    newContent := ((best isNil or:[ best = oldContent ]) 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
                and:[ options isNilOrEmptyCollection not ]) 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
                    ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
                        options first
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
                        ""options inject:options anyOne
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
                            into:[:shortest :each | 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
                                shortest asString size > each asString size ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
                                    each
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
                                ] ifFalse:[ shortest ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
                            ]""
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
                    ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                    ifFalse:[ best ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    self contents:newContent asString.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    self cursorCol:oldContent size + 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    oldContent size < newContent size ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
        self 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
            selectFromLine:1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
            col:oldContent size + 1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
            toLine:1
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
            col:newContent size
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    "
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   181
    true "options size > 1" ifTrue:[
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
        optionsHolder value:options.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
        self showOptionsWindow
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    ]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    "Created: / 08-08-2009 / 22:02:29 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "Modified: / 09-08-2009 / 08:16:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    "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
   189
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
handleNonCommandKey: char
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    super handleNonCommandKey: char.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    self startCompletion
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    "Modified: / 26-07-2009 / 17:41:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
handlesKeyPress:key inView:aView
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   201
    <resource: #keyboard (#CursorDown #CursorUp)>
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   202
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    ^aView == optionsView and:
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
        [(#( #CursorDown #CursorUp ) includes: key) not].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    "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
   207
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
hasKeyboardFocus:aBoolean
14985
8c2d0c3191db class: EditFieldWithCompletion
Claus Gittinger <cg@exept.de>
parents: 13871
diff changeset
   210
    #todo. "/ @jan: please explain what you are doing here...
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    focusEventsToIgnore > 0 ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
        focusEventsToIgnore := focusEventsToIgnore - 1.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
        "
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
        xxx == 0 ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
            Transcript showCR:'--> taking focus'.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
            self takeFocus.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
            self assert: self windowGroup focusView == self.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
            hadFocus := true.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
        ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
        "            
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
        ^self].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    hadFocus == aBoolean ifTrue:[
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
        ^self
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    ].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    aBoolean 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
        ifTrue:
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
            [self selectAll]
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
        ifFalse:
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
            [self unselect.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
            self hideOptionsWindow].
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    hadFocus := aBoolean.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    ^ super hasKeyboardFocus:aBoolean
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    "Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    "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
   240
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
keyPress:key x:x y:y 
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   243
    "Forward certain events to optionsView if any"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   245
    <resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)>
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   247
    (optionsView notNil 
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   248
     and:[#(CursorDown CursorUp) includesIdentical:key]) ifTrue:[
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   249
        optionsView keyPress:key x:x y:y.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   250
        ^ self.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   251
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   253
    key == #Accept ifTrue:[self hideOptionsWindow].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   254
    key == #Return ifTrue:[self hideOptionsWindow].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   255
    key == #Escape ifTrue:[self hideOptionsWindow].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   256
    (key == #BackSpace or:[key == #Delete or:[key == #Tab]]) ifTrue:[
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   257
        super keyPress:key x:x y:y.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   258
        key == #Tab ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   259
            self startTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   260
        ] ifFalse:[    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   261
            self startCompletion.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   262
        ].
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   263
        ^ self.
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   264
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
12389
83d4d24d847c class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents: 12110
diff changeset
   266
    super keyPress:key x:x y:y
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
    "Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    "Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
    "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
   271
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
keyPress:key x:x y:y view:aView
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
    self keyPress: key x:x y:y
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    "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
   278
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   279
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   280
tabCompletion:best options:options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   281
    self updateContentsForLongest:best options:options.
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
    true "options size > 1" ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   284
        optionsHolder value:options.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   285
        self showOptionsWindow
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
    "/ start another job, to update the list
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   288
    self doCompletion.
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
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   291
updateContentsForLongest:best options:options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   292
    |newContent oldContent|
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   293
    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   294
    oldContent := ((self contents ? '') asString).
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   295
    newContent := best ? oldContent.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   296
    newContent ~= oldContent ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   297
        self contents:newContent asString.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   298
        self cursorCol:oldContent size + 1.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   299
        oldContent size < newContent size ifTrue:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   300
            self 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   301
                selectFromLine:1 col:oldContent size + 1
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   302
                toLine:1 col:newContent size.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   303
            typeOfSelection := #paste
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   304
        ].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   305
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
!EditFieldWithCompletion methodsFor:'initialization & release'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
destroy
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
    self hideOptionsWindow.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
    super destroy.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    "Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
    "Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
initialize
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    super initialize.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    showOptions := true.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    optionsHolder := ValueHolder new.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    focusEventsToIgnore := 0.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   325
    
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   326
    completionJob := BackgroundJob 
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   327
                        named: 'Edit Field Completion Job'
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   328
                        on:[self doCompletion].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   329
    tabCompletionJob := BackgroundJob 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   330
                        named: 'Edit Field Completion Job'
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   331
                        on:[self doTabCompletion].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
    "Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    "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
   335
    "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
   336
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
!EditFieldWithCompletion methodsFor:'private'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
doCompletion
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   341
    self doCompletionThenSend:#completion:options:
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   342
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   343
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   344
doCompletionThenSend:selector
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   345
    |oldContents completionInfo options best|
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
    oldContents := (self contents ? '') asString.
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   348
    completionInfo := self entryCompletionBlock 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   349
                    valueWithOptionalArgument:oldContents
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   350
                    and:self.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   351
    completionInfo isNil ifTrue:[
10885
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   352
        ^ self
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   353
    ].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   354
    
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   355
    best := completionInfo first.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   356
    options := completionInfo second.
16715
78d44ccf2a1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 16433
diff changeset
   357
    best isNil ifTrue:[self halt ].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   358
"/    (options includes:best) ifFalse:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   359
"/        best := options 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   360
"/                    detect:[:e | e asString startsWith:best asString ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   361
"/                    ifNone:[ best ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   362
"/    ].
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   363
"/    options isSortedCollection ifFalse:[
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   364
"/        options := options asSortedCollection:[:a :b | a displayString < b displayString ]
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   365
"/    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    self sensor 
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   367
        pushUserEvent:selector
10885
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   368
        for:self
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   369
        withArguments:(Array with:best with:options).
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    "Created: / 26-07-2009 / 17:45:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
    "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
   373
    "Modified: / 18-11-2011 / 14:33:56 / cg"
9509463c1702 changed: #doCompletion
Claus Gittinger <cg@exept.de>
parents: 10445
diff changeset
   374
    "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
   375
    "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
   376
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   378
doTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   379
    self doCompletionThenSend:#tabCompletion:options:
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   380
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   381
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
hideOptionsWindow
10913
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   383
    optionsWindow notNil ifTrue:[
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   384
        optionsWindow destroy.
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   385
        optionsWindow := nil.
f91715a29502 changed:
Claus Gittinger <cg@exept.de>
parents: 10885
diff changeset
   386
    ]
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    "Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
    "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
   390
    "Modified: / 29-11-2011 / 11:27:03 / cg"
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
showOptionsWindow
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   395
    | x y w |
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   396
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    showOptions ifFalse:[^ self].
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   398
    optionsWindow notNil ifTrue:[ 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   399
        optionsWindow raise.
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   400
        ^ self 
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   401
    ].
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
    optionsView := SelectionInListModelView new
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
                    textStartLeft: textStartLeft - 2;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
                    listHolder: optionsHolder;
16715
78d44ccf2a1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 16433
diff changeset
   406
                    action:[:value | value notNil ifTrue:[ self contents:value asString ] ];
10445
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   407
                    doubleClickAction:[:index | 
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   408
                            self contents:(optionsView at:index) asString.
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   409
                            self hideOptionsWindow.
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   410
                            self accept
70c71811bd97 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 10443
diff changeset
   411
                        ];
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
                    useIndex: false;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
                    " JV: Looks good to me "
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
                    highlightMode: #line;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
                    font:self font;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
                    backgroundColor:self backgroundColor;
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   417
                    delegate: self;
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   418
                    yourself.
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   419
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   420
    x := self absoluteLeft + 5" - optionsView textStartLeft".
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   421
    y := self absoluteTop + self height + 1 + 5.
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   422
    w := (width * 2) + 0"((optionsView textStartLeft) * 2)".
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    optionsWindow := StandardSystemView new
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        bePopUpView;
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
        beSlave;        
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   427
        origin:x @ y
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   428
        extent:(w min: (Screen current width - x)) @ (fontHeight * 10);
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   429
        yourself.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
    ScrollableView   
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
        forView:optionsView 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
        hasHorizontalScrollBar:false 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
        hasVerticalScrollBar:true 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
        miniScrollerH:true 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
        miniScrollerV:false 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
        origin:0.0@0.0 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
        corner:1.0@1.0 
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
        in:optionsWindow.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
    focusEventsToIgnore := 4.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    optionsWindow open.
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
    "Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    "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
   446
    "Modified: / 29-11-2011 / 11:27:13 / cg"
13871
67bf2b738bb3 merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 12389
diff changeset
   447
    "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
   448
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
startCompletion
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
10443
eed0953d70a6 Use BackgroundJob to do the search in background
vrany
parents: 10025
diff changeset
   452
    completionJob restart.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    "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
   455
    "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
   456
!
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   457
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   458
startTabCompletion
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   459
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   460
    tabCompletionJob restart.
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
! !
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
!EditFieldWithCompletion class methodsFor:'documentation'!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
version_CVS
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   466
    ^ '$Header$'
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
!
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
version_SVN
16433
1d9bd92bc6a7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 14985
diff changeset
   470
    ^ '$Id$'
10025
cdf041762f27 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
! !
12110
7231e996222a changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents: 10913
diff changeset
   472