diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index b6126d48a..ebcaf88ae 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1383,7 +1383,7 @@ bool NppParameters::load() { auto r = addUserDefineLangsFromXmlTree(_pXmlUserLangDoc); if (r.second - r.first > 0) - _pXmlUserLangsDoc.push_back(UdlXmlFileState(_pXmlUserLangDoc, false, r)); + _pXmlUserLangsDoc.push_back(UdlXmlFileState(_pXmlUserLangDoc, false, true, r)); } for (const auto& i : udlFiles) @@ -1398,7 +1398,7 @@ bool NppParameters::load() { auto r = addUserDefineLangsFromXmlTree(udlDoc); if (r.second - r.first > 0) - _pXmlUserLangsDoc.push_back(UdlXmlFileState(udlDoc, false, r)); + _pXmlUserLangsDoc.push_back(UdlXmlFileState(udlDoc, false, false, r)); } } @@ -3097,7 +3097,7 @@ bool NppParameters::importUDLFromFile(const generic_string& sourceFile) loadOkay = (r.second - r.first) != 0; if (loadOkay) { - _pXmlUserLangsDoc.push_back(UdlXmlFileState(nullptr, true, r)); + _pXmlUserLangsDoc.push_back(UdlXmlFileState(nullptr, true, true, r)); // imported UDL from xml file will be added into default udl, so we should make default udl dirty setUdlXmlDirtyFromXmlDoc(_pXmlUserLangDoc); @@ -3298,7 +3298,7 @@ Default UDL + Created + Imported void NppParameters::writeDefaultUDL() { bool firstCleanDone = false; - std::vector deleteState; + std::vector> deleteState; //vector< pair > for (const auto& udl : _pXmlUserLangsDoc) { if (!_pXmlUserLangDoc) @@ -3310,7 +3310,7 @@ void NppParameters::writeDefaultUDL() } bool toDelete = (udl._indexRange.second - udl._indexRange.first) == 0; - deleteState.push_back(toDelete); + deleteState.push_back(std::pair(toDelete, udl._isInDefaultSharedContainer)); if ((!udl._udlXmlDoc || udl._udlXmlDoc == _pXmlUserLangDoc) && udl._isDirty && !toDelete) // new created or/and imported UDL plus _pXmlUserLangDoc (if exist) { TiXmlNode *root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus")); @@ -3331,11 +3331,11 @@ void NppParameters::writeDefaultUDL() } bool deleteAll = true; - for (bool del : deleteState) + for (std::pair udlState : deleteState) { - if (!del) + if (!udlState.first && udlState.second) // if not marked to be delete udl is (&&) in default shared container (ie. "userDefineLang.xml" file) { - deleteAll = false; + deleteAll = false; // let's keep "userDefineLang.xml" file break; } } @@ -3683,7 +3683,7 @@ int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const TC ++_nbUserLang; unsigned char iEnd = _nbUserLang; - _pXmlUserLangsDoc.push_back(UdlXmlFileState(nullptr, true, make_pair(iBegin, iEnd))); + _pXmlUserLangsDoc.push_back(UdlXmlFileState(nullptr, true, true, make_pair(iBegin, iEnd))); // imported UDL from xml file will be added into default udl, so we should make default udl dirty setUdlXmlDirtyFromXmlDoc(_pXmlUserLangDoc); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 75798709f..1f9a3556b 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1349,9 +1349,11 @@ private: struct UdlXmlFileState final { TiXmlDocument* _udlXmlDoc = nullptr; bool _isDirty = false; + bool _isInDefaultSharedContainer = false; // contained in "userDefineLang.xml" file std::pair _indexRange; - UdlXmlFileState(TiXmlDocument* doc, bool isDirty, std::pair range) : _udlXmlDoc(doc), _isDirty(isDirty), _indexRange(range) {}; + UdlXmlFileState(TiXmlDocument* doc, bool isDirty, bool isInDefaultSharedContainer, std::pair range) + : _udlXmlDoc(doc), _isDirty(isDirty), _isInDefaultSharedContainer(isInDefaultSharedContainer), _indexRange(range) {}; }; const int NB_LANG = 100;