[UPDATE] Build-in FunctionList in progress.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@995 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2012-12-12 22:53:00 +00:00
parent 7e5e59feb5
commit 1216ab3fcb
4 changed files with 161 additions and 41 deletions

View File

@ -1,8 +1,10 @@
Notepad++ v6.2.2 fixed bugs and added features:
Notepad++ v6.2.3 fixed bugs and added features:
1. Fix url link style problem in php document.
2. Add selected line count display on the status bar.
3. Add the capacity to treat path like "\test\test.txt".
1. Fix find "\r\n" bug in RegExpr mode.
2. Change "Delete file" command to "Move to Recycle Bin".
3. Add Remove empty lines feature.
4. Change document default value from ANSI to UTF8 w/o BOM.
5. Enable Word-completion under CJK environment for unicode document.
Included plugins:

View File

@ -560,7 +560,6 @@ bool FileManager::reloadBuffer(BufferID id)
buf->setFormat(format);
buf->setUnicodeMode(uniCookie);
}
}
return res;
}

View File

@ -30,10 +30,11 @@
#include "functionListPanel.h"
#include "ScintillaEditView.h"
void FunctionListPanel::addEntry(const TCHAR *displayText)
void FunctionListPanel::addEntry(const TCHAR *displayText, size_t pos)
{
int index = ::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_GETCOUNT, 0, 0);
::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_INSERTSTRING, index, (LPARAM)displayText);
::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_SETITEMDATA, index, (LPARAM)pos);
}
void FunctionListPanel::removeAllEntries()
@ -42,8 +43,104 @@ void FunctionListPanel::removeAllEntries()
::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_DELETESTRING, 0, 0);
}
// bodyOpenSybe mbol & bodyCloseSymbol should be RE
size_t FunctionListPanel::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol)
{
size_t cntOpen = 1;
void FunctionListPanel::parse(vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *wordToExclude, const TCHAR *regExpr2search, vector< generic_string > dataToSearch, vector< generic_string > data2ToSearch)
int docLen = (*_ppEditView)->getCurrentDocLen();
if (begin >= (size_t)docLen)
return docLen;
generic_string exprToSearch = TEXT("(");
exprToSearch += bodyOpenSymbol;
exprToSearch += TEXT("|");
exprToSearch += bodyCloseSymbol;
exprToSearch += TEXT(")");
int flags = SCFIND_REGEXP | SCFIND_POSIX;
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
int targetStart = (*_ppEditView)->searchInTarget(exprToSearch.c_str(), exprToSearch.length(), begin, docLen);
int targetEnd = 0;
do
{
if (targetStart != -1 && targetStart != -2) // found open or close symbol
{
targetEnd = int((*_ppEditView)->execute(SCI_GETTARGETEND));
// Now we determinate the symbol (open or close)
int tmpStart = (*_ppEditView)->searchInTarget(bodyOpenSymbol, lstrlen(bodyOpenSymbol), targetStart, targetEnd);
if (tmpStart != -1 && tmpStart != -2) // open symbol found
{
cntOpen++;
}
else // if it's not open symbol, then it must be the close one
{
cntOpen--;
}
}
else // nothing found
{
cntOpen = 0; // get me out of here
targetEnd = begin;
}
targetStart = (*_ppEditView)->searchInTarget(exprToSearch.c_str(), exprToSearch.length(), targetEnd, docLen);
} while (cntOpen);
return targetEnd;
}
// This method will
void FunctionListPanel::parse2(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *block, std::vector< generic_string > blockNameToSearch, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, const TCHAR *function, std::vector< generic_string > functionToSearch)
{
if (begin >= end)
return;
int flags = SCFIND_REGEXP | SCFIND_POSIX;
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
int targetStart = (*_ppEditView)->searchInTarget(block, lstrlen(block), begin, end);
int targetEnd = 0;
//foundInfos.clear();
while (targetStart != -1 && targetStart != -2)
{
targetEnd = int((*_ppEditView)->execute(SCI_GETTARGETEND));
// Get class name
int foundPos = 0;
generic_string classStructName = parseSubLevel(targetStart, targetEnd, blockNameToSearch, foundPos);
if (lstrcmp(bodyOpenSymbol, TEXT("")) != 0 && lstrcmp(bodyCloseSymbol, TEXT("")) != 0)
{
targetEnd = getBodyClosePos(targetEnd, bodyOpenSymbol, bodyCloseSymbol);
}
if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it
{
break;
}
int foundTextLen = targetEnd - targetStart;
if (targetStart + foundTextLen == int(end))
break;
// Begin to search all method inside
vector< generic_string > emptyArray;
parse(foundInfos, targetStart, targetEnd, function, functionToSearch, emptyArray, classStructName);
begin = targetStart + (targetEnd - targetStart);
targetStart = (*_ppEditView)->searchInTarget(block, lstrlen(block), begin, end);
}
}
void FunctionListPanel::parse(vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *regExpr2search, vector< generic_string > dataToSearch, vector< generic_string > data2ToSearch, generic_string classStructName)
{
if (begin >= end)
return;
@ -54,7 +151,7 @@ void FunctionListPanel::parse(vector<foundInfo> & foundInfos, size_t begin, size
int targetStart = (*_ppEditView)->searchInTarget(regExpr2search, lstrlen(regExpr2search), begin, end);
int targetEnd = 0;
foundInfos.clear();
//foundInfos.clear();
while (targetStart != -1 && targetStart != -2)
{
targetStart = int((*_ppEditView)->execute(SCI_GETTARGETSTART));
@ -84,15 +181,20 @@ void FunctionListPanel::parse(vector<foundInfo> & foundInfos, size_t begin, size
int foundPos;
if (dataToSearch.size())
{
fi._data = parseSubLevel(targetStart, targetEnd, wordToExclude, dataToSearch, foundPos);
fi._data = parseSubLevel(targetStart, targetEnd, dataToSearch, foundPos);
fi._pos = foundPos;
}
if (data2ToSearch.size())
{
fi._data2 = parseSubLevel(targetStart, targetEnd, wordToExclude, data2ToSearch, foundPos);
fi._data2 = parseSubLevel(targetStart, targetEnd, data2ToSearch, foundPos);
fi._pos2 = foundPos;
}
else if (classStructName != TEXT(""))
{
fi._data2 = classStructName;
fi._pos2 = 0; // change -1 valeur for validated data2
}
}
if (fi._pos != -1 || fi._pos2 != -1) // at least one should be found
@ -106,7 +208,7 @@ void FunctionListPanel::parse(vector<foundInfo> & foundInfos, size_t begin, size
}
generic_string FunctionListPanel::parseSubLevel(size_t begin, size_t end, const TCHAR *wordToExclude, std::vector< generic_string > dataToSearch, int & foundPos)
generic_string FunctionListPanel::parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos)
{
if (begin >= end)
{
@ -114,6 +216,9 @@ generic_string FunctionListPanel::parseSubLevel(size_t begin, size_t end, const
return TEXT("");
}
if (!dataToSearch.size())
return TEXT("");
int flags = SCFIND_REGEXP | SCFIND_POSIX;
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
@ -130,7 +235,7 @@ generic_string FunctionListPanel::parseSubLevel(size_t begin, size_t end, const
if (dataToSearch.size() >= 2)
{
dataToSearch.erase(dataToSearch.begin());
return parseSubLevel(targetStart, targetEnd, wordToExclude, dataToSearch, foundPos);
return parseSubLevel(targetStart, targetEnd, dataToSearch, foundPos);
}
else // only one processed element, so we conclude the result
{
@ -138,16 +243,8 @@ generic_string FunctionListPanel::parseSubLevel(size_t begin, size_t end, const
(*_ppEditView)->getGenericText(foundStr, 1024, targetStart, targetEnd);
if (!isInList(foundStr, wordToExclude))
{
foundPos = targetStart;
return foundStr;
}
else
{
foundPos = -1;
return TEXT("");
}
foundPos = targetStart;
return foundStr;
}
}
@ -159,18 +256,17 @@ void FunctionListPanel::reload()
generic_string funcBegin = TEXT("^[\\s]*");
generic_string qualifier_maybe = TEXT("((static|const)[\\s]+)?");
generic_string returnType = TEXT("[\\w]+");
generic_string space = TEXT("[\\s]+");
generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*|[\\s]+\\*[\\s]+)");
//generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*)");
generic_string classQualifier_maybe = TEXT("([\\w_]+[\\s]*::)?");
generic_string funcName = TEXT("[\\w_]+");
generic_string funcName = TEXT("(?!(if|whil|for))[\\w_]+");
generic_string const_maybe = TEXT("([\\s]*const[\\s]*)?");
generic_string space_maybe = TEXT("[\\s]*");
generic_string params = TEXT("\\([\\n\\w_,*&\\s]*\\)");
generic_string funcBody = TEXT("\\{");
generic_string space_eol_maybe = TEXT("[\\n\\s]*");
//const TCHAR TYPE[] = "";
generic_string function = funcBegin + qualifier_maybe + returnType + space + classQualifier_maybe + funcName + space_maybe + params + const_maybe + space_eol_maybe + funcBody;
generic_string function = funcBegin + qualifier_maybe + returnType + space_starMaybe + classQualifier_maybe + funcName + space_maybe + params + const_maybe + space_eol_maybe + funcBody;
generic_string secondSearch = funcName + space_maybe;
secondSearch += TEXT("\\(");
@ -183,16 +279,32 @@ void FunctionListPanel::reload()
regExpr1.push_back(secondSearch);
regExpr1.push_back(funcName);
parse(fi, 0, docLen, TEXT("if while for"),
//TEXT("^[\\s]*[\\w]+[\\s]+[\\w]*[\\s]*([\\w_]+[\\s]*::)?[\\s]*[\\w_]+[\\s]*\\([\\n\\w_,*&\\s]*\\)[\\n\\s]*\\{"),
function.c_str(),
regExpr1,
//TEXT("[\\w_]+[\\s]*\\("),
regExpr2);
generic_string secondSearch_className = TEXT("[\\w_]+(?=[\\s]*::)");
regExpr2.push_back(secondSearch_className);
generic_string classRegExpr = TEXT("^[\\t ]*(class|struct)[\\t ]+[\\w]+[\\s]*(:[\\s]*(public|protected|private)[\\s]+[\\w]+[\\s]*)?\\{");
vector<generic_string> classRegExprArray;
generic_string str1 = TEXT("(class|struct)[\\t ]+[\\w]+");
generic_string str2 = TEXT("[\\t ]+[\\w]+");
generic_string str3 = TEXT("[\\w]+");
classRegExprArray.push_back(str1.c_str());
classRegExprArray.push_back(str2.c_str());
classRegExprArray.push_back(str3.c_str());
//parse(fi, 0, docLen, function.c_str(), regExpr1, regExpr2);
const TCHAR bodyOpenSymbol[] = TEXT("\\{");
const TCHAR bodyCloseSymbol[] = TEXT("\\}");
parse2(fi, 0, docLen, classRegExpr.c_str(), classRegExprArray, bodyOpenSymbol, bodyCloseSymbol, function.c_str(), regExpr1);
for (size_t i = 0; i < fi.size(); i++)
{
addEntry(fi[i]._data.c_str());
generic_string entryName = TEXT("");
if (fi[i]._pos2 != -1)
{
entryName = fi[i]._data2;
entryName += TEXT("=>");
}
entryName += fi[i]._data;
addEntry(entryName.c_str(), fi[i]._pos);
}
}
@ -217,8 +329,15 @@ BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
{
if (HIWORD(wParam) == LBN_DBLCLK)
{
int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_GETCURSEL, 0, 0);
if (i != LB_ERR)
{
int pos = ::SendDlgItemMessage(_hSelf, IDC_LIST_FUNCLIST, LB_GETITEMDATA, i, (LPARAM)0);
//printInt(pos);
int sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, pos);
(*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line);
(*_ppEditView)->execute(SCI_GOTOPOS, pos);
}
}
return TRUE;
}

View File

@ -91,20 +91,18 @@ public:
// functionalities
void reload();
void addEntry(const TCHAR *displayText);
void addEntry(const TCHAR *displayText, size_t pos);
void removeAllEntries();
void removeEntry();
void modifyEntry();
void update();
void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *wordToExclude, const TCHAR *regExpr2search, std::vector< generic_string > dataToSearch, std::vector< generic_string > data2ToSearch);
generic_string parseSubLevel(size_t begin, size_t end, const TCHAR *wordToExclude, std::vector< generic_string > dataToSearch, int & foundPos);
void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *regExpr2search, std::vector< generic_string > dataToSearch, std::vector< generic_string > data2ToSearch, generic_string classStructName = TEXT(""));
/*
void parse(size_t begin, size_t end, const TCHAR *wordToExclude, const TCHAR *regExpr2search, ...);
bool parseSubLevel(size_t begin, size_t end, const TCHAR *wordToExclude, const TCHAR *regExpr2search, ...);
*/
void parse2(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, const TCHAR *block, std::vector< generic_string > blockNameToSearch, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, const TCHAR *function, std::vector< generic_string > functionToSearch);
protected:
virtual BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -113,5 +111,7 @@ private:
ScintillaEditView **_ppEditView;
std::vector<FuncInfo> _funcInfos;
std::vector< std::pair<int, int> > _skipZones;
generic_string parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos);
size_t getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol);
};
#endif // FUNCLISTPANEL_H