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
);
45 enum TextState
{ TextWhenNothingIsSelected
, TextWhenSomethingIsSelected
};
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.
53 struct RegisteredActionTextChange
{
54 QPointer
<QAction
> action
;
55 QString registeredText
;
56 TextState textStateOfRegisteredText
;
58 RegisteredActionTextChange(QAction
*action
, QString registeredText
, TextState state
)
60 , registeredText
{registeredText
}
61 , textStateOfRegisteredText
{state
} {};
65 * @see RegisteredActionTextChange
67 std::vector
<RegisteredActionTextChange
> m_registeredActionTextChanges
;
72 #endif // ACTIONTEXTHELPER_H