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