Automatic completion enhancements.

[DEVELOPMENT ENVIRONMENT]
* NEW: Automatic completion: The automatic completion and signature popups should not overlap anymore.
* NEW: Automatic completion: More keys now validate the completion then close the popup. Spaces are added according to the Gambas syntax.
This commit is contained in:
gambas 2021-03-02 14:23:11 +01:00 committed by Christof Thalhofer
parent d701739955
commit 6e8828d0c4
6 changed files with 118 additions and 66 deletions

View file

@ -98,7 +98,7 @@ Public Sub CheckCompletion_Timer()
hEditor.Goto(iSave, hEditor.Line) hEditor.Goto(iSave, hEditor.Line)
Endif Endif
Return Goto CHECK_SIGNATURE
Endif Endif
@ -108,6 +108,10 @@ Public Sub CheckCompletion_Timer()
$hModule.CheckCompletion() $hModule.CheckCompletion()
CHECK_SIGNATURE:
Try $hModule.CheckSignature()
End End
Public Sub OnKeyPress() As Boolean Public Sub OnKeyPress() As Boolean
@ -275,3 +279,4 @@ Public Sub GetRightString(sLine As String) As String
If bInside Then Return Mid$(sLine, iPos + 1) If bInside Then Return Mid$(sLine, iPos + 1)
End End

View file

@ -108,6 +108,8 @@ Public Sub Position(hEditor As TextEditor)
hCont = hCont.Parent hCont = hCont.Parent
Loop Loop
FixPosition($hEditor, ByRef iX, ByRef iY)
Dec Application.Busy Dec Application.Busy
If Me.Parent = $hForm And If iX = Me.X And iY = Me.Y And Me.Visible Then Return If Me.Parent = $hForm And If iX = Me.X And iY = Me.Y And Me.Visible Then Return
@ -120,6 +122,46 @@ Public Sub Position(hEditor As TextEditor)
End End
Static Public Sub FixPosition(hEditor As TextEditor, Optional ByRef X As Integer, ByRef Y As Integer)
Dim bCompletion As Boolean
Dim bSignature As Boolean
If IsMissing(X) And If IsMissing(Y) Then
bCompletion = FCompletion.VisibleFrom(hEditor)
bSignature = True
Else
bCompletion = True
bSignature = FSignature.VisibleFrom(hEditor)
Endif
If bCompletion And If bSignature Then
If IsMissing(X) And If IsMissing(Y) Then
X = FCompletion.X
Y = FCompletion.Y
Endif
'Debug Y;; "/";; FSignature.Y;; FSignature.H
If X >= FSignature.X And If X + Me.W <= FSignature.X + FSignature.W Then
If Y = FSignature.Y Then
Y += FSignature.H - 1
Else If Y + FCompletion.H = FSignature.Y + FSignature.H Then
Y -= FSignature.H - 1
Endif
If IsMissing(X) And If IsMissing(Y) Then
FCompletion.Move(X, Y)
Endif
Endif
Endif
End
Public Sub Open(hCompletion As CCompletion, sMode As String, Optional sClass As String, Optional bStatic As Boolean, Optional bHidden As Boolean) Public Sub Open(hCompletion As CCompletion, sMode As String, Optional sClass As String, Optional bStatic As Boolean, Optional bHidden As Boolean)
@ -787,59 +829,61 @@ Public Function ManageKey() As Boolean
Case Key.Up, Key.PageUp Case Key.Up, Key.PageUp
iRow = gvwComp.Row - If(Key.Code = Key.Up, 1, 8) iRow = gvwComp.Row - If(Key.Code = Key.Up, 1, gvwComp.ClientH \ gvwComp.Rows.Height)
If iRow < 0 Then iRow = gvwComp.Rows.Count - 1 If Key.Code = Key.Up Then
If iRow < 0 Then iRow = gvwComp.Rows.Count - 1
Else
If iRow < 0 Then iRow = 0
Endif
gvwComp.Row = iRow gvwComp.Row = iRow
$bUserChoice = True $bUserChoice = True
Case Key.Down, Key.PageDown Case Key.Down, Key.PageDown
iRow = gvwComp.Row + If(Key.Code = Key.Down, 1, 8) iRow = gvwComp.Row + If(Key.Code = Key.Down, 1, gvwComp.ClientH \ gvwComp.Rows.Height)
If iRow >= gvwComp.Rows.Count Then iRow = 0 If Key.Code = Key.Down Then
If iRow >= gvwComp.Rows.Count Then iRow = 0
Else
If iRow >= gvwComp.Rows.Count Then iRow = gvwComp.Rows.Max
Endif
gvwComp.Row = iRow gvwComp.Row = iRow
$bUserChoice = True $bUserChoice = True
Case Key.Home Case Key.Home
If gvwComp.Row = 0 Then If gvwComp.Row = 0 Then Goto HIDE_ME
HideMe
Return
Endif
gvwComp.Row = 0 gvwComp.Row = 0
$bUserChoice = True $bUserChoice = True
Case Key.End Case Key.End
If gvwComp.Row = gvwComp.Rows.Count - 1 Then If gvwComp.Row = gvwComp.Rows.Count - 1 Then Goto HIDE_ME
HideMe
Return
Endif
gvwComp.Row = gvwComp.Rows.Count - 1 gvwComp.Row = gvwComp.Rows.Count - 1
$bUserChoice = True $bUserChoice = True
Case Key.Escape Case Key.Escape, Key.Left, Key.Right
HideMe
Goto HIDE_ME
Case Key.Left, Key.Right
HideMe
Return
Case Key.Enter, Key.Return Case Key.Enter, Key.Return
InsertItem InsertItem
'IF Key.Code <> Key.Tab THEN RETURN 'IF Key.Code <> Key.Tab THEN RETURN
Case Key.Space Case Key.Space
If Key.Control Then If Key.Control Then
If UCase($sText) = "NEW" Then Return If UCase($sText) = "NEW" Then Return
InsertItem(True) InsertItem(True)
Return False
Else Else
HideMe Goto HIDE_ME
Endif Endif
Return False
Case Key.Backspace Case Key.Backspace
'Debug $iLen;; $sText 'Debug $iLen;; $sText
If String.Len($sText) > $iLen Then If String.Len($sText) > $iLen Then
SetText(String.Left$($sText, -1)) SetText(String.Left$($sText, -1))
@ -866,38 +910,49 @@ Public Function ManageKey() As Boolean
$sText &= Key.Text $sText &= Key.Text
Return FindItem() Return FindItem()
Else If InStr(FEditor.IDENT_CAR, Key.Text) Then Else If Key.Text = "[" And If Not $sText Then
Else If InStr(FEditor.IDENT_CAR, Key.Text) And If Key.Text <> "$" Then
If Key.Text = "_" Then If Key.Text = "_" Then
If GetEvents($sText) Then If GetEvents($sText) Then Goto HIDE_ME
HideMe
Return
Endif
Endif Endif
Return SetText($sText & Key.Text, True) Return SetText($sText & Key.Text, True)
Else If Key.Text = "[" And If Not $sText Then Else If $bGambas And If InStr(". A<", $sMode) Then
HideMe If InStr("([.!$", Key.Text) > 0 Then
Else If $bGambas And If InStr("([.!", Key.Text) > 0 And If InStr(". A<", $sMode) Then InsertItem
Return
InsertItem
Else If InStr("=+-*/^", Key.Text) Then
Else
InsertItem(False, " " & Key.Text & " ")
HideMe Return True
Else If InStr(":", Key.Text) Then
InsertItem(False, ": ")
Return True
Endif
Endif Endif
Return False Goto HIDE_ME
Endif Endif
End Select End Select
Return True Return True
HIDE_ME:
HideMe
Return
End End
@ -952,7 +1007,7 @@ Private Function FindItem(Optional bNoInsert As Boolean) As Boolean
End End
Private Function InsertItem(Optional bNoSpace As Boolean) As Boolean Private Function InsertItem(Optional bNoSpace As Boolean, sMore As String) As Boolean
Dim sText As String Dim sText As String
Dim hClass As CClassInfo Dim hClass As CClassInfo
@ -961,7 +1016,7 @@ Private Function InsertItem(Optional bNoSpace As Boolean) As Boolean
Try sText = gvwComp.Current.Text Try sText = gvwComp.Current.Text
If Not sText Then Return True If Not sText Then Return True
If gvwComp[gvwComp.Row, 0].Picture = Picture["$symbol:event"] Then If gvwComp[gvwComp.Row, 0].Picture = Picture["$symbol:event"] Then
If $hForm.IsProc($hEditor[$hEditor.Line].Text) Then If $hForm.IsProc($hEditor[$hEditor.Line].Text) Then
hClass = Project.Documentation.Classes[$sEventClass] hClass = Project.Documentation.Classes[$sEventClass]
@ -973,6 +1028,9 @@ Private Function InsertItem(Optional bNoSpace As Boolean) As Boolean
If bNoSpace Then If bNoSpace Then
If Right(sText) = " " Then sText = Left$(sText, -1) If Right(sText) = " " Then sText = Left$(sText, -1)
Else If sMore Then
If sMore Begins " " Then sText = RTrim(sText)
sText &= sMore
Endif Endif
With $hEditor With $hEditor

View file

@ -77,7 +77,7 @@ Private $hCompletion As CCompletion
Private $hInsertDate As CInsertDate Private $hInsertDate As CInsertDate
Private $bDiffMode As Boolean Private $bDiffMode As Boolean
Private $hTimerSignature As Timer 'Private $hTimerSignature As Timer
'Static Private $cLastClassCount As New Collection 'Static Private $cLastClassCount As New Collection
@ -122,8 +122,8 @@ Public Sub _new(sPath As String)
$hCompletion = New CCompletion(Me) $hCompletion = New CCompletion(Me)
$hInsertDate = New CInsertDate(Me, btnInsertDate) $hInsertDate = New CInsertDate(Me, btnInsertDate)
$hTimerSignature = New Timer As "CheckSignature" ' $hTimerSignature = New Timer As "CheckSignature"
$hTimerSignature.Delay = 50 ' $hTimerSignature.Delay = 50
ReadConfig ReadConfig
Refresh Refresh
@ -381,7 +381,6 @@ Private Sub RefreshLineInfo(Optional bForce As Boolean) As Boolean
Else If $bCheckSignature Or If FSignature.VisibleFrom($hEditor) Then Else If $bCheckSignature Or If FSignature.VisibleFrom($hEditor) Then
$bCheckSignature = False
CheckSignature CheckSignature
Endif Endif
@ -2154,23 +2153,16 @@ Private Function GetExpressionSymbol(aExpr As String[], aType As Integer[]) As C
End End
Private Sub CheckSignature() Public Sub CheckSignature()
If Not $hCompletion.Enabled Then Return
CheckSignature_Timer
'$hTimerSignature.Restart
End
Public Sub CheckSignature_Timer()
Dim sLig As String Dim sLig As String
Dim hSymbol As CSymbolInfo Dim hSymbol As CSymbolInfo
Dim sKind As String Dim sKind As String
$hTimerSignature.Stop If Not $hCompletion.Enabled Then Return
$bCheckSignature = False
'sLig = Left$(edtEditor.GetPurgedLine(edtEditor.Line), edtEditor.Column) & sText 'sLig = Left$(edtEditor.GetPurgedLine(edtEditor.Line), edtEditor.Column) & sText
sLig = String.Left$(Highlight.Purge($hEditor.Current.Text), $hEditor.Column) sLig = String.Left$(Highlight.Purge($hEditor.Current.Text), $hEditor.Column)
Highlight.Analyze(sLig) Highlight.Analyze(sLig)

View file

@ -81,19 +81,20 @@ Private Sub UpdateSignature(Optional hForm As FEditor)
iX -= 3 iX -= 3
iX = Max(0, Min(iX, $hEditor.W - Me.Width)) iX = Max(0, Min(iX, $hEditor.W - Me.Width))
If Not hForm Then If Not hForm Then
Me.Move(iX, iY) Me.Move(iX, iY)
Return Else
If Me.Parent <> hForm Or If iX <> Me.X Or If iY <> Me.Y Or If Me.Visible Then
Me.Reparent(hForm, iX, iY)
Me.Show
Me.Raise
$hEditor.SetFocus
Endif
Endif Endif
If Me.Parent = hForm And If iX = Me.X And iY = Me.Y And Me.Visible Then Return FCompletion.FixPosition($hEditor)
Me.Reparent(hForm, iX, iY)
Me.Show
Me.Raise
$hEditor.SetFocus
End End
Public Sub Position(hForm As FEditor) Public Sub Position(hForm As FEditor)

View file

@ -40,7 +40,6 @@
Border = Border.Plain Border = Border.Plain
{ txtFilter ButtonBox { txtFilter ButtonBox
MoveScaled(0,0,24,4) MoveScaled(0,0,24,4)
Foreground = Color.LightForeground
Picture = Picture["icon:/small/clear"] Picture = Picture["icon:/small/clear"]
Border = False Border = False
} }

View file

@ -62,21 +62,18 @@
Padding = 1 Padding = 1
{ txtFilter ButtonBox { txtFilter ButtonBox
MoveScaled(1,0,5,4) MoveScaled(1,0,5,4)
Foreground = Color.LightForeground
Picture = Picture["icon:/small/clear"] Picture = Picture["icon:/small/clear"]
Border = False Border = False
} }
{ txtFilterExample ButtonBox { txtFilterExample ButtonBox
MoveScaled(7,0,5,4) MoveScaled(7,0,5,4)
Visible = False Visible = False
Foreground = Color.LightForeground
Picture = Picture["icon:/small/clear"] Picture = Picture["icon:/small/clear"]
Border = False Border = False
} }
{ txtFilterSoft ButtonBox { txtFilterSoft ButtonBox
MoveScaled(13,0,6,4) MoveScaled(13,0,6,4)
Visible = False Visible = False
Foreground = Color.LightForeground
Picture = Picture["icon:/small/clear"] Picture = Picture["icon:/small/clear"]
Border = False Border = False
} }