]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/actiontexthelper.h
Better separation of classes
[dolphin.git] / src / selectionmode / actiontexthelper.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
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 class ActionTextHelper : QObject
22 {
23 public:
24 explicit ActionTextHelper(QObject *parent);
25
26 /**
27 * Changes the text of \a action to \a text whenever textsWhenNothingIsSelectedEnabled(true) is called.
28 * The texts can be changed back by calling textsWhenNothingIsSelectedEnabled(false) is called.
29 * @see textsWhenNothingIsSelectedEnabled()
30 */
31 void registerTextWhenNothingIsSelected(QAction *action, QString registeredText);
32
33 /**
34 * Changes all texts that were registered previously using registerTextWhenNothingIsSelected() to those
35 * registered texts if called with \a enabled == true. Otherwise resets the texts to the original one.
36 */
37 void textsWhenNothingIsSelectedEnabled(bool enabled);
38
39 private:
40 enum TextState {
41 TextWhenNothingIsSelected,
42 TextWhenSomethingIsSelected
43 };
44
45 /**
46 * Utility struct to allow switching back and forth between registered actions showing their
47 * distinct texts for when no items are selected or when items are selected.
48 * An example is "Copy" or "Copy…". The latter one is used when nothing is selected and signifies
49 * that it will trigger SelectionMode so items can be selected and then copied.
50 */
51 struct RegisteredActionTextChange {
52 QPointer<QAction> action;
53 QString registeredText;
54 TextState textStateOfRegisteredText;
55
56 RegisteredActionTextChange(QAction *action, QString registeredText, TextState state) :
57 action{action},
58 registeredText{registeredText},
59 textStateOfRegisteredText{state}
60 { };
61 };
62
63 /**
64 * @see RegisteredActionTextChange
65 */
66 std::vector<RegisteredActionTextChange> m_registeredActionTextChanges;
67 };
68
69 }
70
71 #endif // ACTIONTEXTHELPER_H