Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / inc ide / IDE_AutoComplete.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  


     CREATE AutoComplForm AS QFORM
      Width = 300
      Height = 120
      BorderStyle = bsToolWindow
      KeyPreview = True
      OnKeyPress = AutoComplList_Enter

      CREATE AutoComplList AS QLISTBOX
       Font.Size = 12
        'Color = IDE.BackGround
       ItemHeight = 28
       Width = AutoComplForm.ClientWidth
       Height = AutoComplForm.ClientHeight
       OnDblClick = AutoComplList_Selected     'onClick is triggered by cursor down
        'OnEnter = AutoComplList_Enter
      END CREATE
     END CREATE


     SUB IDE_AutoCompleteWord
      IF IDE.KeyWordList.ItemCount = 0 THEN  EXIT SUB                                'if list0 is empty then others should be too

      DEFSTR s = IDE_GetKeywordFromText(re.WordAtCursor(), "_(." + Quot$ + sQuot)
      DEFINT L = LEN(s)
      IF INSTR(s, ".") > 0 THEN s = RIGHT$(s, L - INSTR(s, ".")):   L = LEN(s)    'allow for completing properties
      DEFINT TheCase = ASC(RIGHT$(s , 1))                                         'keep track of the case
      s = LCASE$(s)                                                               'autocomplete keword search must be lower case
'   re.SendEditor(SCI_AUTOCSHOW, LEN(s), IDE.KeyWordList.Text)                  'no joy...

      DIM lookupList AS QSTRINGLIST
'        lookupList.AddItems("$apptype", "$include", "$ifdef", "$ifndef", "$endif", "$typecheck", "$undef")
'        lookupList.AddItems("$option", "$optimize", "$escapechars")
        'RQinFB pre compiler commands
      lookupList.AddItems("pre cmd", "killfiles", "kill", "run", "nobeep" "nocon", "adddll", "noadddll" , "diricon", "upx")
      lookupList.AddList IDE.KeyWordList
      lookupList.AddList IDE.KeyWordList2
      lookupList.AddList IDE.KeyWordList3
        'lookupList.Sorted = True           'keep in priority order

      AutoComplList.Clear
    'generate matches
      DEFINT i = 0
      FOR i = 0 TO lookupList.ItemCount - 1
       IF s = LEFT$(lookupList.Item(i), L)  THEN AutoComplList.AddItems(lookupList.Item(i))
        'IF INSTR(lookupList.Item(i) , s) THEN AutoComplList.AddItems(lookupList.Item(i))
      NEXT i

      lookupList.Clear                                                                'dealloc
      IF AutoComplList.ItemCount = 0 THEN EXIT SUB                                    'no match, nothing close

    'insert into text if only one match otherwise show the autocomplete form
      IF AutoComplList.ItemCount = 1 THEN                                             'just one match
       IF re.SelText <> "" THEN re.Set_AnchorPosition(re.Position + L)
       IF (TheCase > 64) AND (TheCase < 91) THEN                                   'upper case
        re.AddStrings(UCASE$(RIGHT$(AutoComplList.Item(0), LEN(AutoComplList.Item(0)) - L)))
        re.SetFocus
       ELSE
        re.AddStrings(RIGHT$(AutoComplList.Item(0), LEN(AutoComplList.Item(0)) - L))
        re.SetFocus
       END IF

      ELSE

       AutoComplList.ItemIndex = 0
       AutoComplForm.Left = Screen.MOUSEX
       IF AutoComplForm.Left > (Screen.Width - AutoComplForm.Width) THEN AutoComplForm.Left = Screen.Width - AutoComplForm.Width
       AutoComplForm.Top = Screen.MOUSEY
       IF AutoComplForm.Top > (Screen.Height - AutoComplForm.Height) THEN AutoComplForm.Top = Screen.Height - AutoComplForm.Height
       AutoComplForm.Show
      END IF

     END SUB



     SUB AutoComplList_Enter(Key AS BYTE)
      IF Key = 13 THEN AutoComplList_Selected
      IF Key = 27 THEN
       AutoComplForm.CLOSE
       re.SetFocus
      END IF
     END SUB


     SUB AutoComplList_Selected

    'this is redundant but less globals...
      DEFSTR s = IDE_GetKeywordFromText(re.WordAtCursor(), "_(." + Quot$ + sQuot)
      DEFINT L = LEN(s)
      DEFINT TheCase = ASC(RIGHT$(s , 1))                                         'keep track of the case
      s = AutoComplList.Item(AutoComplList.ItemIndex)

      IF re.SelText <> "" THEN re.Set_AnchorPosition(re.Position + L)
      IF (TheCase > 64) AND (TheCase < 91) THEN                                   'upper case
       re.AddStrings(UCASE$(RIGHT$(s, LEN(s) -L)))
      ELSE
       re.AddStrings(RIGHT$(s, LEN(s) -L))
      END IF
      AutoComplForm.CLOSE
      re.SetFocus
     END SUB


'
'        '..........List #1 is priority .........
'        DO
'            IF s = LEFT$(IDE.KeyWordList.Item(i), L) THEN                           'do we have a match?
'                FoundIt = True
'                IF (TheCase > 64) AND (TheCase < 91) THEN                           'upper case
'                    re.AddStrings(UCASE$(RIGHT$(IDE.KeyWordList.Item(i), LEN(IDE.KeyWordList.Item(i)) - L)))
'                ELSE
'                    re.AddStrings(RIGHT$(IDE.KeyWordList.Item(i), LEN(IDE.KeyWordList.Item(i)) - L))
'                END IF
'                EXIT DO                                                             'now bail out
'
'            END IF
'            i++
'        LOOP UNTIL (i > IDE.KeyWordList.ItemCount-1) OR FoundIt 'OR (LEFT$(IDE.KeyWordLookUp.Item(i), 1) > LEFT$(s, 1))
'
'
'        '..........search list #2.........
'        IF (FoundIt = False) AND (IDE.KeyWordList2.ItemCount > 0) THEN
'        i = 0
'        DO
'            IF s = LEFT$(IDE.KeyWordList2.Item(i), L) THEN     'do we have a match?
'
'                FoundIt = True
'                IF (TheCase > 64) AND (TheCase < 91) THEN                           'upper case
'                    re.AddStrings(UCASE$(RIGHT$(IDE.KeyWordList2.Item(i), LEN(IDE.KeyWordList2.Item(i)) - L)))
'                ELSE
'                    re.AddStrings(RIGHT$(IDE.KeyWordList2.Item(i), LEN(IDE.KeyWordList2.Item(i)) - L))
'                END IF
'                EXIT DO                                         'now bail out
'
'            END IF
'            i++
'        LOOP UNTIL (i > IDE.KeyWordList2.ItemCount-1) OR FoundIt 'OR (LEFT$(IDE.KeyWordLookUp.Item(i), 1) > LEFT$(s, 1))
'        END IF
'
'
'        '..........search list #3............
'        IF (FoundIt = False) AND (IDE.KeyWordList3.ItemCount > 0) THEN
'        i = 0
'        DO
'            IF s = LEFT$(IDE.KeyWordList3.Item(i), L) THEN                      'do we have a match?
'
'                FoundIt = True
'                IF (TheCase > 64) AND (TheCase < 91) THEN                           'upper case
'                    re.AddStrings(UCASE$(RIGHT$(IDE.KeyWordList3.Item(i), LEN(IDE.KeyWordList3.Item(i)) - L)))
'                ELSE
'                    re.AddStrings(RIGHT$(IDE.KeyWordList3.Item(i), LEN(IDE.KeyWordList3.Item(i)) - L))
'                END IF
'                EXIT DO                                         'now bail out
'
'            END IF
'            i++
'        LOOP UNTIL (i > IDE.KeyWordList3.ItemCount-1) OR FoundIt 'OR (LEFT$(IDE.KeyWordLookUp.Item(i), 1) > LEFT$(s, 1))
'        END IF
'
'        s = ""      'dealloc
'    END IF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2024-4-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:03