diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0a7928c1..788c3fe0 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -220,6 +220,9 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine) if (PathFileExists(pFn)) { doOpen(pFn); + const char *pLn = lastSession._files[i]._langName.c_str(); + setLangFromName(pLn); + cureentEditView->getCurrentBuffer().setPosition(lastSession._files[i]); cureentEditView->restoreCurrentPos(lastSession._files[i]); @@ -7174,7 +7177,11 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) const Buffer & buf = _mainEditView.getBufferAt((size_t)i); if (PathFileExists(buf._fullPathName)) { - sessionFileInfo sfi(buf._fullPathName, buf._pos); + string languageName = getLangFromMenu( buf ); + const char *langName = languageName.c_str(); + + sessionFileInfo sfi(buf._fullPathName, langName, buf._pos); + //sessionFileInfo sfi(buf._fullPathName, buf._pos); _mainEditView.activateDocAt(i); int maxLine = _mainEditView.execute(SCI_GETLINECOUNT); @@ -7244,6 +7251,9 @@ void Notepad_plus::fileLoadSession(const char *fn) const char *pFn = session2Load._files[i]._fileName.c_str(); if (doOpen(pFn)) { + const char *pLn = session2Load._files[i]._langName.c_str(); + setLangFromName(pLn); + cureentEditView->getCurrentBuffer().setPosition(session2Load._files[i]); cureentEditView->restoreCurrentPos(session2Load._files[i]); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index ba550301..c0b35612 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -865,6 +865,54 @@ private: }; bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible); + + void setLangFromName(const char * langName) + { + int id = 0; + char menuLangName[ 16 ]; + + for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ ) + if ( ::GetMenuString( ::GetMenu( _hSelf ), i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) + if ( !strcmp( langName, menuLangName ) ) + { + id = i; + break; + } + + if ( id == 0 ) + { + for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; i++ ) + if ( ::GetMenuString( ::GetMenu( _hSelf ), i, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ) + if ( !strcmp( langName, menuLangName ) ) + { + id = i; + break; + } + } + + if ( id != 0 ) + command( id ); + } + + string getLangFromMenu(Buffer buf) + { + int id; + const char * userLangName; + char menuLangName[32]; + + id = (NppParameters::getInstance())->langTypeToCommandID( buf.getLangType() ); + + if ( ( id != IDM_LANG_USER ) || !( buf.isUserDefineLangExt() ) ) + { + ( ::GetMenuString( ::GetMenu( _hSelf ), id, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ); + userLangName = (char *)menuLangName; + } + else + { + userLangName = buf.getUserDefineLangName(); + } + return userLangName; + } }; #endif //NOTEPAD_PLUS_H diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index dcda08c5..ceb325f3 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -630,8 +630,11 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p (childNode->ToElement())->Attribute("xOffset", &position._xOffset); (childNode->ToElement())->Attribute("startPos", &position._startPos); (childNode->ToElement())->Attribute("endPos", &position._endPos); + const char *langName; + langName = (childNode->ToElement())->Attribute( "lang" ); - sessionFileInfo sfi(fileName, position); + sessionFileInfo sfi( fileName, langName, position ); + //sessionFileInfo sfi(fileName, position); for (TiXmlNode *markNode = fnNode->NextSibling("Mark"); markNode ; @@ -1036,6 +1039,7 @@ void NppParameters::writeSession(const Session & session, const char *fileName) (fileNameNode->ToElement())->SetAttribute("xOffset", session._files[i]._xOffset); (fileNameNode->ToElement())->SetAttribute("startPos", session._files[i]._startPos); (fileNameNode->ToElement())->SetAttribute("endPos", session._files[i]._endPos); + (fileNameNode->ToElement())->SetAttribute("lang", session._files[i]._langName.c_str()); TiXmlText fileNameFullPath(session._files[i]._fileName.c_str()); fileNameNode->InsertEndChild(fileNameFullPath); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index cc13eb03..bbb1469d 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -93,11 +93,14 @@ struct Position struct sessionFileInfo : public Position { string _fileName; + string _langName; + sessionFileInfo(const char *fn) { if (fn) _fileName = fn; }; - sessionFileInfo(const char *fn, Position pos) : Position(pos) { + sessionFileInfo(const char *fn, const char *ln, Position pos) : Position(pos) { if (fn) _fileName = fn; + if (ln) _langName = ln; }; sessionFileInfo(string fn) : _fileName(fn){}; sessionFileInfo(string fn, Position pos) : Position(pos), _fileName(fn){};