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));
167 &QVariant::fromValue<QKeySequence>);
168 CoreProxy_->GetEntityManager ()->HandleEntity (e);
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));