diff --git a/src/app/crash/backup_observer.cpp b/src/app/crash/backup_observer.cpp index 5a4f4f17b..5ab1710c6 100644 --- a/src/app/crash/backup_observer.cpp +++ b/src/app/crash/backup_observer.cpp @@ -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(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(document)); } m_session->removeDocument(static_cast(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(doc)); + if (doc->needsBackup()) + m_session->saveDocumentChanges(doc); } catch (const std::exception&) { TRACE("DataRecovery: Document '%d' is locked\n", doc->id()); diff --git a/src/app/crash/backup_observer.h b/src/app/crash/backup_observer.h index faa5e6e3b..7f0f4d90a 100644 --- a/src/app/crash/backup_observer.h +++ b/src/app/crash/backup_observer.h @@ -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 m_documents; + std::vector m_documents; bool m_done; base::thread m_thread; }; diff --git a/src/app/document.cpp b/src/app/document.cpp index 898515713..084ceb4be 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -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 diff --git a/src/app/document.h b/src/app/document.h index c6011ce46..aa5383203 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -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