diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b6a28eaf..c4ab9761 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -487,7 +487,7 @@ bool Notepad_plus::loadSession(Session & session) const char *pLn = session._mainViewFiles[i]._langName.c_str(); int id = getLangFromMenuName(pLn); LangType typeToSet = L_TXT; - if (id != 0) + if (id != 0 && strcmp(pLn, "User Defined") != 0) typeToSet = menuID2LangType(id); Buffer * buf = MainFileManager->getBufferByID(lastOpened); @@ -5242,9 +5242,11 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode) Buffer * buf = _pEditView->getCurrentBuffer(); if (buf->getLangType() == L_USER) { - UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); - //::MessageBox(NULL, userLangContainer._keywordLists[4], "User", MB_OK); - symbol = extractSymbol('0', userLangContainer._keywordLists[4]); + UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); + if (!userLangContainer) + return false; + + symbol = extractSymbol('0', userLangContainer->_keywordLists[4]); commentLineSybol = symbol.c_str(); } else @@ -5358,10 +5360,14 @@ bool Notepad_plus::doStreamComment() Buffer * buf = _pEditView->getCurrentBuffer(); if (buf->getLangType() == L_USER) { - UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); - symbolStart = extractSymbol('1', userLangContainer._keywordLists[4]); + UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); + + if (!userLangContainer) + return false; + + symbolStart = extractSymbol('1', userLangContainer->_keywordLists[4]); commentStart = symbolStart.c_str(); - symbolEnd = extractSymbol('2', userLangContainer._keywordLists[4]); + symbolEnd = extractSymbol('2', userLangContainer->_keywordLists[4]); commentEnd = symbolEnd.c_str(); } else diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index b1ed4d3c..47434809 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -693,7 +693,7 @@ private: int getLangFromMenuName(const char * langName) { int id = 0; - char menuLangName[ 16 ]; + char menuLangName[64]; for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 5f7be1f4..b8c24a01 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -900,12 +900,12 @@ public: int getNbUserLang() const {return _nbUserLang;}; UserLangContainer & getULCFromIndex(int i) {return *_userLangArray[i];}; - UserLangContainer & getULCFromName(const char *userLangName) { + UserLangContainer * getULCFromName(const char *userLangName) { for (int i = 0 ; i < _nbUserLang ; i++) if (!strcmp(userLangName, _userLangArray[i]->_name)) - return *_userLangArray[i]; + return _userLangArray[i]; //qui doit etre jamais passer - return *_userLangArray[0]; + return NULL; }; int getNbExternalLang() const {return _nbExternalLang;}; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index fdc3c677..7ac8eb2f 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -426,23 +426,27 @@ void ScintillaEditView::setUserLexer(const char *userLangName) { execute(SCI_SETLEXER, SCLEX_USER); - UserLangContainer & userLangContainer = userLangName?NppParameters::getInstance()->getULCFromName(userLangName):*(_userDefineDlg._pCurrentUserLang); - execute(SCI_SETPROPERTY, (WPARAM)"userDefine.ignoreCase", (LPARAM)(userLangContainer._isCaseIgnored?"1":"0")); - execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentLineSymbol", (LPARAM)(userLangContainer._isCommentLineSymbol?"1":"0")); - execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentSymbol", (LPARAM)(userLangContainer._isCommentSymbol?"1":"0")); + UserLangContainer * userLangContainer = userLangName?NppParameters::getInstance()->getULCFromName(userLangName):_userDefineDlg._pCurrentUserLang; + + if (!userLangContainer) + return; + + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.ignoreCase", (LPARAM)(userLangContainer->_isCaseIgnored?"1":"0")); + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentLineSymbol", (LPARAM)(userLangContainer->_isCommentLineSymbol?"1":"0")); + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentSymbol", (LPARAM)(userLangContainer->_isCommentSymbol?"1":"0")); const char strArray[4][20] = {"userDefine.g1Prefix", "userDefine.g2Prefix", "userDefine.g3Prefix", "userDefine.g4Prefix"}; for (int i = 0 ; i < 4 ; i++) - execute(SCI_SETPROPERTY, (WPARAM)strArray[i], (LPARAM)(userLangContainer._isPrefix[i]?"1":"0")); + execute(SCI_SETPROPERTY, (WPARAM)strArray[i], (LPARAM)(userLangContainer->_isPrefix[i]?"1":"0")); - for (int i = 0 ; i < userLangContainer.getNbKeywordList() ; i++) + for (int i = 0 ; i < userLangContainer->getNbKeywordList() ; i++) { - execute(SCI_SETKEYWORDS, i, reinterpret_cast(userLangContainer._keywordLists[i])); + execute(SCI_SETKEYWORDS, i, reinterpret_cast(userLangContainer->_keywordLists[i])); } - for (int i = 0 ; i < userLangContainer._styleArray.getNbStyler() ; i++) + for (int i = 0 ; i < userLangContainer->_styleArray.getNbStyler() ; i++) { - Style & style = userLangContainer._styleArray.getStyler(i); + Style & style = userLangContainer->_styleArray.getStyler(i); setStyle(style); } } @@ -1093,6 +1097,9 @@ void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask) { if (buffer == _currentBuffer) { if (mask & BufferChangeLanguage) { defineDocType(buffer->getLangType()); + int end = execute(SCI_GETENDSTYLED); //style up to the last styled byte. + execute(SCI_CLEARDOCUMENTSTYLE); + execute(SCI_COLOURISE, 0, end); foldAll(fold_uncollapse); } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 0d3e1084..7acd0945 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -52,7 +52,7 @@ class NppParameters; typedef int (* SCINTILLA_FUNC) (void*, int, int, int); typedef void * SCINTILLA_PTR; -typedef std::vector buf_vec_t; +//typedef std::vector buf_vec_t; #define WM_DOCK_USERDEFINE_DLG (SCINTILLA_USER + 1) #define WM_UNDOCK_USERDEFINE_DLG (SCINTILLA_USER + 2)