59 SIGNAL (destroyed ()),
61 SLOT (handleActionDestroyed ()));
63 if (HasActionInfo (
id))
65 const auto& info = ActionInfo_ [id];
66 if (act->text ().isEmpty ())
67 act->setText (info.UserVisibleText_);
68 if (act->icon ().isNull () &&
69 act->property (
"ActionIcon").isNull ())
70 act->setIcon (info.Icon_);
74 const auto& icon = act->icon ().isNull () ?
75 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
85 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
87 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
92 for (
const auto& [
id, act] : pairs)
98 Shortcuts_ [id] << shortcut;
100 SIGNAL (destroyed ()),
102 SLOT (handleShortcutDestroyed ()));
106 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
108 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
113 if (!HasActionInfo (
id))
114 ActionInfo_ [id] = info;
118 QObject *target,
const QByteArray& method,
const ActionInfo& info)
121 "x-leechcraft/global-action-register");
122 e.
Additional_ [
"Receiver"] = QVariant::fromValue (target);
129 ActionInfo_ [id] = info;
134 for (
const auto& entity : Globals_)
135 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
140 for (
auto act : Actions_ [
id])
141 act->setShortcuts (seqs);
143 for (
auto sc : Shortcuts_ [
id])
145 sc->setKey (seqs.value (0));
146 qDeleteAll (Shortcut2Subs_.take (sc));
148 const int seqsSize = seqs.size ();
149 for (
int i = 1; i < seqsSize; ++i)
151 auto subsc =
new QShortcut { sc->parentWidget () };
152 subsc->setContext (sc->context ());
153 subsc->setKey (seqs.value (i));
155 SIGNAL (activated ()),
157 SIGNAL (activated ()));
158 Shortcut2Subs_ [sc] << subsc;
162 if (Globals_.contains (
id))
164 auto& e = Globals_ [id];
165 e.Additional_ [
"Shortcut"] = QVariant::fromValue (seqs.value (0));
166 e.Additional_ [
"AltShortcuts"] =
Util::Map (seqs.mid (1),
167 &QVariant::fromValue<QKeySequence>);
168 CoreProxy_->GetEntityManager ()->HandleEntity (e);
179 RegisterAction (pair.first, pair.second);
183 bool ShortcutManager::HasActionInfo (
const QString&
id)
const 185 return ActionInfo_.contains (
id) &&
186 !ActionInfo_ [id].UserVisibleText_.isEmpty ();
189 void ShortcutManager::handleActionDestroyed ()
191 auto act =
static_cast<QAction*
> (sender ());
192 for (
auto& list : Actions_)
193 list.removeAll (act);
196 void ShortcutManager::handleShortcutDestroyed()
198 auto sc =
static_cast<QShortcut*
> (sender ());
199 for (
auto& list : Shortcuts_)
202 qDeleteAll (Shortcut2Subs_.take (sc));
void SetShortcut(const QString &id, const QKeySequences_t &sequences)
Sets the key sequence for the given action.
ShortcutManager(ICoreProxy_ptr proxy, QObject *parent=nullptr)
Creates the shortcut manager.
void RegisterAction(const QString &id, QAction *action)
Registers the given QAction by the given id.
Describes an action exposed in shortcut manager.
void RegisterActions(const std::initializer_list< IDPair_t > &actions)
void RegisterGlobalShortcut(const QString &id, QObject *target, const QByteArray &method, const ActionInfo &info)
Registers the given global shortcut with the given id.
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
auto Map(Container &&c, F f)
void SetObject(QObject *pluginObj)
Sets the plugin instance object of this manager.
void RegisterActionInfo(const QString &id, const ActionInfo &info)
Registers the given action info with the given id.
void RegisterShortcut(const QString &id, const ActionInfo &info, QShortcut *shortcut)
Registers the given QShortcut with the given id.
void AnnounceGlobalShorcuts()
Announces the global shortcuts.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
QMap< QString, QVariant > Additional_
Additional parameters.
Aids in providing configurable shortcuts.
A message used for inter-plugin communication.
QKeySequences_t Seqs_
List of key sequences for this action.
QMap< QString, ActionInfo > GetActionInfo() const
Returns the map with information about actions.