]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/actiontexthelper.h
Add missing KF6::ColorScheme link
[dolphin.git] / src / selectionmode / actiontexthelper.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef ACTIONTEXTHELPER_H
9 #define ACTIONTEXTHELPER_H
10
11 #include <QAction>
12 #include <QPointer>
13 #include <QString>
14
15 namespace SelectionMode
16 {
17
18 /**
19 * @brief Helps changing the texts of actions depending on the current selection.
20 *
21 * This is useful for actions that directly trigger a change when there is a selection and do something
22 * different when nothing is selected. For example should the copy action read "Copy" when items are
23 * selected but when no items are selected it can read "Copy…" since triggering it will enter selection
24 * mode and ask users to select the files they want to copy first.
25 */
26 class ActionTextHelper : QObject
27 {
28 public:
29 explicit ActionTextHelper(QObject *parent);
30
31 /**
32 * Changes the text of \a action to \a text whenever textsWhenNothingIsSelectedEnabled(true) is called.
33 * The texts can be changed back by calling textsWhenNothingIsSelectedEnabled(false).
34 * @see textsWhenNothingIsSelectedEnabled()
35 */
36 void registerTextWhenNothingIsSelected(QAction *action, QString registeredText);
37
38 /**
39 * Changes all texts that were registered previously using registerTextWhenNothingIsSelected() to those
40 * registered texts if called with \a enabled == true. Otherwise resets the texts to the original one.
41 */
42 void textsWhenNothingIsSelectedEnabled(bool enabled);
43
44 private:
45 enum TextState { TextWhenNothingIsSelected, TextWhenSomethingIsSelected };
46
47 /**
48 * Utility struct to allow switching back and forth between registered actions showing their
49 * distinct texts for when no items are selected or when items are selected.
50 * An example is "Copy" or "Copy…". The latter one is used when nothing is selected and signifies
51 * that it will trigger SelectionMode so items can be selected and then copied.
52 */
53 struct RegisteredActionTextChange {
54 QPointer<QAction> action;
55 QString registeredText;
56 TextState textStateOfRegisteredText;
57
58 RegisteredActionTextChange(QAction *action, QString registeredText, TextState state)
59 : action{action}
60 , registeredText{registeredText}
61 , textStateOfRegisteredText{state} {};
62 };
63
64 /**
65 * @see RegisteredActionTextChange
66 */
67 std::vector<RegisteredActionTextChange> m_registeredActionTextChanges;
68 };
69
70 }
71
72 #endif // ACTIONTEXTHELPER_H