⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parameterprop.cpp

📁 用于开发Atmel的AVR系列单片机的GCC集成开发环境
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
void __fastcall TForm1::PropExecute(TObject *Sender, bool &CanExecute)
{
 TSynEdit *ActEdit;
 TSynCompletionProposal *comprop;
 AnsiString temp, lookup;
 int pos, ParmNum = 0, ParenCounter, StartPos, SavePos, i;
 int index;
 bool FoundMatch = false;

 comprop = (TSynCompletionProposal *)Sender;
 ActEdit = (TSynEdit *)comprop->Editor;
 i = ActEdit->SelStart;
 // Step Back to end of Last Function for Multiline Support
 for (i = ActEdit->SelStart;i > 1;i--)
 {
  if (ActEdit->Lines->Text[i] == ';' ||
      ActEdit->Lines->Text[i] == '{' ||
      ActEdit->Lines->Text[i] == '}') break;
 }
 temp = ActEdit->Lines->Text.SubString (i, ActEdit->SelStart - i);
 pos = temp.Length ();
 // Parse Text
 while (pos && !FoundMatch)
 {
  if (temp[pos] == ',') // Look for Parameter Number
  {
   ParmNum++;
   pos--;
  }
  else if (temp[pos] == ')') // Check if Number of Open/Close Parenthesis are equal
  {                          // In this case, no Parameter Proposal is displayed
   ParenCounter = 1;
   pos--;
   while (pos && ParenCounter)
   {
    if (temp[pos] == ')') ParenCounter++;
    else if (temp[pos] == '(') ParenCounter--;
    pos--;
   }
  }
  else if (temp[pos] == '(')
  {
   StartPos = pos;
   while (pos && !ValidChars.Contains (temp[pos])) pos--; // Look for Start of Keyword
   if (pos)
   {
    SavePos = pos;
    while (pos && ValidChars.Contains (temp[pos])) pos--;
    pos++;
    lookup = temp.SubString (pos, SavePos - pos + 1);
    // Search Keyword in StringList (Method IndexOf is not case sensitive)
    for (index = 0;index < FuncList->Count;index++)
    {
     if (FuncList->Strings[index] == lookup)
     {
      FoundMatch = true;
      break;
     }
    }
    if (!FoundMatch)
    {
     pos = StartPos;
     pos--;
    }
   }
  }
  else pos--;
 } // End of Parsing

 CanExecute = FoundMatch;
 if (CanExecute)
 {
  if (lookup != comprop->PreviousWord)
  {
   comprop->ItemList->Clear ();
   comprop->ItemList->Add (FormatParameters (FuncList->Strings[index + 1], ParmNum));
  }
 }
 else comprop->ItemList->Clear ();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TForm1::FormatParameters (AnsiString parm, int idx)
{
 AnsiString result = "";
 int i, ParameterIndex = 0;
 bool ParameterPart = false, ActParameter = false;

 // 'Format Parameters' in SynCompletionProposal didn't work correctly
 // so i had to write my own
 for (i = 1;i <= parm.Length ();i++)
 {
  if (parm[i] == ',')
  {
   ParameterIndex++;
   if (ActParameter) result += '\x9';
   ActParameter = false;
  }
  if (parm[i] == ')' && ActParameter)
  {
   result += '\x9';
   ActParameter = ParameterPart = false;
  }
  result += parm[i];
  if (parm[i] == '(') ParameterPart = true;
  if (ParameterPart && ParameterIndex == idx && !ActParameter)
  {
   result += '\x9'; // Enclose selected Parameter Part in ASCII 9 to make it bold
   ActParameter = true;
  }
 }
 return result;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DeleteFuncTable (void)
{
 delete FuncList;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BuildFuncTable (void)
{
 char i;

 for (i = '0';i <= '9';i++) ValidChars << i;
 for (i = 'A';i <= 'Z';i++) ValidChars << i;
 for (i = 'a';i <= 'z';i++) ValidChars << i;
 ValidChars << '_';
 
 FuncList = new TStringList;
 FuncList->LoadFromFile ("paramprop.lst");
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -