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