23 , CoreProxy_ { proxy }
40 for (
auto& list : Actions_)
44 if (HasActionInfo (
id))
46 const auto& info = ActionInfo_ [id];
47 if (act->text ().isEmpty ())
48 act->setText (info.UserVisibleText_);
49 if (act->icon ().isNull () &&
50 act->property (
"ActionIcon").isNull ())
51 act->setIcon (info.Icon_);
55 const auto& icon = act->icon ().isNull () ?
56 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
66 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
68 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
73 for (
const auto& [
id, act] : pairs)
79 Shortcuts_ [id] << shortcut;
85 for (
auto& list : Shortcuts_)
86 list.removeAll (shortcut);
88 qDeleteAll (Shortcut2Subs_.take (shortcut));
93 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
95 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
100 if (!HasActionInfo (
id))
101 ActionInfo_ [id] = info;
105 QObject *target,
const QByteArray& method,
const ActionInfo& info)
108 QStringLiteral (
"x-leechcraft/global-action-register"));
109 e.
Additional_ [QStringLiteral (
"Receiver")] = QVariant::fromValue (target);
111 e.
Additional_ [QStringLiteral (
"Method")] = method;
112 e.
Additional_ [QStringLiteral (
"Shortcut")] = QVariant::fromValue (info.
Seqs_.value (0));
116 ActionInfo_ [id] = info;
121 for (
const auto& entity : Globals_)
122 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
127 for (
auto act : Actions_ [
id])
128 act->setShortcuts (seqs);
130 for (
auto sc : Shortcuts_ [
id])
132 sc->setKey (seqs.value (0));
133 qDeleteAll (Shortcut2Subs_.take (sc));
135 const int seqsSize = seqs.size ();
136 for (
int i = 1; i < seqsSize; ++i)
138 auto subsc =
new QShortcut { sc->parentWidget () };
139 subsc->setContext (sc->context ());
140 subsc->setKey (seqs.value (i));
142 &QShortcut::activated,
144 &QShortcut::activated);
145 Shortcut2Subs_ [sc] << subsc;
149 if (Globals_.contains (
id))
151 auto& e = Globals_ [id];
152 e.Additional_ [QStringLiteral (
"Shortcut")] = QVariant::fromValue (seqs.value (0));
153 e.Additional_ [QStringLiteral (
"AltShortcuts")] =
Util::Map (seqs.mid (1),
154 &QVariant::fromValue<QKeySequence>);
155 CoreProxy_->GetEntityManager ()->HandleEntity (e);
170 bool ShortcutManager::HasActionInfo (
const QString&
id)
const
172 return ActionInfo_.contains (
id) &&
173 !ActionInfo_ [id].UserVisibleText_.isEmpty ();
Aids in providing configurable shortcuts.
void AnnounceGlobalShorcuts()
Announces the global shortcuts.
void RegisterActionInfo(const QString &id, const ActionInfo &info)
Registers the given action info with the given id.
void RegisterAction(const QString &id, QAction *action)
Registers the given QAction by the given id.
QMap< QString, ActionInfo > GetActionInfo() const
Returns the map with information about actions.
void SetObject(QObject *pluginObj)
Sets the plugin instance object of this manager.
void RegisterGlobalShortcut(const QString &id, QObject *target, const QByteArray &method, const ActionInfo &info)
Registers the given global shortcut with the given id.
ShortcutManager(const ICoreProxy_ptr &proxy, QObject *parent=nullptr)
Creates the shortcut manager.
void SetShortcut(const QString &id, const QKeySequences_t &sequences)
Sets the key sequence for the given action.
void RegisterShortcut(const QString &id, const ActionInfo &info, QShortcut *shortcut)
Registers the given QShortcut with the given id.
void RegisterActions(const std::initializer_list< IDPair_t > &actions)
ShortcutManager & operator<<(const QPair< QString, QAction * > &pair)
Utility function equivalent to RegisterAction().
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
auto Map(Container &&c, F f)
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
Describes an action exposed in shortcut manager.
QKeySequences_t Seqs_
List of key sequences for this action.
A message used for inter-plugin communication.
QMap< QString, QVariant > Additional_
Additional parameters.