Only ask to save if document has been changed. Remembers old save-points. Also corrected an error message.
This commit is contained in:
parent
b0224c0f2b
commit
45a9afd6bf
@ -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;
|
||||
}
|
||||
|
||||
@ -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<TCHAR> &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;
|
||||
}
|
||||
|
||||
@ -295,12 +304,23 @@ 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<size_t, size_t> clientRemap;
|
||||
bool clientPaused;
|
||||
|
||||
private:
|
||||
std::vector<size_t> trackOrder;
|
||||
|
||||
// undo / redo functionality
|
||||
std::stack<Command*> undoStack;
|
||||
std::stack<Command*> redoStack;
|
||||
int savePointDelta; // how many undos must be done to get to the last saved state
|
||||
bool savePointUnreachable; // is the save-point reachable?
|
||||
|
||||
};
|
||||
|
||||
@ -325,9 +325,13 @@ void fileSave()
|
||||
|
||||
void attemptQuit()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user