26 , CoreProxy_ { proxy }
27 , ContextObj_ { parent }
39 for (
auto& list : Actions_)
43 if (HasActionInfo (
id))
45 const auto& info = ActionInfo_ [id];
46 if (act->text ().isEmpty ())
47 act->setText (info.Text_);
48 if (act->icon ().isNull ())
51 [
this, act] (
const QByteArray& name)
53 act->setIcon (CoreProxy_->GetIconThemeManager ()->GetIcon (name));
54 act->setProperty (
"ActionIcon", name);
56 [act] (
const QIcon& icon) { act->setIcon (icon); });
60 const auto& icon = act->icon ().isNull () ?
61 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
63 auto shortcuts = act->shortcuts ();
73 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
75 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
80 for (
const auto& [
id, act] : pairs)
86 Shortcuts_ [id] << shortcut;
92 for (
auto& list : Shortcuts_)
93 list.removeAll (shortcut);
95 qDeleteAll (Shortcut2Subs_.take (shortcut));
100 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
102 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
107 if (!HasActionInfo (
id))
108 ActionInfo_ [id] = info;
112 QObject *target,
const QByteArray& method,
const ActionInfo& info)
116 e.
Additional_ [Receiver] = QVariant::fromValue (target);
121 [] (
const QKeySequence& seq) { return QVariant::fromValue (seq); });
124 ActionInfo_ [id] = info;
129 for (
const auto& entity : std::as_const (Globals_))
130 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
135 for (
auto act : std::as_const (Actions_ [
id]))
136 act->setShortcuts (seqs);
138 for (
auto sc : std::as_const (Shortcuts_ [
id]))
140 sc->setKey (seqs.value (0));
141 qDeleteAll (Shortcut2Subs_.take (sc));
143 const int seqsSize = seqs.size ();
144 for (
int i = 1; i < seqsSize; ++i)
146 auto subsc =
new QShortcut { sc->parent () };
147 subsc->setContext (sc->context ());
148 subsc->setKey (seqs.value (i));
150 &QShortcut::activated,
152 &QShortcut::activated);
153 Shortcut2Subs_ [sc] << subsc;
157 if (Globals_.contains (
id))
159 auto& e = Globals_ [id];
160 e.Additional_ [QStringLiteral (
"Shortcut")] = QVariant::fromValue (seqs.value (0));
161 e.Additional_ [QStringLiteral (
"AltShortcuts")] =
Util::Map (seqs.mid (1),
162 [] (
const QKeySequence& seq) { return QVariant::fromValue (seq); });
163 CoreProxy_->GetEntityManager ()->HandleEntity (e);
178 bool ShortcutManager::HasActionInfo (
const QByteArray&
id)
const
180 return ActionInfo_.contains (
id) &&
181 !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.