2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef ACTIONTEXTHELPER_H
9 #define ACTIONTEXTHELPER_H
15 namespace SelectionMode
19 * @brief Helps changing the texts of actions depending on the current selection.
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.
26 class ActionTextHelper
: QObject
29 explicit ActionTextHelper(QObject
*parent
);
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()
36 void registerTextWhenNothingIsSelected(QAction
*action
, QString registeredText
);
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.
42 void textsWhenNothingIsSelectedEnabled(bool enabled
);
46 TextWhenNothingIsSelected
,
47 TextWhenSomethingIsSelected
51 * Utility struct to allow switching back and forth between registered actions showing their
52 * distinct texts for when no items are selected or when items are selected.
53 * An example is "Copy" or "Copy…". The latter one is used when nothing is selected and signifies
54 * that it will trigger SelectionMode so items can be selected and then copied.
56 struct RegisteredActionTextChange
{
57 QPointer
<QAction
> action
;
58 QString registeredText
;
59 TextState textStateOfRegisteredText
;
61 RegisteredActionTextChange(QAction
*action
, QString registeredText
, TextState state
) :
63 registeredText
{registeredText
},
64 textStateOfRegisteredText
{state
}
69 * @see RegisteredActionTextChange
71 std::vector
<RegisteredActionTextChange
> m_registeredActionTextChanges
;
76 #endif // ACTIONTEXTHELPER_H