1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-24 06:12:06 +00:00
serenity/Userland/Libraries/LibGUI/UndoStack.h
Andreas Kling 161568103e LibGUI: Remove UndoStack's automatic command combo'ing
UndoStack will now merge adjacent commands *if they want to be merged*
instead of bundling everything you push onto it until you tell it
to "finalize the combo."

This uses less memory and gives applications full control over how
their undo stacks end up. :^)
2021-05-08 22:17:51 +02:00

41 lines
687 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibGUI/Forward.h>
namespace GUI {
class UndoStack {
public:
UndoStack();
~UndoStack();
void push(NonnullOwnPtr<Command>);
bool can_undo() const;
bool can_redo() const;
void undo();
void redo();
void set_current_unmodified();
bool is_current_modified() const;
void clear();
Function<void()> on_state_change;
private:
NonnullOwnPtrVector<Command> m_stack;
size_t m_stack_index { 0 };
Optional<size_t> m_clean_index;
};
}