[Gambas-user] Auto property type filling

Bruce Steers bsteers4 at gmail.com
Thu May 5 10:36:43 CEST 2022


On Wed, 4 May 2022 at 11:45, Benoît Minisini <g4mba5 at gmail.com> wrote:

> Le 04/05/2022 à 12:03, Bruce Steers a écrit :
> > I want to add a way to auto insert property types as I enter them.
> >
> > Eg.
> > if i type...
> > Dim bMySwitch
> > or
> > Private/Public bMySwitch
> > Then when hitting space i want it to auto-detect I'm defining a variable
> > and see the lowercase letter followed by an uppercase letter and use the
> > lowercase to auto-add the *As Boolean* bit.
> >
> > My question is...
> >
> > Where is the best place to add code for it?
> > Would it be the in the texteditor gambas mode class or in
> > Completion/FCompletion classes somewhere?
> >
> > Any suggestions/advice appreciated Ben (or anyone else)
> >
> > Cheers
> > BruceS
> >
> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> It's not easy to explain, give me some time! I just recover from surgery
> for appendicitis.
>


Oh no!!  wishing wellness and a speedy recovery to you kind sir.


My method thus far (an initial draft) is to add it to FCompletion.class
Open() method line 207 where Case " " is true
I have changed...

    Case " "
      $bGambas = True
      $sText = ""
      FillWithClasses

To...
    Case " "
      $bGambas = True
      $sText = ""
      Dim sSplit As String[] = Split($hEditor.Current.Text, " ", Null, True)
      If sSplit.Count >= 3 Then
        If LCase(sSplit[sSplit.Max]) = "as" Then
          If LCase(sSplit[0]) = "static" Then sSplit.Remove(0, 1)
          sSplit[0] = LCase(sSplit[0])
          $sText = Left(sSplit[1])
          Select sSplit[0]
            Case "dim", "public", "private"
              If IsUCase(sSplit[1][1, 1]) Then
              Select $sText
                Case "b"
                  $sText = "Boolean"
                Case "s"
                  $sText = "String"
                Case "i"
                  $sText = "Integer"
                Case "v"
                  $sText = "Variant"
                Case "f"
                  $sText = "Float"
              End Select
               If Len($sText) > 1 Then
                $hEditor.Insert($sText)
                $hEditor.Select($hEditor.Column - Len($sText),
$hEditor.Line, $hEditor.Column, $hEditor.Line)
               Endif
              Endif
          End Select
        Endif
      Endif
      FillWithClasses

So it only auto-fills after typing *As* and only if 1st char of declaration
is one of f,s,b,i,v and 2nd char is upper case and Dim,Private or Public is
1st word (minus Static)

It inserts the text selected so it can be erased in one go pressing
backspace if a different class name is to be used.

Seems to work okay for now, I'm sure there's a better way but not in any
rush for refining it.

Take care Ben, Get well soon

BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220505/0ab3fc24/attachment-0001.htm>


More information about the User mailing list