[NEW_FEATURE] The set languages in session are remembered now.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@34 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2007-09-15 14:42:03 +00:00
parent 20f8196bec
commit 49c21209a1
4 changed files with 68 additions and 3 deletions

View File

@ -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]);

View File

@ -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

View File

@ -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);

View File

@ -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){};