summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-05-08 21:44:22 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-08 22:17:51 +0200
commitce90d87eb60cbb86d07afb101d2226991924b865 (patch)
treebcfc3228aadd9a11242660f635bd4d41854eb284 /Userland/Libraries/LibGUI
parentc670d8c56d14c48e5641819458695c607531501c (diff)
downloadserenity-ce90d87eb60cbb86d07afb101d2226991924b865.zip
LibGUI: Show command name in GUI::TextEditor undo/redo action text
We can now show things like "Undo Insert Text" and "Redo Remove Text" instead of just "Undo" and "Redo" in menu items. Pretty neat! :^)
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp10
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.h4
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp13
3 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 6687574513..e5a91258f5 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -719,6 +719,11 @@ InsertTextCommand::InsertTextCommand(TextDocument& document, const String& text,
{
}
+String InsertTextCommand::action_text() const
+{
+ return "Insert Text";
+}
+
bool InsertTextCommand::merge_with(GUI::Command const& other)
{
if (!is<InsertTextCommand>(other))
@@ -804,6 +809,11 @@ RemoveTextCommand::RemoveTextCommand(TextDocument& document, const String& text,
{
}
+String RemoveTextCommand::action_text() const
+{
+ return "Remove Text";
+}
+
bool RemoveTextCommand::merge_with(GUI::Command const& other)
{
if (!is<RemoveTextCommand>(other))
diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h
index 1d0319f077..8f97466d66 100644
--- a/Userland/Libraries/LibGUI/TextDocument.h
+++ b/Userland/Libraries/LibGUI/TextDocument.h
@@ -113,6 +113,8 @@ public:
void undo();
void redo();
+ UndoStack const& undo_stack() const { return m_undo_stack; }
+
void notify_did_change();
void set_all_cursors(const TextPosition&);
@@ -207,6 +209,7 @@ public:
virtual void undo() override;
virtual void redo() override;
virtual bool merge_with(GUI::Command const&) override;
+ virtual String action_text() const override;
const String& text() const { return m_text; }
const TextRange& range() const { return m_range; }
@@ -222,6 +225,7 @@ public:
virtual void redo() override;
const TextRange& range() const { return m_range; }
virtual bool merge_with(GUI::Command const&) override;
+ virtual String action_text() const override;
private:
String m_text;
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 7e1582562d..8a3b9f97e3 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1636,9 +1636,22 @@ void TextEditor::document_did_change()
void TextEditor::document_did_update_undo_stack()
{
+ auto make_action_text = [](auto prefix, auto suffix) {
+ StringBuilder builder;
+ builder.append(prefix);
+ if (suffix.has_value()) {
+ builder.append(' ');
+ builder.append(suffix.value());
+ }
+ return builder.to_string();
+ };
+
m_undo_action->set_enabled(can_undo());
m_redo_action->set_enabled(can_redo());
+ m_undo_action->set_text(make_action_text("&Undo", document().undo_stack().undo_action_text()));
+ m_redo_action->set_text(make_action_text("&Redo", document().undo_stack().redo_action_text()));
+
// FIXME: This is currently firing more often than it should.
// Ideally we'd only send this out when the undo stack modified state actually changes.
if (on_modified_change)