25 , CoreProxy_ { proxy }
26 , ContextObj_ { parent }
38 for (
auto& list : Actions_)
42 if (HasActionInfo (
id))
44 const auto& info = ActionInfo_ [id];
45 if (act->text ().isEmpty ())
46 act->setText (info.Text_);
47 if (act->icon ().isNull ())
50 [
this, act] (
const QByteArray& name)
52 act->setIcon (CoreProxy_->GetIconThemeManager ()->GetIcon (name));
53 act->setProperty (
"ActionIcon", name);
55 [act] (
const QIcon& icon) { act->setIcon (icon); });
59 const auto& icon = act->icon ().isNull () ?
60 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
62 auto shortcuts = act->shortcuts ();
72 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
74 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
79 for (
const auto& [
id, act] : pairs)
85 Shortcuts_ [id] << shortcut;
91 for (
auto& list : Shortcuts_)
92 list.removeAll (shortcut);
94 qDeleteAll (Shortcut2Subs_.take (shortcut));
99 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
101 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
106 if (!HasActionInfo (
id))
107 ActionInfo_ [id] = info;
111 QObject *target,
const QByteArray& method,
const ActionInfo& info)
115 e.
Additional_ [Receiver] = QVariant::fromValue (target);
120 [] (
const QKeySequence& seq) { return QVariant::fromValue (seq); });
123 ActionInfo_ [id] = info;
128 for (
const auto& entity : qAsConst (Globals_))
129 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
134 for (
auto act : qAsConst (Actions_ [
id]))
135 act->setShortcuts (seqs);
137 for (
auto sc : qAsConst (Shortcuts_ [
id]))
139 sc->setKey (seqs.value (0));
140 qDeleteAll (Shortcut2Subs_.take (sc));
142 const int seqsSize = seqs.size ();
143 for (
int i = 1; i < seqsSize; ++i)
145 auto subsc =
new QShortcut { sc->parentWidget () };
146 subsc->setContext (sc->context ());
147 subsc->setKey (seqs.value (i));
149 &QShortcut::activated,
151 &QShortcut::activated);
152 Shortcut2Subs_ [sc] << subsc;
156 if (Globals_.contains (
id))
158 auto& e = Globals_ [id];
159 e.Additional_ [QStringLiteral (
"Shortcut")] = QVariant::fromValue (seqs.value (0));
160 e.Additional_ [QStringLiteral (
"AltShortcuts")] =
Util::Map (seqs.mid (1),
161 [] (
const QKeySequence& seq) { return QVariant::fromValue (seq); });
162 CoreProxy_->GetEntityManager ()->HandleEntity (e);
177 bool ShortcutManager::HasActionInfo (
const QByteArray&
id)
const
179 return ActionInfo_.contains (
id) &&
180 !ActionInfo_ [id].Text_.isEmpty ();
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
QList< QKeySequence > QKeySequences_t
Entity fields corresponding to global action registration.
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.