┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/actiontexthelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/selectionmode/actiontexthelper.cpp')
-rw-r--r--src/selectionmode/actiontexthelper.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/selectionmode/actiontexthelper.cpp b/src/selectionmode/actiontexthelper.cpp
new file mode 100644
index 000000000..3eb868a8c
--- /dev/null
+++ b/src/selectionmode/actiontexthelper.cpp
@@ -0,0 +1,41 @@
+/*
+ This file is part of the KDE project
+ SPDX-FileCopyrightText: 2022 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#include "actiontexthelper.h"
+
+using namespace SelectionMode;
+
+ActionTextHelper::ActionTextHelper(QObject *parent) :
+ QObject(parent)
+{ }
+
+void ActionTextHelper::registerTextWhenNothingIsSelected(QAction *action, QString registeredText)
+{
+ Q_CHECK_PTR(action);
+ m_registeredActionTextChanges.emplace_back(action, registeredText, TextWhenNothingIsSelected);
+}
+
+void ActionTextHelper::textsWhenNothingIsSelectedEnabled(bool enabled)
+{
+ for (auto i = m_registeredActionTextChanges.begin(); i != m_registeredActionTextChanges.end(); ++i) {
+ if (!i->action) {
+ i = m_registeredActionTextChanges.erase(i);
+ continue;
+ }
+ if (enabled && i->textStateOfRegisteredText == TextWhenNothingIsSelected) {
+ QString textWhenSomethingIsSelected = i->action->text();
+ i->action->setText(i->registeredText);
+ i->registeredText = textWhenSomethingIsSelected;
+ i->textStateOfRegisteredText = TextWhenSomethingIsSelected;
+ } else if (!enabled && i->textStateOfRegisteredText == TextWhenSomethingIsSelected) {
+ QString textWhenNothingIsSelected = i->action->text();
+ i->action->setText(i->registeredText);
+ i->registeredText = textWhenNothingIsSelected;
+ i->textStateOfRegisteredText = TextWhenNothingIsSelected;
+ }
+ }
+}