[CLEAN] Clean up the code.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1176 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 11 years ago
parent 0683267b5e
commit f1e1cfbe90

@ -3384,7 +3384,7 @@ void Notepad_plus::showAutoComp()
{
bool isFromPrimary = _pEditView == &_mainEditView;
AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub;
autoC->showAutoComplete();
autoC->showApiComplete();
}
void Notepad_plus::showPathCompletion()

@ -40,40 +40,44 @@ static bool isInList(generic_string word, const vector<generic_string> & wordArr
return false;
};
bool AutoCompletion::showAutoComplete() {
bool AutoCompletion::showApiComplete()
{
if (!_funcCompletionActive)
return false;
// calculate entered word's length
int curPos = int(_pEditView->execute(SCI_GETCURRENTPOS));
int line = _pEditView->getCurrentLineNumber();
int startLinePos = int(_pEditView->execute(SCI_POSITIONFROMLINE, line ));
int startWordPos = startLinePos;
int len = curPos-startLinePos;
int len = curPos - startLinePos;
char * lineBuffer = new char[len+1];
_pEditView->getText(lineBuffer, startLinePos, curPos);
int offset = len-1;
int offset = len - 1;
int nrChars = 0;
char c;
while (offset>=0)
while (offset >= 0)
{
c = lineBuffer[offset];
if (isalnum(c) || c == '_') {
if (isalnum(c) || c == '_')
{
++nrChars;
} else {
}
else
{
break;
}
--offset;
}
startWordPos = curPos-nrChars;
startWordPos = curPos - nrChars;
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM('\n'));
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
_pEditView->showAutoComletion(curPos - startWordPos, _keyWords.c_str());
_activeCompletion = CompletionAuto;
return true;
}
@ -230,7 +234,6 @@ void AutoCompletion::showPathCompletion()
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM('\n'));
_pEditView->execute(SCI_AUTOCSETIGNORECASE, true);
_pEditView->showAutoComletion(rawPath.length(), autoCompleteEntries.c_str());
_activeCompletion = CompletionPath;
return;
}
@ -247,6 +250,8 @@ bool AutoCompletion::showWordComplete(bool autoInsert)
if (len >= bufSize)
return false;
// Get word array
TCHAR beginChars[bufSize];
_pEditView->getGenericText(beginChars, bufSize, startPos, curPos);
@ -291,6 +296,8 @@ bool AutoCompletion::showWordComplete(bool autoInsert)
}
sort(wordArray.begin(), wordArray.end());
// Get word list
generic_string words(TEXT(""));
for (size_t i = 0, len = wordArray.size(); i < len; ++i)
@ -304,17 +311,16 @@ bool AutoCompletion::showWordComplete(bool autoInsert)
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' '));
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
_pEditView->showAutoComletion(curPos - startPos, words.c_str());
_activeCompletion = CompletionWord;
return true;
}
bool AutoCompletion::showFunctionComplete() {
bool AutoCompletion::showFunctionComplete()
{
if (!_funcCompletionActive)
return false;
if (_funcCalltip.updateCalltip(0, true)) {
_activeCompletion = CompletionFunc;
if (_funcCalltip.updateCalltip(0, true))
{
return true;
}
return false;
@ -418,7 +424,6 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
_pEditView->execute(SCI_INSERTTEXT, caretPos, (LPARAM)matchedChars);
}
void AutoCompletion::update(int character)
{
const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();
@ -427,7 +432,6 @@ void AutoCompletion::update(int character)
if (nppGUI._funcParams || _funcCalltip.isVisible()) {
if (_funcCalltip.updateCalltip(character)) { //calltip visible because triggered by autocomplete, set mode
_activeCompletion = CompletionFunc;
return; //only return in case of success, else autocomplete
}
}
@ -459,14 +463,7 @@ void AutoCompletion::update(int character)
}
}
else if (nppGUI._autocStatus == nppGUI.autoc_func)
showAutoComplete();
/*
if (nppGUI._autocStatus == nppGUI.autoc_word)
showWordComplete(false);
else if (nppGUI._autocStatus == nppGUI.autoc_func)
showAutoComplete();
*/
showApiComplete();
}
}
@ -562,7 +559,9 @@ bool AutoCompletion::setLanguage(LangType language) {
}
_keyWords = TEXT("");
if (_funcCompletionActive) { //Cache the keywords
if (_funcCompletionActive)
{
//Cache the keywords
//Iterate through all keywords
TiXmlElement *funcNode = _pXmlKeyword;
const TCHAR * name = NULL;
@ -577,7 +576,8 @@ bool AutoCompletion::setLanguage(LangType language) {
return _funcCompletionActive;
}
const TCHAR * AutoCompletion::getApiFileName() {
const TCHAR * AutoCompletion::getApiFileName()
{
if (_curLang == L_USER)
{
Buffer * currentBuf = _pEditView->getCurrentBuffer();

@ -44,7 +44,7 @@ public:
enum ActiveCompletion {CompletionNone = 0, CompletionAuto, CompletionWord, CompletionFunc, CompletionPath};
AutoCompletion(ScintillaEditView * pEditView) : _funcCompletionActive(false), _pEditView(pEditView), _funcCalltip(pEditView),
_curLang(L_TEXT), _pXmlFile(NULL), _activeCompletion(CompletionNone),
_curLang(L_TEXT), _pXmlFile(NULL),
_pXmlKeyword(NULL), _ignoreCase(true), _keyWords(TEXT("")) {
//Do not load any language yet
};
@ -57,7 +57,7 @@ public:
bool setLanguage(LangType language);
//AutoComplete from the list
bool showAutoComplete();
bool showApiComplete();
//WordCompletion from the current file
bool showWordComplete(bool autoInsert); //autoInsert true if completion should fill in the word on a single match
//Parameter display from the list
@ -76,7 +76,6 @@ private:
LangType _curLang;
TiXmlDocument *_pXmlFile;
TiXmlElement *_pXmlKeyword;
ActiveCompletion _activeCompletion;
bool _ignoreCase;

Loading…
Cancel
Save