60 SIGNAL (destroyed ()),
62 SLOT (handleActionDestroyed ()));
64 const QIcon& icon = act->icon ().isNull () ?
65 CoreProxy_->GetIconThemeManager ()->GetIcon (act->property (
"ActionIcon").toString ()) :
68 { act->text (), act->shortcuts (), icon });
70 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
72 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
77 Shortcuts_ [id] << shortcut;
79 SIGNAL (destroyed ()),
81 SLOT (handleShortcutDestroyed ()));
85 if (CoreProxy_->GetShortcutProxy ()->HasObject (ContextObj_))
87 CoreProxy_->GetShortcutProxy ()->GetShortcuts (ContextObj_,
id));
92 if (!ActionInfo_.contains (
id) ||
93 ActionInfo_ [id].UserVisibleText_.isEmpty ())
94 ActionInfo_ [
id] = info;
98 QObject *target,
const QByteArray& method,
const ActionInfo& info)
101 "x-leechcraft/global-action-register");
102 e.
Additional_ [
"Receiver"] = QVariant::fromValue (target);
109 ActionInfo_ [id] = info;
114 for (
const auto& entity : Globals_)
115 CoreProxy_->GetEntityManager ()->HandleEntity (entity);
120 for (
auto act : Actions_ [
id])
121 act->setShortcuts (seqs);
123 for (
auto sc : Shortcuts_ [
id])
125 sc->setKey (seqs.value (0));
126 qDeleteAll (Shortcut2Subs_.take (sc));
128 const auto seqsSize = seqs.size ();
130 for (
int i = 1; i < seqsSize; ++i)
132 auto subsc =
new QShortcut { sc->parentWidget () };
133 subsc->setContext (sc->context ());
134 subsc->setKey (seqs.value (i));
136 SIGNAL (activated ()),
138 SIGNAL (activated ()));
139 Shortcut2Subs_ [sc] << subsc;
143 if (Globals_.contains (
id))
145 auto& e = Globals_ [id];
146 e.Additional_ [
"Shortcut"] = QVariant::fromValue (seqs.value (0));
147 e.Additional_ [
"AltShortcuts"] =
Util::Map (seqs.mid (1),
148 &QVariant::fromValue<QKeySequence>);
149 CoreProxy_->GetEntityManager ()->HandleEntity (e);
160 RegisterAction (pair.first, pair.second);
164 void ShortcutManager::handleActionDestroyed ()
166 auto act =
static_cast<QAction*
> (sender ());
167 for (
const auto&
id : Actions_.keys ())
168 Actions_ [
id].removeAll (act);
171 void ShortcutManager::handleShortcutDestroyed()
173 auto sc =
static_cast<QShortcut*
> (sender ());
174 for (
const auto&
id : Shortcuts_.keys ())
175 Shortcuts_ [
id].removeAll (sc);
177 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.
ShortcutManager(ICoreProxy_ptr proxy, QObject *parent=0)
Creates the shortcut manager.
void SetObject(QObject *pluginObj)
Sets the plugin instance object of this manager.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
void AnnounceGlobalShorcuts()
Announces the global shortcuts.
auto Map(const Container< T > &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f, std::declval< T >()))>::value, WrapType_t< Container< typename std::decay< decltype(Invoke(f, std::declval< T >()))>::type >>>::type
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.
Aids in providing configurable shortcuts.
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.