summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TextDocument.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-05-08 13:16:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-08 13:49:34 +0200
commitee19f7c0aac48b1ca6527413552fc05a4fe16710 (patch)
tree63d2767702e5a289e77f8c336a830cf61a2d77a8 /Userland/Libraries/LibGUI/TextDocument.cpp
parent0cb610392823b9591479da4492e9ba964df91141 (diff)
downloadserenity-ee19f7c0aac48b1ca6527413552fc05a4fe16710.zip
LibGUI: Use UndoStack::on_state_change inside TextDocument/TextEditor
Have TextDocument listen for state changes on the internal undo stack, and forward those to all clients via a new virtual function. This simplifies updating the can_undo / can_redo states of TextEditor.
Diffstat (limited to 'Userland/Libraries/LibGUI/TextDocument.cpp')
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index e007ce65cc..7686e67a0b 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -28,6 +28,13 @@ TextDocument::TextDocument(Client* client)
append_line(make<TextDocumentLine>(*this));
set_unmodified();
+ m_undo_stack.on_state_change = [this] {
+ if (m_client_notifications_enabled) {
+ for (auto* client : m_clients)
+ client->document_did_update_undo_stack();
+ }
+ };
+
m_undo_timer = Core::Timer::create_single_shot(
2000, [this] {
update_undo();
@@ -694,6 +701,7 @@ void TextDocument::redo()
void TextDocument::add_to_undo_stack(NonnullOwnPtr<TextDocumentUndoCommand> undo_command)
{
m_undo_stack.push(move(undo_command));
+ notify_did_change();
}
TextDocumentUndoCommand::TextDocumentUndoCommand(TextDocument& document)