[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; bool isFromPrimary = _pEditView == &_mainEditView;
AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub;
autoC->showAutoComplete(); autoC->showApiComplete();
} }
void Notepad_plus::showPathCompletion() void Notepad_plus::showPathCompletion()

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

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

Loading…
Cancel
Save