From 45a9afd6bfc82b82e5ddb0927601a7258a22a964 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Tue, 14 Oct 2008 12:28:13 +0000 Subject: [PATCH] Only ask to save if document has been changed. Remembers old save-points. Also corrected an error message. --- editor/syncdocument.cpp | 7 +++++-- editor/syncdocument.h | 22 +++++++++++++++++++++- editor/synctracker2.cpp | 10 +++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/editor/syncdocument.cpp b/editor/syncdocument.cpp index 84522c3..4b6543b 100644 --- a/editor/syncdocument.cpp +++ b/editor/syncdocument.cpp @@ -57,6 +57,8 @@ bool SyncDocument::load(const std::string &fileName) } } this->exec(multiCmd); + savePointDelta = 0; + savePointUnreachable = false; } catch(_com_error &e) { @@ -108,13 +110,14 @@ bool SyncDocument::save(const std::string &fileName) trackElem->appendChild(keyElem); } } - doc->save(fileName.c_str()); + savePointDelta = 0; + savePointUnreachable = false; } catch(_com_error &e) { char temp[256]; - _snprintf(temp, 256, "Error loading: %s\n", (const char*)_bstr_t(e.Description())); + _snprintf(temp, 256, "Error saving: %s\n", (const char*)_bstr_t(e.Description())); MessageBox(NULL, temp, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); return false; } diff --git a/editor/syncdocument.h b/editor/syncdocument.h index 17ecdd7..feea0eb 100644 --- a/editor/syncdocument.h +++ b/editor/syncdocument.h @@ -15,7 +15,7 @@ class SyncDocument : public sync::Data { public: - SyncDocument() : sync::Data(), clientPaused(true) {} + SyncDocument() : sync::Data(), clientPaused(true), savePointDelta(0), savePointUnreachable(true) {} ~SyncDocument(); size_t createTrack(const std::basic_string &name) @@ -219,6 +219,9 @@ public: undoStack.push(cmd); cmd->exec(this); clearRedoStack(); + + if (savePointDelta < 0) savePointUnreachable = true; + savePointDelta++; } bool undo() @@ -230,6 +233,9 @@ public: redoStack.push(cmd); cmd->undo(this); + + savePointDelta--; + return true; } @@ -242,6 +248,9 @@ public: undoStack.push(cmd); cmd->exec(this); + + savePointDelta++; + return true; } @@ -294,6 +303,12 @@ public: bool load(const std::string &fileName); bool save(const std::string &fileName); + + bool modified() + { + if (savePointUnreachable) return true; + return 0 != savePointDelta; + } NetworkSocket clientSocket; std::map clientRemap; @@ -301,6 +316,11 @@ public: private: std::vector trackOrder; + + // undo / redo functionality std::stack undoStack; std::stack redoStack; + int savePointDelta; // how many undos must be done to get to the last saved state + bool savePointUnreachable; // is the save-point reachable? + }; diff --git a/editor/synctracker2.cpp b/editor/synctracker2.cpp index b894f76..0523a24 100644 --- a/editor/synctracker2.cpp +++ b/editor/synctracker2.cpp @@ -325,9 +325,13 @@ void fileSave() void attemptQuit() { - UINT res = MessageBox(hwnd, _T("Save before exit?"), mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION); - if (IDYES == res) fileSave(); - if (IDCANCEL != res) DestroyWindow(hwnd); + if (document.modified()) + { + UINT res = MessageBox(hwnd, _T("Save before exit?"), mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION); + if (IDYES == res) fileSave(); + if (IDCANCEL != res) DestroyWindow(hwnd); + } + else DestroyWindow(hwnd); }