EditTextViewCompletionSupport.st
author Claus Gittinger <cg@exept.de>
Wed, 18 Dec 2019 19:08:06 +0100
changeset 6768 c9329ef316b5
parent 6757 78d263683942
child 6802 b6d0911d51e7
permissions -rw-r--r--
regenerated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6757
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     1
"
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     2
 COPYRIGHT (c) 2018 by eXept Software AG
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     3
              All Rights Reserved
6746
cc13f6cb0f10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6740
diff changeset
     4
6757
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     5
 This software is furnished under a license and may be used
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     6
 only in accordance with the terms of that license and with the
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     7
 inclusion of the above copyright notice.  This software may not
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     8
 be provided or otherwise made available to, or used by, any
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
     9
 other person.  No title to or ownership of the software is
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    10
 hereby transferred.
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    11
"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
"{ Package: 'stx:libwidg' }"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
    14
"{ NameSpace: Smalltalk }"
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
    15
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
Object subclass:#EditTextViewCompletionSupport
5772
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    17
	instanceVariableNames:'completionView completionProcess editView autoSelect
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    18
		editViewLostFocusBlock'
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
	classVariableNames:'LastCompletions'
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
	poolDictionaries:''
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
	category:'Views-Text'
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
!EditTextViewCompletionSupport class methodsFor:'documentation'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
6757
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    26
copyright
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    27
"
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    28
 COPYRIGHT (c) 2018 by eXept Software AG
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    29
              All Rights Reserved
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    30
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    31
 This software is furnished under a license and may be used
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    32
 only in accordance with the terms of that license and with the
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    33
 inclusion of the above copyright notice.  This software may not
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    34
 be provided or otherwise made available to, or used by, any
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    35
 other person.  No title to or ownership of the software is
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    36
 hereby transferred.
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    37
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    38
"
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    39
!
78d263683942 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6746
diff changeset
    40
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
documentation
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
    An abstract supperclass to support completion in text views.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
    Individual completion engines may create a subclass of 
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
    EditTextCompletionSupport and customize it.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
5788
3043bff6248c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 5772
diff changeset
    47
    Basically, they have to implement #computeCompletions
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
    [author:]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
        Claus Gittinger
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
    [instance variables:]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
    [class variables:]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
    [see also:]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
!EditTextViewCompletionSupport class methodsFor:'instance creation'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
for:anEditView
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
    ^ self new editView:anEditView
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
!EditTextViewCompletionSupport class methodsFor:'queries'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
isAbstract
5509
b5286dea20fa #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
    70
    ^ self == EditTextViewCompletionSupport
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
    "Created: / 26-09-2013 / 16:22:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
!EditTextViewCompletionSupport methodsFor:'accessing'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
editView:anEditTextView
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
    editView := anEditTextView.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
!EditTextViewCompletionSupport methodsFor:'events'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
buttonPress:button x:x y:y
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
    self closeCompletionView.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
editViewLostFocus
5772
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    88
    "this is a hack for Windows:
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    89
     on windows, an activate:false event is first sent to my textView,
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    90
     then an activate is sent to the completion popup.
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    91
     this is done BEFORE the buttonPress event is delivered.
5891
584219e0a322 #OTHER by mawalch
mawalch
parents: 5788
diff changeset
    92
     therefore, allow for the activate of the completionMenu and its button event to be processed.
5772
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    93
     before forcing it to be closed..."
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
    94
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
    completionView notNil ifTrue:[
4808
b37597d2df93 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
    96
        editView graphicsDevice anyButtonPressed ifTrue:[
b37597d2df93 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
    97
            editView sensor pushUserEvent:#editViewLostFocus for:self.
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
    98
        ] ifFalse:[
6746
cc13f6cb0f10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6740
diff changeset
    99
            "/ don't do it here - give code completion view a chance to call its select action
cc13f6cb0f10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6740
diff changeset
   100
            "/ (bug was: sometimes, the completion did not arrive)
cc13f6cb0f10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6740
diff changeset
   101
            "/ self closeCompletionView.
cc13f6cb0f10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6740
diff changeset
   102
            editView sensor pushUserEvent:#closeCompletionView for:self
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   103
        ]
4808
b37597d2df93 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
   104
    ].
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
handleKeyPress:key x:x y:y
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
    "return true, if I have eaten this keypress"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
6734
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   110
    <resource: #keyboard ( #'Control_L' #Ctrl #'Control_R' #Control 
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   111
                           #Tab #CursorDown #CursorUp #CursorLeft #CursorRight #Return
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   112
                           #Escape #BackSpace
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   113
                           #'Shift_L' #'Shift_R' #Shift) >
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   114
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   115
    |ch eatCursorLeftOrRight eatCursorUpDown sensor|
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   117
    "/ completeImmediate := UserPreferences current immediateCodeCompletion.
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   118
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   119
    sensor := editView sensor.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   120
    
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
    "/ open on CTRL- or TAB-key?
6370
b5cd4fd52b3c #BUGFIX by sr
sr
parents: 6315
diff changeset
   122
    (completionView notNil and:[completionView realized]) ifFalse:[
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
        editView hasSelection ifFalse:[
6650
340342c01ce4 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   124
            ch := editView characterBeforeCursor.
6666
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   125
6650
340342c01ce4 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   126
            (ch notNil "/ i.e. not at begin of line
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   127
              and:[ ch isLetterOrDigitOrUnderline or:[ch == Character space]]
6666
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   128
            ) ifTrue:[
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
                (key == #Control_L or:[ key == #Ctrl or:[ key == #Control_R or:[ key == #Control]]]) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
                    UserPreferences current codeCompletionOnControlKey ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
                        autoSelect := true.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
                        self updateCompletionList
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
                    ]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
                ].
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   135
                ((key == #Tab) and:[sensor shiftDown not]) ifTrue:[
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
                    UserPreferences current codeCompletionOnTabKey ifTrue:[
6315
1362b6366e09 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 6197
diff changeset
   137
                        "/ only if the character after the cursor is a separator!!
1362b6366e09 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 6197
diff changeset
   138
                        "/ otherwise, we cannot insert tabs 
6370
b5cd4fd52b3c #BUGFIX by sr
sr
parents: 6315
diff changeset
   139
                        ((ch := editView characterAfterCursor) isNil or:[ch isSeparator]) ifTrue:[
6315
1362b6366e09 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 6197
diff changeset
   140
                            autoSelect := true.
1362b6366e09 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 6197
diff changeset
   141
                            self updateCompletionList.
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   142
                            "/ ^ true
6315
1362b6366e09 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 6197
diff changeset
   143
                        ].
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
                    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   145
                ]
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   146
            ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
        ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   148
        ^ false.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   149
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   150
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   151
    "/ the completion view is already open
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   152
    "/ determine, if the key should be forwarded to it (cursor keys)
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   153
6197
3a3a1cabb663 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5995
diff changeset
   154
    editView cursorCol <= 1 ifTrue:[^ false].
3a3a1cabb663 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5995
diff changeset
   155
    
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   156
    "/ key for completion view ? (careful: do not forward too many, it would disturb user's typing)
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
    key isCharacter ifFalse:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   158
        "/ forward to menu
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   159
        (completionView notNil) ifTrue:[
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   160
            "/never
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   161
            eatCursorLeftOrRight := false.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   162
"/                                    completeImmediate not
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   163
"/                                    or:[ sensor shiftDown 
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   164
"/                                    or:[ sensor ctrlDown ]].
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   165
            "/ only with shift or ctrl
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   166
            eatCursorUpDown := 
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   167
                    (UserPreferences current codeCompletionViewKeyboardNavigationNeedsModifier not)
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   168
                    or:[ sensor shiftDown 
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   169
                    or:[ sensor ctrlDown]].
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   170
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   171
            ((key == #CursorDown and:[eatCursorUpDown])
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   172
                or:[ (key == #CursorUp and:[eatCursorUpDown])
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   173
                or:[ ((key == #CursorLeft) and:[eatCursorLeftOrRight])
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   174
                or:[ ((key == #CursorRight) and:[eatCursorLeftOrRight])
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   175
                or:[ ((key == #Return) and:[ completionView hasSelection ])
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
            ]]]]) ifTrue:[
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   177
                "/ forward to completion view
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   178
                completionView sensor pushAction:[ completionView keyPress:key x:0 y:0 ].
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   179
                ^ true.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
            ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   181
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   182
            (key == #Control_L or:[ key == #Control_R or:[ key == #Control or:[ key == #Ctrl ]]]) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   183
                "/ CTRL is a toggle
5064
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   184
"/                self closeCompletionView.   
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   185
"/                ^ true.
55e4260c1ea1 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
   186
                ^ false "/ don't eat
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   187
            ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   188
            (key == #Escape) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   189
                self closeCompletionView.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   190
                ^ true  "/ EAT
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
            ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   192
            "/ shift does not close
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   193
            (key == #Shift_L or:[ key == #Shift_R or:[ key == #Shift]]) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   194
                ^ false "/ don' eat
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   195
            ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   196
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   197
            (key == #BackSpace) ifTrue:[
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   198
                ^ false "/ don' eat
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   199
            ].
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
            self closeCompletionView.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
            ^ false "/ don' eat
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   202
        ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   203
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   204
    ^ false.
6197
3a3a1cabb663 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5995
diff changeset
   205
3a3a1cabb663 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5995
diff changeset
   206
    "Modified: / 24-08-2017 / 21:32:52 / cg"
6370
b5cd4fd52b3c #BUGFIX by sr
sr
parents: 6315
diff changeset
   207
    "Modified: / 03-07-2018 / 13:41:45 / sr"
6594
c347f9e598d7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 6433
diff changeset
   208
    "Modified: / 05-06-2019 / 17:06:15 / Claus Gittinger"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   209
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   210
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   211
postKeyPress:key
6734
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   212
    <resource: #keyboard ( #'BasicBackspace' #BackSpace)>
e8d5a97c068c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6722
diff changeset
   213
6666
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   214
    |doComplete ch w|
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   215
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   216
    UserPreferences current immediateCodeCompletion ifFalse:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   217
        "/ only update, if already open
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
        completionView isNil ifTrue:[^ self].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
6650
340342c01ce4 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   221
    "/ (completionView notNil and:[completionView realized]) ifTrue:[^ self].
340342c01ce4 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   222
    editView hasSelection ifTrue:[^ self].
6666
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   223
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   224
false ifTrue:[
6650
340342c01ce4 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   225
    ch := editView characterBeforeCursor.
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   226
    (ch notNil and:[ch isLetterOrDigitOrUnderline]) ifFalse:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   227
        ^ self
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   228
    ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   229
].
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
    (key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
        autoSelect := false.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   232
        self updateCompletionList.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   233
        ^ self
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   234
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   235
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   236
    key isCharacter ifTrue:[
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   237
        (doComplete := key isSeparator not) ifFalse:[
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   238
            "/ also on a separator, but only if at the end of a non-empty line
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   239
            doComplete := editView lineStringBeforeCursor withoutSeparators notEmpty.
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   240
        ].
6666
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   241
        doComplete ifTrue:[
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   242
            w := editView wordBeforeCursor.
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   243
            w isNil ifTrue:[
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   244
                doComplete := false
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   245
            ] ifFalse:[
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   246
                "/ self halt.
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   247
            ]
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   248
        ].
7aa9f3c69ba2 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 6659
diff changeset
   249
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   250
        doComplete ifFalse:[
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   251
            self closeCompletionView
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   252
        ] ifTrue:[
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   253
            autoSelect := false.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   254
            self updateCompletionList.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   255
        ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   256
        ^ self
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   257
    ].
5772
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   258
!
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   259
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   260
startTimeoutForEditViewLostFocus
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   261
    "see comment in #editViewLostFocus"
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   262
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   263
    editViewLostFocusBlock isNil ifTrue:[
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   264
        editViewLostFocusBlock := [self editViewLostFocus].
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   265
"/ Pro: This saves some warnings about timeout for dead process.
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   266
"/ Con: Can add more than a single exit action
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   267
"/        Processor activeProcess 
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   268
"/            addExitAction:[Processor removeTimedBlock:editViewLostFocusBlock].
5772
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   269
    ].
fa9c46bd7a1b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5705
diff changeset
   270
    Processor addTimedBlock:editViewLostFocusBlock afterMilliseconds:200.
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   271
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   272
    "Modified: / 24-10-2019 / 18:44:41 / Stefan Vogel"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   273
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   274
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   275
!EditTextViewCompletionSupport methodsFor:'private'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   276
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   277
computeAndShowCompletions
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   278
    "compute completions, then push an event to show them.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   279
     Notice: this is interrupted and terminated if the user presses another key
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   280
     within delayTime"
6657
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   281
    
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   282
    |delayTime completions startTime restTime|
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   283
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   284
    delayTime := 0.4 seconds.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   285
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   286
    startTime := Timestamp now.
6657
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   287
    completions := self computeCompletions.
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   288
    completions notEmptyOrNil ifTrue:[
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   289
        restTime := (startTime + delayTime) - Timestamp now.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   290
        restTime positive ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   291
            Delay waitFor:restTime
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   292
        ].
6657
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   293
        self assert:completions isArray.
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   294
        self assert:completions size == 4.
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   295
        editView sensor
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   296
            pushUserEvent:#'suggestionsArrived:implementations:actions:autoSelect:'
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   297
            for:self
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   298
            withArguments:completions
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   299
    ].
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   300
6657
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   301
    "Created: / 15-07-2019 / 17:29:54 / Claus Gittinger"
90673a5bc399 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   302
    "Modified: / 24-07-2019 / 07:53:35 / Claus Gittinger"
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   303
!
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   304
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   305
computeCompletions
6659
bf9e461b517c #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6657
diff changeset
   306
    "compute the completions.
bf9e461b517c #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6657
diff changeset
   307
     Don't know how to do this here."
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   308
6659
bf9e461b517c #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 6657
diff changeset
   309
    ^ nil
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   310
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   311
    "Created: / 26-09-2013 / 17:35:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   312
!
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   313
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   314
release
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   315
    self stopCompletionProcess.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   316
    self closeCompletionView.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   317
    super release
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   318
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   319
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   320
startCompletionProcess
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   321
    "start the code completion process in the background"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   322
6627
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   323
    |initialList cursorX cursorY p|
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   324
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   325
    "/ terminate any previous process
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   326
    self synchronized:[
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   327
        self stopCompletionProcess.
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   328
    ].
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   329
    
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   330
    (editView sensor hasKeyPressEventFor:nil) ifTrue:[ 
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   331
        "/ 'cl' printCR.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   332
        self closeCompletionView. 
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   333
        ^ self
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   334
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   335
    ((cursorX := editView xOfCursor) isNil
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   336
    or:[ (cursorY := editView yOfCursor) isNil ]) ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   337
        "/ no cursor - user is selecting, or cursor has been scrolled out of sight.
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   338
        "/ 'cl2' printCR.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   339
        self closeCompletionView. 
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   340
        ^ self
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   341
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   342
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   343
    initialList := #( 'Busy...' ).
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   344
    completionView notNil ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   345
"/        initialList := completionView list.
4817
597e3af71218 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4808
diff changeset
   346
    ].
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   347
    "/ self openCompletionView:initialList.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   348
6627
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   349
    completionProcess := p := 
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   350
        [
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   351
            [
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   352
                "/ protect end-user applications from errors
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   353
                Error handle:[:ex |
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   354
                    (ParseError accepts:ex creator) ifFalse:[
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   355
                        Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ ex reject ]
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   356
                    ].
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   357
                ] do:[ 
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   358
                    |startTime|
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   359
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   360
false ifTrue:[
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   361
                    startTime := Timestamp now.
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   362
                    "/ Wait a while to give user chance finish typing.
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   363
                    "/ This also reduces CPU consumption by avoiding
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   364
                    "/ useless computation
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   365
                    Delay waitForMilliseconds: 200.
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   366
].
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   367
                    (editView topView isDebugView) ifTrue:[
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   368
                        ControlInterrupt ignoreIn:[
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   369
                            self computeAndShowCompletions.
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   370
                        ].    
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   371
                    ] ifFalse:[    
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   372
                        self computeAndShowCompletions.
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   373
                    ].
6391
935a745d3c55 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
   374
                ].
6627
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   375
                p == completionProcess ifTrue:[
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   376
                    completionProcess := nil
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   377
                ]
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   378
            ] ifCurtailed:[
6433
fa1517a0ad10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6432
diff changeset
   379
                "/ completionView notNil ifTrue:[
fa1517a0ad10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6432
diff changeset
   380
                "/    completionView topView destroy
fa1517a0ad10 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6432
diff changeset
   381
                "/ ].    
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   382
            ].    
6627
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   383
        ] newProcess.
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   384
    "/ p priority:(Processor activePriority - 1).
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   385
    p priorityRange:(Processor activePriority-1 to:Processor activePriority).
322e0fc5efc4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6594
diff changeset
   386
    p resume.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   387
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   388
    "Modified: / 26-09-2013 / 17:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6632
8670224f9fd5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6627
diff changeset
   389
    "Modified: / 15-07-2019 / 17:30:55 / Claus Gittinger"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   390
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   391
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   392
stopCompletionProcess
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   393
    "kill any background completion process"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   394
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   395
    |p|
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   396
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   397
    (p := completionProcess) notNil ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   398
        completionProcess := nil.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   399
        p terminate.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   400
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   401
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   402
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   403
updateCompletionList
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   404
    "called for keypress events"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   405
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   406
    self startCompletionProcess.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   407
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   408
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   409
!EditTextViewCompletionSupport methodsFor:'private-API'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   410
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   411
adjustSizeOfCompletionView:topView
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   412
    |screenBounds screenBoundsCorner 
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   413
     helpViewsExtent helpViewsWidth helpViewsHeight
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   414
     textCursorPosInTextView textCursorPosOnScreen 
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   415
     newX newY cursorX cursorY distanceFromCursorIfBelow distanceFromCursorIfAbove|
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   416
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   417
    textCursorPosInTextView := editView xOfCursor @ editView yOfCursor.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   418
    textCursorPosOnScreen := editView device 
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   419
                    translatePoint:textCursorPosInTextView 
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   420
                    fromView:editView toView:nil.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   421
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   422
    cursorX := textCursorPosOnScreen x.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   423
    cursorY := textCursorPosOnScreen y.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   424
    distanceFromCursorIfAbove := editView font height.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   425
    distanceFromCursorIfBelow := distanceFromCursorIfAbove * 2.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   426
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   427
    topView resizeToFit.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   428
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   429
    "/ make sure, the window is visible
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   430
    screenBounds := topView device monitorBoundsAt:editView topView origin.
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   431
    screenBoundsCorner := screenBounds corner.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   432
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   433
    helpViewsExtent := topView extent.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   434
    helpViewsWidth := helpViewsExtent x.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   435
    helpViewsHeight := helpViewsExtent y.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   436
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   437
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   438
    newX := cursorX + 20.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   439
    newY := cursorY + distanceFromCursorIfBelow.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   440
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   441
    "/ if it does not lie completely inside the screen, move it     
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   442
    (newX + helpViewsWidth) > screenBoundsCorner x ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   443
        newX := screenBoundsCorner x - helpViewsWidth.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   444
    ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   445
    (newY + helpViewsHeight) > screenBoundsCorner y ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   446
        newY := screenBoundsCorner y - helpViewsHeight.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   447
    ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   448
    newX < 0 ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   449
        newX := 0
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   450
    ].    
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   451
    newY < 0 ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   452
        newY := 0
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   453
    ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   454
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   455
    "/ topView origin:(newX @ newY).
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   456
    (cursorY between:newY and:(newY + helpViewsHeight)) ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   457
        "/ lift it towards the top
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   458
        newY := cursorY - distanceFromCursorIfAbove - helpViewsHeight.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   459
    ] ifFalse:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   460
        "/ (cursorX between:newX and:(newX + helpViewsWidth)) ifTrue:[
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   461
        "/     self halt.
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   462
        "/ ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   463
    ].
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   464
    topView origin:(newX @ newY).
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   465
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   466
    "Modified: / 24-10-2019 / 18:41:07 / Stefan Vogel"
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   467
!
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   468
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   469
closeCompletionView
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   470
    |v|
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   471
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   472
    (v := completionView) notNil ifTrue:[
6722
e302ad05e8c1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6721
diff changeset
   473
        "/ completionView := nil.
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   474
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   475
        "/ let it close itself - avoids synchronization problems
6722
e302ad05e8c1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6721
diff changeset
   476
        v sensor pushAction:[ completionView := nil. v topView destroy ]
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   477
    ].
6432
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   478
03625766b591 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6391
diff changeset
   479
    "Modified (format): / 14-09-2018 / 22:08:05 / Claus Gittinger"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   480
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   481
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   482
openCompletionView
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   483
    "Opens the completion view with an initial list. Called as soon as
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   484
     completion is initiated but completion options are not yet computed."
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   485
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   486
    self openCompletionView: (Array with: 'Busy...')
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   487
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   488
    "Created: / 26-09-2013 / 17:06:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   489
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   490
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   491
openCompletionView: list
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   492
    "Makes sure the completion view is opened and with given `list`."
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   493
    
6711
1b1833b56e01 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6704
diff changeset
   494
    |cursorX cursorY textCursorPosInTextView textCursorPosOnScreen movePos topView|
1b1833b56e01 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6704
diff changeset
   495
6712
293d6dde8845 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6711
diff changeset
   496
    "/ race here - openCompletionView may arrive late, when the user started to do something else
293d6dde8845 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 6711
diff changeset
   497
    "/ (scroll or select). Then it could happen the no cursor is currently visible.
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   498
"/ Disable dead code:
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   499
"/    cursorX := editView xOfCursor.
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   500
"/    cursorY := editView yOfCursor.
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   501
"/    (cursorX isNil or:[cursorY isNil]) ifTrue:[^ self].
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   502
"/
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   503
"/    "/ move the window away from the text cursor (to not cover what user types in)
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   504
"/    "/ get the screen-relative position of the text cursor
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   505
"/    textCursorPosInTextView := cursorX @ cursorY.
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   506
"/    
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   507
"/    "/ care for the scroll-offset (xOfCursor/yOFCursor gives me               
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   508
"/    textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0).
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   509
"/    
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   510
"/    textCursorPosOnScreen := editView device 
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   511
"/                    translatePoint:textCursorPosInTextView 
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   512
"/                    fromView:editView toView:nil.
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   513
"/
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   514
"/    "/ currently, we have to stay away a bit, to avoid getting the focus
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   515
"/    "/ this will be somewhat to the down-right of the textCursor
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   516
"/    movePos := textCursorPosOnScreen + (60 @ (editView font height)).
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   517
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   518
    completionView isNil ifTrue:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   519
        completionView := CodeCompletionHelpMenuView new.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   520
        completionView name:'completion'.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   521
        completionView level:0.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   522
        completionView list:list.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   523
        completionView enable:false.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   524
        completionView extent:completionView preferredExtentForContents.
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   525
        "/ completionView font: editView font.
6704
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   526
        topView := CodeCompletionHelpView with:(HVScrollableView forView:completionView).
0b9dff1f67d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6666
diff changeset
   527
        "/ topView := CodeCompletionHelpView with:completionView.
4968
254b5e81199a class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4824
diff changeset
   528
        topView editView:editView.
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   529
    ] ifFalse:[
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   530
        completionView list:list.
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   531
        topView := completionView topView.
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   532
    ].
5939
c22f1eec3ffd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5891
diff changeset
   533
    
4824
e3806247e940 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 4819
diff changeset
   534
    topView ~~ completionView ifTrue:[
6740
c5b2dda450d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6734
diff changeset
   535
        topView shown ifTrue:[
c5b2dda450d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6734
diff changeset
   536
            self adjustSizeOfCompletionView:topView.
c5b2dda450d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 6734
diff changeset
   537
        ].
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   538
    ].
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   539
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   540
    "Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6721
1cd09d31cb4a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 6712
diff changeset
   541
    "Modified: / 24-10-2019 / 17:57:57 / Stefan Vogel"
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   542
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   543
6391
935a745d3c55 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
   544
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   545
!EditTextViewCompletionSupport class methodsFor:'documentation'!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   546
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   547
version
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   548
    ^ '$Header$'
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   549
!
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   550
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   551
version_CVS
5410
78eefa911c26 class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
   552
    ^ '$Header$'
4788
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   553
! !
8ac7fbb56cb5 initial checkin
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   554