diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index 1b932b025..389da0f04 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -377,6 +377,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context) if (newWidth < 1) newWidth = 1; if (newHeight < 1) newHeight = 1; if (width != newWidth || height != newHeight) { + doc->setInhibitBackup(true); + Params params; params.set("use-ui", "false"); params.set("width", base::convert_to(newWidth).c_str()); @@ -424,6 +426,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context) Command* undoCmd = Commands::instance()->byId(CommandId::Undo()); if (undoCmd) context->executeCommand(undoCmd); + + doc->setInhibitBackup(false); } } diff --git a/src/app/crash/backup_observer.cpp b/src/app/crash/backup_observer.cpp index 37add28e1..83063d096 100644 --- a/src/app/crash/backup_observer.cpp +++ b/src/app/crash/backup_observer.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2017 David Capello +// Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -105,7 +105,11 @@ void BackupObserver::backgroundThread() for (app::Document* doc : m_documents) { try { if (doc->needsBackup()) { - if (!m_session->saveDocumentChanges(doc)) { + if (doc->inhibitBackup()) { + TRACE("RECO: Document '%d' backup is temporarily inhibited\n", doc->id()); + somethingLocked = true; + } + else if (!m_session->saveDocumentChanges(doc)) { TRACE("RECO: Document '%d' backup was canceled by UI\n", doc->id()); somethingLocked = true; } diff --git a/src/app/document.cpp b/src/app/document.cpp index afe9a91db..4d963c0a7 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2017 David Capello +// Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -42,13 +42,12 @@ using namespace base; using namespace doc; Document::Document(Sprite* sprite) - : m_undo(new DocumentUndo) - , m_associated_to_file(false) - // Information about the file format used to load/save this document - , m_format_options(NULL) + : m_flags(kMaskVisible) + , m_undo(new DocumentUndo) + // Information about the file format used to load/save this document + , m_format_options(nullptr) // Mask , m_mask(new Mask()) - , m_maskVisible(true) , m_lastDrawingPoint(Document::NoLastDrawingPoint()) { setFilename("Sprite"); @@ -164,13 +163,13 @@ bool Document::isModified() const bool Document::isAssociatedToFile() const { - return m_associated_to_file; + return (m_flags & kAssociatedToFile) == kAssociatedToFile; } void Document::markAsSaved() { m_undo->markSavedState(); - m_associated_to_file = true; + m_flags |= kAssociatedToFile; } void Document::impossibleToBackToSavedState() @@ -185,6 +184,19 @@ bool Document::needsBackup() const return m_undo->canUndo() || m_undo->canRedo(); } +bool Document::inhibitBackup() const +{ + return (m_flags & kInhibitBackup) == kInhibitBackup; +} + +void Document::setInhibitBackup(const bool inhibitBackup) +{ + if (inhibitBackup) + m_flags |= kInhibitBackup; + else + m_flags &= ~kInhibitBackup; +} + ////////////////////////////////////////////////////////////////////// // Loaded options from file @@ -226,7 +238,7 @@ void Document::generateMaskBoundaries(const Mask* mask) void Document::setMask(const Mask* mask) { m_mask.reset(new Mask(*mask)); - m_maskVisible = true; + m_flags |= kMaskVisible; resetTransformation(); } @@ -234,14 +246,17 @@ void Document::setMask(const Mask* mask) bool Document::isMaskVisible() const { return - m_maskVisible && // The mask was not hidden by the user explicitly + (m_flags & kMaskVisible) && // The mask was not hidden by the user explicitly m_mask && // The mask does exist !m_mask->isEmpty(); // The mask is not empty } void Document::setMaskVisible(bool visible) { - m_maskVisible = visible; + if (visible) + m_flags |= kMaskVisible; + else + m_flags &= ~kMaskVisible; } ////////////////////////////////////////////////////////////////////// @@ -422,8 +437,10 @@ Document* Document::duplicate(DuplicateType type) const break; } + // Copy only some flags + documentCopy->m_flags = (m_flags & kMaskVisible); + documentCopy->setMask(mask()); - documentCopy->m_maskVisible = m_maskVisible; documentCopy->generateMaskBoundaries(); return documentCopy.release(); diff --git a/src/app/document.h b/src/app/document.h index ecdf49ed3..a303315e5 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2017 David Capello +// Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -53,6 +53,11 @@ namespace app { // opened and being edited by the user (a sprite). class Document : public doc::Document, public RWLock { + enum Flags { + kAssociatedToFile = 1, // This sprite is associated to a file in the file-system + kMaskVisible = 2, // The mask wasn't hidden by the user + kInhibitBackup = 4, // Inhibit the backup process + }; public: Document(Sprite* sprite); ~Document(); @@ -98,6 +103,12 @@ namespace app { // for an unmodified document. bool needsBackup() const; + // Can be used to avoid creating a backup when the file is in a + // unusual temporary state (e.g. when the file is resized to be + // exported with other size) + bool inhibitBackup() const; + void setInhibitBackup(const bool inhibitBackup); + ////////////////////////////////////////////////////////////////////// // Loaded options from file @@ -166,12 +177,11 @@ namespace app { virtual void onContextChanged() override; private: + int m_flags; + // Undo and redo information about the document. base::UniquePtr m_undo; - // True if this sprite is associated to a file in the file-system. - bool m_associated_to_file; - // Selected mask region boundaries base::UniquePtr m_maskBoundaries; @@ -183,7 +193,6 @@ namespace app { // Current mask. base::UniquePtr m_mask; - bool m_maskVisible; // Current transformation. Transformation m_transformation;