Retain read only flag state in session

Close #4987, Fix #4409, Fix #4872, Fix #2970, Fix #2548
This commit is contained in:
Rajendra Singh 2019-03-26 22:13:13 +05:30 committed by Don HO
parent 54d2bc5528
commit cfa702a8a8
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
4 changed files with 17 additions and 4 deletions

View File

@ -4989,7 +4989,9 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD
generic_string languageName = getLangFromMenu(buf);
const TCHAR *langName = languageName.c_str();
sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(editView), buf->getBackupFileName().c_str(), buf->getLastModifiedTimestamp(), buf->getMapPosition());
sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getUserReadOnly(), buf->getPosition(editView), buf->getBackupFileName().c_str(), buf->getLastModifiedTimestamp(), buf->getMapPosition());
sfi._isMonitoring = buf->isMonitoringOn();
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
size_t maxLine = static_cast<size_t>(_invisibleEditView.execute(SCI_GETLINECOUNT));

View File

@ -1718,6 +1718,8 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
if (session._mainViewFiles[i]._encoding != -1)
buf->setEncoding(session._mainViewFiles[i]._encoding);
buf->setUserReadOnly(session._mainViewFiles[i]._isUserReadOnly);
if (isSnapshotMode && session._mainViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str()))
buf->setDirty(true);
@ -1831,6 +1833,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
}
buf->setLangType(typeToSet, pLn);
buf->setEncoding(session._subViewFiles[k]._encoding);
buf->setUserReadOnly(session._mainViewFiles[k]._isUserReadOnly);
if (isSnapshotMode && session._subViewFiles[k]._backupFilePath != TEXT("") && PathFileExists(session._subViewFiles[k]._backupFilePath.c_str()))
buf->setDirty(true);

View File

@ -2122,7 +2122,12 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
(childNode->ToElement())->Attribute(TEXT("originalFileLastModifTimestamp"), reinterpret_cast<int32_t*>(&fileModifiedTimestamp.dwLowDateTime));
(childNode->ToElement())->Attribute(TEXT("originalFileLastModifTimestampHigh"), reinterpret_cast<int32_t*>(&fileModifiedTimestamp.dwHighDateTime));
sessionFileInfo sfi(fileName, langName, encStr?encoding:-1, position, backupFilePath, fileModifiedTimestamp, mapPosition);
bool isUserReadOnly = false;
const TCHAR *boolStrReadOnly = (childNode->ToElement())->Attribute(TEXT("userReadOnly"));
if (boolStrReadOnly)
isUserReadOnly = _wcsicmp(TEXT("yes"), boolStrReadOnly) == 0;
sessionFileInfo sfi(fileName, langName, encStr ? encoding : -1, isUserReadOnly, position, backupFilePath, fileModifiedTimestamp, mapPosition);
for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
markNode ;
@ -3137,6 +3142,7 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), viewSessionFiles[i]._selMode);
(fileNameNode->ToElement())->SetAttribute(TEXT("lang"), viewSessionFiles[i]._langName.c_str());
(fileNameNode->ToElement())->SetAttribute(TEXT("encoding"), viewSessionFiles[i]._encoding);
(fileNameNode->ToElement())->SetAttribute(TEXT("userReadOnly"), (viewSessionFiles[i]._isUserReadOnly && !viewSessionFiles[i]._isMonitoring) ? TEXT("yes") : TEXT("no"));
(fileNameNode->ToElement())->SetAttribute(TEXT("filename"), viewSessionFiles[i]._fileName.c_str());
(fileNameNode->ToElement())->SetAttribute(TEXT("backupFilePath"), viewSessionFiles[i]._backupFilePath.c_str());
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestamp"), static_cast<int32_t>(viewSessionFiles[i]._originalFileLastModifTimestamp.dwLowDateTime));

View File

@ -162,8 +162,8 @@ private:
struct sessionFileInfo : public Position
{
sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, const Position& pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) :
_encoding(encoding), Position(pos), _originalFileLastModifTimestamp(originalFileLastModifTimestamp), _mapPos(mapPos)
sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, bool userReadOnly, const Position& pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) :
_isUserReadOnly(userReadOnly), _encoding(encoding), Position(pos), _originalFileLastModifTimestamp(originalFileLastModifTimestamp), _mapPos(mapPos)
{
if (fn) _fileName = fn;
if (ln) _langName = ln;
@ -177,6 +177,8 @@ struct sessionFileInfo : public Position
std::vector<size_t> _marks;
std::vector<size_t> _foldStates;
int _encoding = -1;
bool _isUserReadOnly = false;
bool _isMonitoring = false;
generic_string _backupFilePath;
FILETIME _originalFileLastModifTimestamp = {};