Fix Project workspace changes lost on save cancel

Fix #9605, close #9609
This commit is contained in:
Udo Hoffmann 2021-03-06 16:42:11 +01:00 committed by Don HO
parent 22e87184aa
commit a044cefe7c
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
2 changed files with 32 additions and 22 deletions

View File

@ -1178,7 +1178,8 @@ Do you want to recover your langs.xml?"/> <!-- HowToReproduce: Close Notepad++.
Please remove its root from the panel before you add folder &quot;$STR_REPLACE$&quot;."/> <!-- HowToReproduce: Add a folder like "c:\temp\aFolder\" into "Folder as Workspace" panel, then try to add "c:\temp\". --> Please remove its root from the panel before you add folder &quot;$STR_REPLACE$&quot;."/> <!-- HowToReproduce: Add a folder like "c:\temp\aFolder\" into "Folder as Workspace" panel, then try to add "c:\temp\". -->
<ProjectPanelChanged title="$STR_REPLACE$" message="The workspace was modified. Do you want to save it?"/> <ProjectPanelChanged title="$STR_REPLACE$" message="The workspace was modified. Do you want to save it?"/>
<ProjectPanelChangedSaveError title="$STR_REPLACE$" message="Your workspace has not been saved."/> <!-- HowToReproduce: this message prevents from system failure. It's hard to reproduce. --> <ProjectPanelSaveError title="$STR_REPLACE$" message="An error occurred while writing your workspace file.
Your workspace has not been saved."/> <!-- HowToReproduce: this message prevents from system failure. It's hard to reproduce. -->
<ProjectPanelOpenDoSaveDirtyWsOrNot title="Open Workspace" message="The current workspace was modified. Do you want to save the current project?"/> <ProjectPanelOpenDoSaveDirtyWsOrNot title="Open Workspace" message="The current workspace was modified. Do you want to save the current project?"/>
<ProjectPanelNewDoSaveDirtyWsOrNot title="New Workspace" message="The current workspace was modified. Do you want to save the current project?"/> <ProjectPanelNewDoSaveDirtyWsOrNot title="New Workspace" message="The current workspace was modified. Do you want to save the current project?"/>
<ProjectPanelOpenFailed title="Open Workspace" message="The workspace could not be opened. <ProjectPanelOpenFailed title="Open Workspace" message="The workspace could not be opened.

View File

@ -191,13 +191,7 @@ bool ProjectPanel::checkIfNeedSave()
if (res == IDYES) if (res == IDYES)
{ {
if (!saveWorkSpace()) if (!saveWorkSpace())
pNativeSpeaker->messageBox("ProjectPanelChangedSaveError", return false;
_hSelf,
TEXT("Your workspace has not been saved."),
TEXT("$STR_REPLACE$"),
MB_OK | MB_ICONERROR,
0,
title);
} }
else if (res == IDNO) else if (res == IDNO)
{ {
@ -436,7 +430,9 @@ bool ProjectPanel::saveWorkSpace()
} }
else else
{ {
writeWorkSpace(); if (!writeWorkSpace())
return false;
setWorkSpaceDirty(false); setWorkSpaceDirty(false);
return true; return true;
} }
@ -460,9 +456,6 @@ bool ProjectPanel::writeWorkSpace(const TCHAR *projectFileName)
if (!tvRoot) if (!tvRoot)
return false; return false;
TCHAR * fileName = PathFindFileName(fn2write);
_treeView.renameItem(tvRoot, fileName);
for (HTREEITEM tvProj = _treeView.getChildFrom(tvRoot); for (HTREEITEM tvProj = _treeView.getChildFrom(tvRoot);
tvProj != NULL; tvProj != NULL;
tvProj = _treeView.getNextSibling(tvProj)) tvProj = _treeView.getNextSibling(tvProj))
@ -475,7 +468,22 @@ bool ProjectPanel::writeWorkSpace(const TCHAR *projectFileName)
projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText); projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText);
buildProjectXml(projRoot, tvProj, fn2write); buildProjectXml(projRoot, tvProj, fn2write);
} }
projDoc.SaveFile();
if (!projDoc.SaveFile())
{
const TCHAR * title = _workSpaceFilePath.length() > 0 ? PathFindFileName (_workSpaceFilePath.c_str()) : _panelTitle.c_str();
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
pNativeSpeaker->messageBox("ProjectPanelSaveError",
_hSelf,
TEXT("An error occurred while writing your workspace file.\nYour workspace has not been saved."),
TEXT("$STR_REPLACE$"),
MB_OK | MB_ICONERROR,
0,
title);
return false;
}
TCHAR * fileName = PathFindFileName(fn2write);
_treeView.renameItem(tvRoot, fileName);
return true; return true;
} }
@ -1231,17 +1239,18 @@ bool ProjectPanel::saveWorkSpaceAs(bool saveCopyAs)
fDlg.setExtIndex(0); // 0 index for "custom extention" type if any else for "All types *.*" fDlg.setExtIndex(0); // 0 index for "custom extention" type if any else for "All types *.*"
const generic_string fn = fDlg.doSaveDlg(); const generic_string fn = fDlg.doSaveDlg();
if (!fn.empty()) if (fn.empty())
return false;
if (!writeWorkSpace(fn.c_str()))
return false;
if (!saveCopyAs)
{ {
writeWorkSpace(fn.c_str()); _workSpaceFilePath = fn;
if (!saveCopyAs) setWorkSpaceDirty(false);
{
_workSpaceFilePath = fn;
setWorkSpaceDirty(false);
}
return true;
} }
return false; return true;
} }
void ProjectPanel::setFileExtFilter(CustomFileDialog & fDlg) void ProjectPanel::setFileExtFilter(CustomFileDialog & fDlg)