diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index e17727fd6..36b74efa8 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -496,13 +496,13 @@ add_library(app-lib console.cpp context.cpp context_flags.cpp + doc_undo.cpp document.cpp document_api.cpp document_diff.cpp document_exporter.cpp document_range.cpp document_range_ops.cpp - document_undo.cpp documents.cpp extensions.cpp extra_cel.cpp diff --git a/src/app/cli/cli_processor.cpp b/src/app/cli/cli_processor.cpp index ffc84b082..a4a036a5d 100644 --- a/src/app/cli/cli_processor.cpp +++ b/src/app/cli/cli_processor.cpp @@ -16,9 +16,9 @@ #include "app/commands/commands.h" #include "app/commands/params.h" #include "app/console.h" +#include "app/doc_undo.h" #include "app/document.h" #include "app/document_exporter.h" -#include "app/document_undo.h" #include "app/file/file.h" #include "app/filename_formatter.h" #include "app/restore_visible_layers.h" diff --git a/src/app/cmd_transaction.h b/src/app/cmd_transaction.h index b3e56a8b4..b62ac7780 100644 --- a/src/app/cmd_transaction.h +++ b/src/app/cmd_transaction.h @@ -18,7 +18,7 @@ namespace app { // Cmds created on each Transaction. - // The whole DocumentUndo contains a list of these CmdTransaction. + // The whole DocUndo contains a list of these CmdTransaction. class CmdTransaction : public CmdSequence { public: CmdTransaction(const std::string& label, diff --git a/src/app/commands/cmd_duplicate_layer.cpp b/src/app/commands/cmd_duplicate_layer.cpp index 74ebc1264..27fb070fc 100644 --- a/src/app/commands/cmd_duplicate_layer.cpp +++ b/src/app/commands/cmd_duplicate_layer.cpp @@ -12,8 +12,8 @@ #include "app/commands/command.h" #include "app/console.h" #include "app/context_access.h" +#include "app/doc_undo.h" #include "app/document_api.h" -#include "app/document_undo.h" #include "app/modules/editors.h" #include "app/modules/gui.h" #include "app/transaction.h" diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index ad7c63b1c..ade6eedac 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -16,8 +16,8 @@ #include "app/commands/params.h" #include "app/console.h" #include "app/context_access.h" +#include "app/doc_undo.h" #include "app/document.h" -#include "app/document_undo.h" #include "app/file/file.h" #include "app/file/gif_format.h" #include "app/file/png_format.h" diff --git a/src/app/commands/cmd_undo.cpp b/src/app/commands/cmd_undo.cpp index 34efd2a1d..ee4329834 100644 --- a/src/app/commands/cmd_undo.cpp +++ b/src/app/commands/cmd_undo.cpp @@ -11,7 +11,7 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/context_access.h" -#include "app/document_undo.h" +#include "app/doc_undo.h" #include "app/ini_file.h" #include "app/modules/editors.h" #include "app/modules/gui.h" @@ -66,7 +66,7 @@ void UndoCommand::onExecute(Context* context) { ContextWriter writer(context); Document* document(writer.document()); - DocumentUndo* undo = document->undoHistory(); + DocUndo* undo = document->undoHistory(); #ifdef ENABLE_UI Sprite* sprite = document->sprite(); diff --git a/src/app/commands/cmd_undo_history.cpp b/src/app/commands/cmd_undo_history.cpp index 4235304d2..1440b5135 100644 --- a/src/app/commands/cmd_undo_history.cpp +++ b/src/app/commands/cmd_undo_history.cpp @@ -13,10 +13,10 @@ #include "app/console.h" #include "app/context.h" #include "app/context_observer.h" +#include "app/doc_undo.h" +#include "app/doc_undo_observer.h" #include "app/document.h" #include "app/document_access.h" -#include "app/document_undo.h" -#include "app/document_undo_observer.h" #include "app/documents_observer.h" #include "app/modules/gui.h" #include "app/modules/palettes.h" @@ -34,7 +34,7 @@ namespace app { class UndoHistoryWindow : public app::gen::UndoHistory, public ContextObserver, public DocumentsObserver, - public DocumentUndoObserver { + public DocUndoObserver { public: class Item : public ui::ListItem { public: @@ -132,8 +132,8 @@ private: detachDocument(); } - // DocumentUndoObserver - void onAddUndoState(DocumentUndo* history) override { + // DocUndoObserver + void onAddUndoState(DocUndo* history) override { ASSERT(history->currentState()); Item* item = new Item(history->currentState()); actions()->addChild(item); @@ -142,7 +142,7 @@ private: actions()->selectChild(item); } - void onDeleteUndoState(DocumentUndo* history, + void onDeleteUndoState(DocUndo* history, undo::UndoState* state) override { for (auto child : actions()->children()) { Item* item = static_cast(child); @@ -157,15 +157,15 @@ private: view()->updateView(); } - void onCurrentUndoStateChange(DocumentUndo* history) override { + void onCurrentUndoStateChange(DocUndo* history) override { selectState(history->currentState()); } - void onClearRedo(DocumentUndo* history) override { + void onClearRedo(DocUndo* history) override { refillList(history); } - void onTotalUndoSizeChange(DocumentUndo* history) override { + void onTotalUndoSizeChange(DocUndo* history) override { updateTitle(); } @@ -176,7 +176,7 @@ private: if (!document) return; - DocumentUndo* history = m_document->undoHistory(); + DocUndo* history = m_document->undoHistory(); history->add_observer(this); refillList(history); @@ -202,7 +202,7 @@ private: view()->updateView(); } - void refillList(DocumentUndo* history) { + void refillList(DocUndo* history) { clearList(); // Create an item to reference the initial state (undo state == nullptr) diff --git a/src/app/document_undo.cpp b/src/app/doc_undo.cpp similarity index 72% rename from src/app/document_undo.cpp rename to src/app/doc_undo.cpp index 9087c8f6b..7d3df9fe0 100644 --- a/src/app/document_undo.cpp +++ b/src/app/doc_undo.cpp @@ -8,13 +8,13 @@ #include "config.h" #endif -#include "app/document_undo.h" +#include "app/doc_undo.h" #include "app/app.h" #include "app/cmd.h" #include "app/cmd_transaction.h" #include "app/context.h" -#include "app/document_undo_observer.h" +#include "app/doc_undo_observer.h" #include "app/pref/preferences.h" #include "base/mem_utils.h" #include "undo/undo_history.h" @@ -28,7 +28,7 @@ namespace app { -DocumentUndo::DocumentUndo() +DocUndo::DocUndo() : m_undoHistory(this) , m_ctx(nullptr) , m_totalUndoSize(0) @@ -37,12 +37,12 @@ DocumentUndo::DocumentUndo() { } -void DocumentUndo::setContext(Context* ctx) +void DocUndo::setContext(Context* ctx) { m_ctx = ctx; } -void DocumentUndo::add(CmdTransaction* cmd) +void DocUndo::add(CmdTransaction* cmd) { ASSERT(cmd); UNDO_TRACE("UNDO: Add state <%s> of %s to %s\n", @@ -59,8 +59,8 @@ void DocumentUndo::add(CmdTransaction* cmd) m_undoHistory.add(cmd); m_totalUndoSize += cmd->memSize(); - notify_observers(&DocumentUndoObserver::onAddUndoState, this); - notify_observers(&DocumentUndoObserver::onTotalUndoSizeChange, this); + notify_observers(&DocUndoObserver::onAddUndoState, this); + notify_observers(&DocUndoObserver::onTotalUndoSizeChange, this); if (App::instance()) { const size_t undoLimitSize = @@ -87,17 +87,17 @@ void DocumentUndo::add(CmdTransaction* cmd) base::get_pretty_memory_size(m_totalUndoSize).c_str()); } -bool DocumentUndo::canUndo() const +bool DocUndo::canUndo() const { return m_undoHistory.canUndo(); } -bool DocumentUndo::canRedo() const +bool DocUndo::canRedo() const { return m_undoHistory.canRedo(); } -void DocumentUndo::undo() +void DocUndo::undo() { const undo::UndoState* state = nextUndo(); ASSERT(state); @@ -106,14 +106,14 @@ void DocumentUndo::undo() m_totalUndoSize -= cmd->memSize(); { m_undoHistory.undo(); - notify_observers(&DocumentUndoObserver::onCurrentUndoStateChange, this); + notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this); } m_totalUndoSize += cmd->memSize(); if (m_totalUndoSize != oldSize) - notify_observers(&DocumentUndoObserver::onTotalUndoSizeChange, this); + notify_observers(&DocUndoObserver::onTotalUndoSizeChange, this); } -void DocumentUndo::redo() +void DocUndo::redo() { const undo::UndoState* state = nextRedo(); ASSERT(state); @@ -122,36 +122,36 @@ void DocumentUndo::redo() m_totalUndoSize -= cmd->memSize(); { m_undoHistory.redo(); - notify_observers(&DocumentUndoObserver::onCurrentUndoStateChange, this); + notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this); } m_totalUndoSize += cmd->memSize(); if (m_totalUndoSize != oldSize) - notify_observers(&DocumentUndoObserver::onTotalUndoSizeChange, this); + notify_observers(&DocUndoObserver::onTotalUndoSizeChange, this); } -void DocumentUndo::clearRedo() +void DocUndo::clearRedo() { m_undoHistory.clearRedo(); - notify_observers(&DocumentUndoObserver::onClearRedo, this); + notify_observers(&DocUndoObserver::onClearRedo, this); } -bool DocumentUndo::isSavedState() const +bool DocUndo::isSavedState() const { return (!m_savedStateIsLost && m_savedCounter == 0); } -void DocumentUndo::markSavedState() +void DocUndo::markSavedState() { m_savedCounter = 0; m_savedStateIsLost = false; } -void DocumentUndo::impossibleToBackToSavedState() +void DocUndo::impossibleToBackToSavedState() { m_savedStateIsLost = true; } -std::string DocumentUndo::nextUndoLabel() const +std::string DocUndo::nextUndoLabel() const { const undo::UndoState* state = nextUndo(); if (state) @@ -160,7 +160,7 @@ std::string DocumentUndo::nextUndoLabel() const return ""; } -std::string DocumentUndo::nextRedoLabel() const +std::string DocUndo::nextRedoLabel() const { const undo::UndoState* state = nextRedo(); if (state) @@ -169,7 +169,7 @@ std::string DocumentUndo::nextRedoLabel() const return ""; } -SpritePosition DocumentUndo::nextUndoSpritePosition() const +SpritePosition DocUndo::nextUndoSpritePosition() const { const undo::UndoState* state = nextUndo(); if (state) @@ -178,7 +178,7 @@ SpritePosition DocumentUndo::nextUndoSpritePosition() const return SpritePosition(); } -SpritePosition DocumentUndo::nextRedoSpritePosition() const +SpritePosition DocUndo::nextRedoSpritePosition() const { const undo::UndoState* state = nextRedo(); if (state) @@ -187,7 +187,7 @@ SpritePosition DocumentUndo::nextRedoSpritePosition() const return SpritePosition(); } -std::istream* DocumentUndo::nextUndoDocumentRange() const +std::istream* DocUndo::nextUndoDocumentRange() const { const undo::UndoState* state = nextUndo(); if (state) @@ -196,7 +196,7 @@ std::istream* DocumentUndo::nextUndoDocumentRange() const return nullptr; } -std::istream* DocumentUndo::nextRedoDocumentRange() const +std::istream* DocUndo::nextRedoDocumentRange() const { const undo::UndoState* state = nextRedo(); if (state) @@ -205,7 +205,7 @@ std::istream* DocumentUndo::nextRedoDocumentRange() const return nullptr; } -Cmd* DocumentUndo::lastExecutedCmd() const +Cmd* DocUndo::lastExecutedCmd() const { const undo::UndoState* state = m_undoHistory.currentState(); if (state) @@ -214,10 +214,10 @@ Cmd* DocumentUndo::lastExecutedCmd() const return NULL; } -void DocumentUndo::moveToState(const undo::UndoState* state) +void DocUndo::moveToState(const undo::UndoState* state) { m_undoHistory.moveTo(state); - notify_observers(&DocumentUndoObserver::onCurrentUndoStateChange, this); + notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this); // Recalculate the total undo size size_t oldSize = m_totalUndoSize; @@ -228,15 +228,15 @@ void DocumentUndo::moveToState(const undo::UndoState* state) s = s->next(); } if (m_totalUndoSize != oldSize) - notify_observers(&DocumentUndoObserver::onTotalUndoSizeChange, this); + notify_observers(&DocUndoObserver::onTotalUndoSizeChange, this); } -const undo::UndoState* DocumentUndo::nextUndo() const +const undo::UndoState* DocUndo::nextUndo() const { return m_undoHistory.currentState(); } -const undo::UndoState* DocumentUndo::nextRedo() const +const undo::UndoState* DocUndo::nextRedo() const { const undo::UndoState* state = m_undoHistory.currentState(); if (state) @@ -245,7 +245,7 @@ const undo::UndoState* DocumentUndo::nextRedo() const return m_undoHistory.firstState(); } -void DocumentUndo::onDeleteUndoState(undo::UndoState* state) +void DocUndo::onDeleteUndoState(undo::UndoState* state) { ASSERT(state); Cmd* cmd = STATE_CMD(state); @@ -256,7 +256,7 @@ void DocumentUndo::onDeleteUndoState(undo::UndoState* state) base::get_pretty_memory_size(m_totalUndoSize).c_str()); m_totalUndoSize -= cmd->memSize(); - notify_observers(&DocumentUndoObserver::onDeleteUndoState, this, state); + notify_observers(&DocUndoObserver::onDeleteUndoState, this, state); } } // namespace app diff --git a/src/app/document_undo.h b/src/app/doc_undo.h similarity index 91% rename from src/app/document_undo.h rename to src/app/doc_undo.h index 688ba1a57..5d4a6ccd0 100644 --- a/src/app/document_undo.h +++ b/src/app/doc_undo.h @@ -24,12 +24,12 @@ namespace app { class Cmd; class CmdTransaction; class Context; - class DocumentUndoObserver; + class DocUndoObserver; - class DocumentUndo : public obs::observable, - public undo::UndoHistoryDelegate { + class DocUndo : public obs::observable, + public undo::UndoHistoryDelegate { public: - DocumentUndo(); + DocUndo(); size_t totalUndoSize() const { return m_totalUndoSize; } @@ -87,7 +87,7 @@ namespace app { // way. E.g. If the save process fails. bool m_savedStateIsLost; - DISABLE_COPYING(DocumentUndo); + DISABLE_COPYING(DocUndo); }; } // namespace app diff --git a/src/app/document_undo_observer.h b/src/app/doc_undo_observer.h similarity index 51% rename from src/app/document_undo_observer.h rename to src/app/doc_undo_observer.h index b75b1d829..9808b55b5 100644 --- a/src/app/document_undo_observer.h +++ b/src/app/doc_undo_observer.h @@ -14,17 +14,17 @@ namespace undo { namespace app { -class DocumentUndo; + class DocUndo; - class DocumentUndoObserver { + class DocUndoObserver { public: - virtual ~DocumentUndoObserver() { } - virtual void onAddUndoState(DocumentUndo* history) = 0; - virtual void onDeleteUndoState(DocumentUndo* history, + virtual ~DocUndoObserver() { } + virtual void onAddUndoState(DocUndo* history) = 0; + virtual void onDeleteUndoState(DocUndo* history, undo::UndoState* state) = 0; - virtual void onCurrentUndoStateChange(DocumentUndo* history) = 0; - virtual void onClearRedo(DocumentUndo* history) = 0; - virtual void onTotalUndoSizeChange(DocumentUndo* history) = 0; + virtual void onCurrentUndoStateChange(DocUndo* history) = 0; + virtual void onClearRedo(DocUndo* history) = 0; + virtual void onTotalUndoSizeChange(DocUndo* history) = 0; }; } // namespace app diff --git a/src/app/document.cpp b/src/app/document.cpp index 4ea7c8889..debebecf3 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -17,8 +17,8 @@ #include "app/context.h" #include "app/doc_event.h" #include "app/doc_observer.h" +#include "app/doc_undo.h" #include "app/document_api.h" -#include "app/document_undo.h" #include "app/file/format_options.h" #include "app/flatten.h" #include "app/pref/preferences.h" @@ -44,7 +44,7 @@ using namespace doc; Document::Document(Sprite* sprite) : m_ctx(nullptr) , m_flags(kMaskVisible) - , m_undo(new DocumentUndo) + , m_undo(new DocUndo) // Information about the file format used to load/save this document , m_format_options(nullptr) // Mask diff --git a/src/app/document.h b/src/app/document.h index 9aaa3e090..ea1528c00 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -43,7 +43,7 @@ namespace app { class Context; class DocumentApi; - class DocumentUndo; + class DocUndo; class Transaction; using namespace doc; @@ -76,8 +76,8 @@ namespace app { ////////////////////////////////////////////////////////////////////// // Main properties - const DocumentUndo* undoHistory() const { return m_undo; } - DocumentUndo* undoHistory() { return m_undo; } + const DocUndo* undoHistory() const { return m_undo; } + DocUndo* undoHistory() { return m_undo; } color_t bgColor() const; color_t bgColor(Layer* layer) const; @@ -194,7 +194,7 @@ namespace app { int m_flags; // Undo and redo information about the document. - base::UniquePtr m_undo; + base::UniquePtr m_undo; // Selected mask region boundaries base::UniquePtr m_maskBoundaries; diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index 0f1f30dfe..97e6b5b1a 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -43,8 +43,8 @@ #include "app/color_target.h" #include "app/color_utils.h" #include "app/context.h" +#include "app/doc_undo.h" #include "app/document.h" -#include "app/document_undo.h" #include "app/transaction.h" #include "base/unique_ptr.h" #include "doc/algorithm/flip_image.h" diff --git a/src/app/document_range_tests.cpp b/src/app/document_range_tests.cpp index 9ed5c65cf..95fc7004e 100644 --- a/src/app/document_range_tests.cpp +++ b/src/app/document_range_tests.cpp @@ -7,11 +7,11 @@ #include "tests/test.h" #include "app/context.h" +#include "app/doc_undo.h" #include "app/document.h" #include "app/document_api.h" #include "app/document_range.h" #include "app/document_range_ops.h" -#include "app/document_undo.h" #include "app/test_context.h" #include "app/transaction.h" #include "base/unique_ptr.h" diff --git a/src/app/tools/inks.h b/src/app/tools/inks.h index 2dcbeb3f2..aaa2036be 100644 --- a/src/app/tools/inks.h +++ b/src/app/tools/inks.h @@ -9,8 +9,8 @@ #include "app/app.h" // TODO avoid to include this file #include "app/color_utils.h" #include "app/context.h" +#include "app/doc_undo.h" #include "app/document.h" -#include "app/document_undo.h" #include "app/tools/pick_ink.h" #include "doc/mask.h" #include "doc/slice.h" diff --git a/src/app/transaction.cpp b/src/app/transaction.cpp index 246935d51..eeb1a30d0 100644 --- a/src/app/transaction.cpp +++ b/src/app/transaction.cpp @@ -12,8 +12,8 @@ #include "app/cmd_transaction.h" #include "app/context_access.h" +#include "app/doc_undo.h" #include "app/document.h" -#include "app/document_undo.h" #include "doc/sprite.h" #define TX_TRACE(...) diff --git a/src/app/transaction.h b/src/app/transaction.h index 80fdd08dc..bac294321 100644 --- a/src/app/transaction.h +++ b/src/app/transaction.h @@ -16,7 +16,7 @@ namespace app { class CmdTransaction; class Context; class DocumentRange; - class DocumentUndo; + class DocUndo; enum Modification { ModifyDocument, // This item changes the "saved status" of the document. @@ -59,8 +59,8 @@ namespace app { // created). // // WARNING: This must be called from the main UI thread, because - // it will generate a DocumentUndo::add() which triggers a - // DocumentUndoObserver::onAddUndoState() notification, which + // it will generate a DocUndo::add() which triggers a + // DocUndoObserver::onAddUndoState() notification, which // updates the Undo History window UI. void commit(); @@ -70,7 +70,7 @@ namespace app { void rollback(); Context* m_ctx; - DocumentUndo* m_undo; + DocUndo* m_undo; CmdTransaction* m_cmds; }; diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 1a60af64e..236e549b3 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -26,8 +26,8 @@ #include "app/commands/quick_command.h" #include "app/console.h" #include "app/context_access.h" +#include "app/doc_undo.h" #include "app/document_api.h" -#include "app/document_undo.h" #include "app/i18n/strings.h" #include "app/ini_file.h" #include "app/modules/editors.h" @@ -1166,7 +1166,7 @@ void ColorBar::updateCurrentSpritePalette(const char* operationName) currentSpritePalette->countDiff(newPalette, &from, &to); if (from >= 0 && to >= from) { - DocumentUndo* undo = document->undoHistory(); + DocUndo* undo = document->undoHistory(); Cmd* cmd = new cmd::SetPalette(sprite, frame, newPalette); // Add undo information to save the range of pal entries that will be modified. diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index fb780406b..120bd7836 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -19,7 +19,7 @@ #include "app/console.h" #include "app/context.h" #include "app/context_access.h" -#include "app/document_undo.h" +#include "app/doc_undo.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/modules/palettes.h" diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index c19e106c1..a464396b7 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -19,10 +19,10 @@ #include "app/console.h" #include "app/context_access.h" #include "app/doc_event.h" +#include "app/doc_undo.h" #include "app/document.h" #include "app/document_api.h" #include "app/document_range_ops.h" -#include "app/document_undo.h" #include "app/loop_tag.h" #include "app/modules/editors.h" #include "app/modules/gfx.h"