editor: fix aborting save on exit

This commit is contained in:
Erik Faye-Lund 2010-07-05 19:06:29 +02:00
parent 1e94cd9975
commit 47d8e9de6c

View File

@ -252,7 +252,7 @@ void fileOpen()
} }
} }
void fileSaveAs() bool fileSaveAs()
{ {
wchar_t temp[_MAX_FNAME + 1]; wchar_t temp[_MAX_FNAME + 1];
temp[0] = '\0'; temp[0] = '\0';
@ -266,10 +266,8 @@ void fileSaveAs()
ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0"; ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT; ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
if (GetSaveFileNameW(&ofn)) if (GetSaveFileNameW(&ofn)) {
{ if (document.save(temp)) {
if (document.save(temp))
{
document.sendSaveCommand(); document.sendSaveCommand();
setWindowFileName(temp); setWindowFileName(temp);
fileName = temp; fileName = temp;
@ -277,20 +275,24 @@ void fileSaveAs()
mruFileList.insert(temp); mruFileList.insert(temp);
mruFileList.update(); mruFileList.update();
DrawMenuBar(hwnd); DrawMenuBar(hwnd);
} return true;
else } else
error("Failed to save file"); error("Failed to save file");
} }
return false;
} }
void fileSave() bool fileSave()
{
if (fileName.empty()) fileSaveAs();
else if (!document.save(fileName.c_str()))
{ {
if (fileName.empty())
return fileSaveAs();
if (!document.save(fileName.c_str())) {
document.sendSaveCommand(); document.sendSaveCommand();
error("Failed to save file"); error("Failed to save file");
return false;
} }
return true;
} }
void attemptQuit() void attemptQuit()
@ -298,8 +300,8 @@ void attemptQuit()
if (document.modified()) if (document.modified())
{ {
UINT res = MessageBox(hwnd, "Save before exit?", mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION); UINT res = MessageBox(hwnd, "Save before exit?", mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION);
if (IDYES == res) fileSave(); if ((IDYES == res && fileSave()) || (IDNO == res))
if (IDCANCEL != res) DestroyWindow(hwnd); DestroyWindow(hwnd);
} }
else DestroyWindow(hwnd); else DestroyWindow(hwnd);
} }