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 Shortcuts_ [id] << shortcut;
94 SIGNAL (destroyed ()),
96 SLOT (handleShortcutDestroyed ()));
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)
115 "x-leechcraft/global-action-register");
116 e.
Additional_ [
"Receiver"] = QVariant::fromValue (target);
123 ActionInfo_ [id] = info;
128 for (
const auto& entity : Globals_)
129 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
134 for (
auto act : Actions_ [
id])
135 act->setShortcuts (seqs);
137 for (
auto sc : 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 SIGNAL (activated ()),
151 SIGNAL (activated ()));
152 Shortcut2Subs_ [sc] << subsc;
156 if (Globals_.contains (
id))
158 auto& e = Globals_ [id];
159 e.Additional_ [
"Shortcut"] = QVariant::fromValue (seqs.value (0));
160 e.Additional_ [
"AltShortcuts"] =
Util::Map (seqs.mid (1),
161 &QVariant::fromValue<QKeySequence>);
162 CoreProxy_->GetEntityManager ()->HandleEntity (e);
173 RegisterAction (pair.first, pair.second);
177 bool ShortcutManager::HasActionInfo (
const QString&
id)
const 179 return ActionInfo_.contains (
id) &&
180 !ActionInfo_ [id].UserVisibleText_.isEmpty ();
183 void ShortcutManager::handleActionDestroyed ()
185 auto act =
static_cast<QAction*
> (sender ());
186 for (
auto& list : Actions_)
187 list.removeAll (act);
190 void ShortcutManager::handleShortcutDestroyed()
192 auto sc =
static_cast<QShortcut*
> (sender ());
193 for (
auto& list : Shortcuts_)
196 qDeleteAll (Shortcut2Subs_.take (sc));
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
void RegisterShortcut(const QString &id, const ActionInfo &info, QShortcut *shortcut)
Registers the given QShortcut with 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 AnnounceGlobalShorcuts()
Announces the global shortcuts.
ShortcutManager(ICoreProxy_ptr proxy, QObject *parent=nullptr)
Creates the shortcut manager.
void RegisterGlobalShortcut(const QString &id, QObject *target, const QByteArray &method, const ActionInfo &info)
Registers the given global shortcut with the given id.
void RegisterAction(const QString &id, QAction *action)
Registers the given QAction by the given id.
Describes an action exposed in shortcut manager.
QKeySequences_t Seqs_
List of key sequences for this action.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Aids in providing configurable shortcuts.
auto Map(Container &&c, F f)
QMap< QString, QVariant > Additional_
Additional parameters.
void SetShortcut(const QString &id, const QKeySequences_t &sequences)
Sets the key sequence for the given action.
A message used for inter-plugin communication.
void RegisterActionInfo(const QString &id, const ActionInfo &info)
Registers the given action info with the given id.