mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-02 11:59:58 +00:00
Avoid saving backups when we are in the middle of a File > Export with Resize
This commit is contained in:
parent
b321a75b5b
commit
67a61fd3d6
@ -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<std::string>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<DocumentUndo> 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<doc::MaskBoundaries> m_maskBoundaries;
|
||||
|
||||
@ -183,7 +193,6 @@ namespace app {
|
||||
|
||||
// Current mask.
|
||||
base::UniquePtr<Mask> m_mask;
|
||||
bool m_maskVisible;
|
||||
|
||||
// Current transformation.
|
||||
Transformation m_transformation;
|
||||
|
Loading…
Reference in New Issue
Block a user