[BUG_FIXED] Fix crash issue while file's language is "User Defined" in the last session.

Fix the User Defined language and some languages' syntax highlighting problem while reload last session.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@247 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-06-22 19:09:40 +00:00
parent d5f5e41fd5
commit 8e9e2f30bc
5 changed files with 34 additions and 21 deletions

View File

@ -487,7 +487,7 @@ bool Notepad_plus::loadSession(Session & session)
const char *pLn = session._mainViewFiles[i]._langName.c_str(); const char *pLn = session._mainViewFiles[i]._langName.c_str();
int id = getLangFromMenuName(pLn); int id = getLangFromMenuName(pLn);
LangType typeToSet = L_TXT; LangType typeToSet = L_TXT;
if (id != 0) if (id != 0 && strcmp(pLn, "User Defined") != 0)
typeToSet = menuID2LangType(id); typeToSet = menuID2LangType(id);
Buffer * buf = MainFileManager->getBufferByID(lastOpened); Buffer * buf = MainFileManager->getBufferByID(lastOpened);
@ -5242,9 +5242,11 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode)
Buffer * buf = _pEditView->getCurrentBuffer(); Buffer * buf = _pEditView->getCurrentBuffer();
if (buf->getLangType() == L_USER) if (buf->getLangType() == L_USER)
{ {
UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName());
//::MessageBox(NULL, userLangContainer._keywordLists[4], "User", MB_OK); if (!userLangContainer)
symbol = extractSymbol('0', userLangContainer._keywordLists[4]); return false;
symbol = extractSymbol('0', userLangContainer->_keywordLists[4]);
commentLineSybol = symbol.c_str(); commentLineSybol = symbol.c_str();
} }
else else
@ -5358,10 +5360,14 @@ bool Notepad_plus::doStreamComment()
Buffer * buf = _pEditView->getCurrentBuffer(); Buffer * buf = _pEditView->getCurrentBuffer();
if (buf->getLangType() == L_USER) if (buf->getLangType() == L_USER)
{ {
UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName());
symbolStart = extractSymbol('1', userLangContainer._keywordLists[4]);
if (!userLangContainer)
return false;
symbolStart = extractSymbol('1', userLangContainer->_keywordLists[4]);
commentStart = symbolStart.c_str(); commentStart = symbolStart.c_str();
symbolEnd = extractSymbol('2', userLangContainer._keywordLists[4]); symbolEnd = extractSymbol('2', userLangContainer->_keywordLists[4]);
commentEnd = symbolEnd.c_str(); commentEnd = symbolEnd.c_str();
} }
else else

View File

@ -693,7 +693,7 @@ private:
int getLangFromMenuName(const char * langName) { int getLangFromMenuName(const char * langName) {
int id = 0; int id = 0;
char menuLangName[ 16 ]; char menuLangName[64];
for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ ) for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ )
if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) )

View File

@ -900,12 +900,12 @@ public:
int getNbUserLang() const {return _nbUserLang;}; int getNbUserLang() const {return _nbUserLang;};
UserLangContainer & getULCFromIndex(int i) {return *_userLangArray[i];}; UserLangContainer & getULCFromIndex(int i) {return *_userLangArray[i];};
UserLangContainer & getULCFromName(const char *userLangName) { UserLangContainer * getULCFromName(const char *userLangName) {
for (int i = 0 ; i < _nbUserLang ; i++) for (int i = 0 ; i < _nbUserLang ; i++)
if (!strcmp(userLangName, _userLangArray[i]->_name)) if (!strcmp(userLangName, _userLangArray[i]->_name))
return *_userLangArray[i]; return _userLangArray[i];
//qui doit etre jamais passer //qui doit etre jamais passer
return *_userLangArray[0]; return NULL;
}; };
int getNbExternalLang() const {return _nbExternalLang;}; int getNbExternalLang() const {return _nbExternalLang;};

View File

@ -426,23 +426,27 @@ void ScintillaEditView::setUserLexer(const char *userLangName)
{ {
execute(SCI_SETLEXER, SCLEX_USER); execute(SCI_SETLEXER, SCLEX_USER);
UserLangContainer & userLangContainer = userLangName?NppParameters::getInstance()->getULCFromName(userLangName):*(_userDefineDlg._pCurrentUserLang); 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")); if (!userLangContainer)
execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentSymbol", (LPARAM)(userLangContainer._isCommentSymbol?"1":"0")); 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"}; const char strArray[4][20] = {"userDefine.g1Prefix", "userDefine.g2Prefix", "userDefine.g3Prefix", "userDefine.g4Prefix"};
for (int i = 0 ; i < 4 ; i++) 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<LPARAM>(userLangContainer._keywordLists[i])); execute(SCI_SETKEYWORDS, i, reinterpret_cast<LPARAM>(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); setStyle(style);
} }
} }
@ -1093,6 +1097,9 @@ void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask) {
if (buffer == _currentBuffer) { if (buffer == _currentBuffer) {
if (mask & BufferChangeLanguage) { if (mask & BufferChangeLanguage) {
defineDocType(buffer->getLangType()); 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); foldAll(fold_uncollapse);
} }

View File

@ -52,7 +52,7 @@ class NppParameters;
typedef int (* SCINTILLA_FUNC) (void*, int, int, int); typedef int (* SCINTILLA_FUNC) (void*, int, int, int);
typedef void * SCINTILLA_PTR; typedef void * SCINTILLA_PTR;
typedef std::vector<Buffer> buf_vec_t; //typedef std::vector<Buffer> buf_vec_t;
#define WM_DOCK_USERDEFINE_DLG (SCINTILLA_USER + 1) #define WM_DOCK_USERDEFINE_DLG (SCINTILLA_USER + 1)
#define WM_UNDOCK_USERDEFINE_DLG (SCINTILLA_USER + 2) #define WM_UNDOCK_USERDEFINE_DLG (SCINTILLA_USER + 2)