24 , CoreProxy_ { proxy }
25 , ContextObj_ { parent }
37 for (
auto& list : Actions_)
41 if (HasActionInfo (
id))
43 const auto& info = ActionInfo_ [id];
44 if (act->text ().isEmpty ())
45 act->setText (info.Text_);
46 if (act->icon ().isNull ())
49 [
this, act] (
const QByteArray& name)
51 act->setIcon (CoreProxy_->GetIconThemeManager ()->GetIcon (name));
52 act->setProperty (
"ActionIcon", name);
54 [act] (
const QIcon& icon) { act->setIcon (icon); });
58 const auto& icon = act->icon ().isNull () ?
61 auto shortcuts = act->shortcuts ();
78 for (
const auto& [
id, act] : pairs)
84 Shortcuts_ [id] << shortcut;
90 for (
auto& list : Shortcuts_)
91 list.removeAll (shortcut);
93 qDeleteAll (Shortcut2Subs_.take (shortcut));
105 if (!HasActionInfo (
id))
106 ActionInfo_ [id] = info;
110 QObject *target,
const QByteArray& method,
const ActionInfo& info)
113 using namespace EF::GlobalAction;
114 e.
Additional_ [Receiver] = QVariant::fromValue (target);
121 ActionInfo_ [id] = info;
126 for (
const auto& entity : qAsConst (Globals_))
132 for (
auto act : qAsConst (Actions_ [
id]))
133 act->setShortcuts (seqs);
135 for (
auto sc : qAsConst (Shortcuts_ [
id]))
137 sc->setKey (seqs.value (0));
138 qDeleteAll (Shortcut2Subs_.take (sc));
140 const int seqsSize = seqs.size ();
141 for (
int i = 1; i < seqsSize; ++i)
143 auto subsc =
new QShortcut { sc->parentWidget () };
144 subsc->setContext (sc->context ());
145 subsc->setKey (seqs.value (i));
147 &QShortcut::activated,
149 &QShortcut::activated);
150 Shortcut2Subs_ [sc] << subsc;
154 if (Globals_.contains (
id))
156 auto& e = Globals_ [id];
157 e.Additional_ [QStringLiteral (
"Shortcut")] = QVariant::fromValue (seqs.value (0));
158 e.Additional_ [QStringLiteral (
"AltShortcuts")] =
Util::Map (seqs.mid (1),
159 &QVariant::fromValue<QKeySequence>);
175 bool ShortcutManager::HasActionInfo (
const QByteArray&
id)
const
177 return ActionInfo_.contains (
id) &&
178 !ActionInfo_ [id].Text_.isEmpty ();
virtual IEntityManager * GetEntityManager() const =0
Returns the entity manager object.
virtual IShortcutProxy * GetShortcutProxy() const =0
Returns the shortcut proxy used to communicate with the shortcut manager.
virtual IIconThemeManager * GetIconThemeManager() const =0
Returns the icon theme manager.
virtual bool HandleEntity(LC::Entity entity, QObject *desired=nullptr)=0
Handles the given entity.
virtual QIcon GetIcon(const QString &on, const QString &off=QString())=0
Returns the current theme's icon for the given on and off states.
virtual QList< QKeySequence > GetShortcuts(QObject *object, const QByteArray &id)=0
Returns a QKeySequence for the given action.
virtual bool HasObject(QObject *object) const =0
Checks whether a given object has been registered already.
Aids in providing configurable shortcuts.
void AnnounceGlobalShorcuts()
Announces the global shortcuts.
ShortcutManager(const ICoreProxy_ptr &proxy, QObject *parent)
Creates the shortcut manager.
ShortcutManager & operator<<(const QPair< QByteArray, QAction * > &pair)
Utility function equivalent to RegisterAction().
void RegisterAction(const QByteArray &id, QAction *action)
Registers the given QAction by the given id.
void SetShortcut(const QByteArray &id, const QKeySequences_t &sequences)
Sets the key sequence for the given action.
void RegisterGlobalShortcut(const QByteArray &id, QObject *target, const QByteArray &method, const ActionInfo &info)
Registers the given global shortcut with the given id.
void RegisterActionInfo(const QByteArray &id, const ActionInfo &info)
Registers the given action info with the given id.
QMap< QByteArray, ActionInfo > GetActionInfo() const
Returns the map with information about actions.
void RegisterActions(const std::initializer_list< IDPair_t > &actions)
void RegisterShortcut(const QByteArray &id, const ActionInfo &info, QShortcut *shortcut)
Registers the given QShortcut with the given id.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Q_DECL_IMPORT const QString GlobalActionRegister
Registration of a global system-wide action.
auto Visit(const Either< Left, Right > &either, Args &&... args)
auto Map(Container &&c, F &&f) noexcept(noexcept(std::is_nothrow_invocable_v< F, decltype(*c.begin())>))
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
Describes an action exposed in shortcut manager.
QKeySequences_t AdditionalSeqs_
The additional key sequences for this action.
QKeySequence Seq_
The primary key sequence for this action.
A message used for inter-plugin communication.
QMap< QString, QVariant > Additional_
Additional parameters.
A proper void type, akin to unit (or ()) type in functional languages.