From a044cefe7ce2bd8baba38ca6bcee8e5b50c7928a Mon Sep 17 00:00:00 2001 From: Udo Hoffmann Date: Sat, 6 Mar 2021 16:42:11 +0100 Subject: [PATCH] Fix Project workspace changes lost on save cancel Fix #9605, close #9609 --- PowerEditor/installer/nativeLang/english.xml | 3 +- .../WinControls/ProjectPanel/ProjectPanel.cpp | 51 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index f5a2ad70b..f7a8c17cd 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1178,7 +1178,8 @@ Do you want to recover your langs.xml?"/> - + ToElement()->SetAttribute(TEXT("name"), tvItem.pszText); 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; } @@ -1231,17 +1239,18 @@ bool ProjectPanel::saveWorkSpaceAs(bool saveCopyAs) fDlg.setExtIndex(0); // 0 index for "custom extention" type if any else for "All types *.*" 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()); - if (!saveCopyAs) - { - _workSpaceFilePath = fn; - setWorkSpaceDirty(false); - } - return true; + _workSpaceFilePath = fn; + setWorkSpaceDirty(false); } - return false; + return true; } void ProjectPanel::setFileExtFilter(CustomFileDialog & fDlg)