mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-02 11:59:58 +00:00
Don't save backups for documents without modifications
This commit is contained in:
parent
2ee6df8038
commit
383e371ddd
@ -50,7 +50,7 @@ void BackupObserver::onAddDocument(doc::Document* document)
|
||||
{
|
||||
TRACE("DataRecovery: Observe document %p\n", document);
|
||||
base::scoped_lock hold(m_mutex);
|
||||
m_documents.push_back(document);
|
||||
m_documents.push_back(static_cast<app::Document*>(document));
|
||||
}
|
||||
|
||||
void BackupObserver::onRemoveDocument(doc::Document* document)
|
||||
@ -58,7 +58,7 @@ void BackupObserver::onRemoveDocument(doc::Document* document)
|
||||
TRACE("DataRecovery:: Remove document %p\n", document);
|
||||
{
|
||||
base::scoped_lock hold(m_mutex);
|
||||
base::remove_from_container(m_documents, document);
|
||||
base::remove_from_container(m_documents, static_cast<app::Document*>(document));
|
||||
}
|
||||
m_session->removeDocument(static_cast<app::Document*>(document));
|
||||
}
|
||||
@ -78,9 +78,10 @@ void BackupObserver::backgroundThread()
|
||||
base::Chrono chrono;
|
||||
bool somethingLocked = false;
|
||||
|
||||
for (doc::Document* doc : m_documents) {
|
||||
for (app::Document* doc : m_documents) {
|
||||
try {
|
||||
m_session->saveDocumentChanges(static_cast<app::Document*>(doc));
|
||||
if (doc->needsBackup())
|
||||
m_session->saveDocumentChanges(doc);
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
TRACE("DataRecovery: Document '%d' is locked\n", doc->id());
|
||||
|
@ -22,6 +22,7 @@ namespace doc {
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Document;
|
||||
namespace crash {
|
||||
class Session;
|
||||
|
||||
@ -43,7 +44,7 @@ namespace crash {
|
||||
Session* m_session;
|
||||
base::mutex m_mutex;
|
||||
doc::Context* m_ctx;
|
||||
std::vector<doc::Document*> m_documents;
|
||||
std::vector<app::Document*> m_documents;
|
||||
bool m_done;
|
||||
base::thread m_thread;
|
||||
};
|
||||
|
@ -200,6 +200,13 @@ void Document::impossibleToBackToSavedState()
|
||||
m_undo->impossibleToBackToSavedState();
|
||||
}
|
||||
|
||||
bool Document::needsBackup() const
|
||||
{
|
||||
// If the undo history isn't empty, the user has modified the
|
||||
// document, so we needs to backup those changes.
|
||||
return m_undo->canUndo() || m_undo->canRedo();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Loaded options from file
|
||||
|
||||
|
@ -100,6 +100,11 @@ namespace app {
|
||||
// back to the saved state using the UndoHistory.
|
||||
void impossibleToBackToSavedState();
|
||||
|
||||
// Returns true if it does make sense to create a backup in this
|
||||
// document. For example, it doesn't make sense to create a backup
|
||||
// for an unmodified document.
|
||||
bool needsBackup() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Loaded options from file
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user