Browse Source

Fix document language not remembered through sessions issue

Fix document language not remembered through sessions due to languange being hidden from languages menu.

Fix #13743, close #13744
pull/13751/head
Don Ho 1 year ago
parent
commit
dba15cfaf3
  1. 21
      PowerEditor/src/Notepad_plus.cpp
  2. 28
      PowerEditor/src/NppIO.cpp
  3. 32
      PowerEditor/src/Parameters.h

21
PowerEditor/src/Notepad_plus.cpp

@ -6072,8 +6072,24 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD
continue;
generic_string languageName = getLangFromMenu(buf);
const TCHAR *langName = languageName.c_str();
wstring languageName = getLangFromMenu(buf);
if (languageName.empty()) // The lang menu item in question is hidden
{
NppParameters& nppParam = NppParameters::getInstance();
const NppGUI& nppGUI = nppParam.getNppGUI();
for (size_t k = 0; k < nppGUI._excludedLangList.size(); ++k) // try to find it in exclude lang list
{
if (buf->getLangType() == nppGUI._excludedLangList[k]._langType)
{
languageName = nppGUI._excludedLangList[k]._langName;
break;
}
}
}
const wchar_t* langName = languageName.c_str();
sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getUserReadOnly(), buf->getPosition(editView), buf->getBackupFileName().c_str(), buf->getLastModifiedTimestamp(), buf->getMapPosition());
sfi._isMonitoring = buf->isMonitoringOn();
@ -6788,7 +6804,6 @@ int Notepad_plus::getLangFromMenuName(const TCHAR * langName)
generic_string Notepad_plus::getLangFromMenu(const Buffer * buf)
{
int id;
generic_string userLangName;
TCHAR menuLangName[menuItemStrLenMax]{};

28
PowerEditor/src/NppIO.cpp

@ -2141,8 +2141,8 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
if (lastOpened != BUFFER_INVALID)
{
showView(MAIN_VIEW);
const TCHAR* pLn = nullptr;
LangType typeToSet = L_TEXT;
const wchar_t* pLn = nullptr;
LangType langTypeToSet = L_TEXT;
Buffer* buf = MainFileManager.getBufferByID(lastOpened);
if (!buf->isLargeFile())
@ -2151,10 +2151,24 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
int id = getLangFromMenuName(pLn);
if (id != 0 && id != IDM_LANG_USER)
typeToSet = menuID2LangType(id);
if (typeToSet == L_EXTERNAL)
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
if (!id) // it could be due to the hidden language from the sub-menu "Languages"
{
const NppGUI& nppGUI = nppParam.getNppGUI();
for (size_t k = 0; k < nppGUI._excludedLangList.size(); ++k) // try to find it in exclude lang list
{
if (nppGUI._excludedLangList[k]._langName == pLn)
{
langTypeToSet = nppGUI._excludedLangList[k]._langType;
break;
}
}
}
else if (id != IDM_LANG_USER)
langTypeToSet = menuID2LangType(id);
if (langTypeToSet == L_EXTERNAL)
langTypeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
}
@ -2170,7 +2184,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
buf->setPosition(session._mainViewFiles[i], &_mainEditView);
buf->setMapPosition(session._mainViewFiles[i]._mapPos);
buf->setLangType(typeToSet, pLn);
buf->setLangType(langTypeToSet, pLn);
if (session._mainViewFiles[i]._encoding != -1)
buf->setEncoding(session._mainViewFiles[i]._encoding);

32
PowerEditor/src/Parameters.h

@ -190,7 +190,7 @@ public:
struct sessionFileInfo : public Position
{
sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, bool userReadOnly, const Position& pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) :
sessionFileInfo(const wchar_t* fn, const TCHAR *ln, int encoding, bool userReadOnly, const Position& pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) :
Position(pos), _encoding(encoding), _isUserReadOnly(userReadOnly), _originalFileLastModifTimestamp(originalFileLastModifTimestamp), _mapPos(mapPos)
{
if (fn) _fileName = fn;
@ -198,10 +198,10 @@ struct sessionFileInfo : public Position
if (backupFilePath) _backupFilePath = backupFilePath;
}
sessionFileInfo(generic_string fn) : _fileName(fn) {}
sessionFileInfo(std::wstring fn) : _fileName(fn) {}
generic_string _fileName;
generic_string _langName;
std::wstring _fileName;
std::wstring _langName;
std::vector<size_t> _marks;
std::vector<size_t> _foldStates;
int _encoding = -1;
@ -209,8 +209,8 @@ struct sessionFileInfo : public Position
bool _isMonitoring = false;
int _individualTabColour = -1;
generic_string _backupFilePath;
FILETIME _originalFileLastModifTimestamp = {};
std::wstring _backupFilePath;
FILETIME _originalFileLastModifTimestamp {};
MapPosition _mapPos;
};
@ -578,9 +578,9 @@ struct LangMenuItem final
{
LangType _langType = L_TEXT;
int _cmdID = -1;
generic_string _langName;
std::wstring _langName;
LangMenuItem(LangType lt, int cmdID = 0, const generic_string& langName = TEXT("")):
LangMenuItem(LangType lt, int cmdID = 0, const std::wstring& langName = TEXT("")):
_langType(lt), _cmdID(cmdID), _langName(langName){};
};
@ -588,17 +588,17 @@ struct PrintSettings final {
bool _printLineNumber = true;
int _printOption = SC_PRINT_COLOURONWHITE;
generic_string _headerLeft;
generic_string _headerMiddle;
generic_string _headerRight;
generic_string _headerFontName;
std::wstring _headerLeft;
std::wstring _headerMiddle;
std::wstring _headerRight;
std::wstring _headerFontName;
int _headerFontStyle = 0;
int _headerFontSize = 0;
generic_string _footerLeft;
generic_string _footerMiddle;
generic_string _footerRight;
generic_string _footerFontName;
std::wstring _footerLeft;
std::wstring _footerMiddle;
std::wstring _footerRight;
std::wstring _footerFontName;
int _footerFontStyle = 0;
int _footerFontSize = 0;

Loading…
Cancel
Save