59 SIGNAL (destroyed ()),
61 SLOT (handleActionDestroyed ()));
63 const QIcon& icon = act->icon ().isNull () ?
64 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
67 { act->text (), act->shortcuts (), icon });
69 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
71 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
76 Shortcuts_ [id] << shortcut;
78 SIGNAL (destroyed ()),
80 SLOT (handleShortcutDestroyed ()));
84 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
86 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
91 if (!ActionInfo_.contains (
id) ||
92 ActionInfo_ [id].UserVisibleText_.isEmpty ())
93 ActionInfo_ [
id] = info;
97 QObject *target,
const QByteArray& method,
const ActionInfo& info)
100 "x-leechcraft/global-action-register");
101 e.
Additional_ [
"Receiver"] = QVariant::fromValue (target);
108 ActionInfo_ [id] = info;
113 for (
const auto& entity : Globals_)
114 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
119 for (
auto act : Actions_ [
id])
120 act->setShortcuts (seqs);
122 for (
auto sc : Shortcuts_ [
id])
124 sc->setKey (seqs.value (0));
125 qDeleteAll (Shortcut2Subs_.take (sc));
127 const int seqsSize = seqs.size ();
128 for (
int i = 1; i < seqsSize; ++i)
130 auto subsc =
new QShortcut { sc->parentWidget () };
131 subsc->setContext (sc->context ());
132 subsc->setKey (seqs.value (i));
134 SIGNAL (activated ()),
136 SIGNAL (activated ()));
137 Shortcut2Subs_ [sc] << subsc;
141 if (Globals_.contains (
id))
143 auto& e = Globals_ [id];
144 e.Additional_ [
"Shortcut"] = QVariant::fromValue (seqs.value (0));
145 e.Additional_ [
"AltShortcuts"] =
Util::Map (seqs.mid (1),
146 &QVariant::fromValue<QKeySequence>);
147 CoreProxy_->GetEntityManager ()->HandleEntity (e);
162 void ShortcutManager::handleActionDestroyed ()
164 auto act =
static_cast<QAction*
> (sender ());
165 for (
auto& list : Actions_)
166 list.removeAll (act);
169 void ShortcutManager::handleShortcutDestroyed()
171 auto sc =
static_cast<QShortcut*
> (sender ());
172 for (
auto& list : Shortcuts_)
175 qDeleteAll (Shortcut2Subs_.take (sc));
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
QMap< QString, ActionInfo > GetActionInfo() const
Returns the map with information about actions.
void RegisterShortcut(const QString &id, const ActionInfo &info, QShortcut *shortcut)
Registers the given QShortcut with the given id.
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(const Container< T > &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f,*c.begin()))>::value, WrapType_t< Container< typename std::decay< decltype(Invoke(f,*c.begin()))>::type >>>::type
QMap< QString, QVariant > Additional_
Additional parameters.
void SetShortcut(const QString &id, const QKeySequences_t &sequences)
Sets the key sequence for the given action.
Describes parameters of an entity.
void RegisterActionInfo(const QString &id, const ActionInfo &info)
Registers the given action info with the given id.