diff --git a/src/plugins/macros/actionmacrohandler.cpp b/src/plugins/macros/actionmacrohandler.cpp index aa5b95132640fb309a7366fc557d9a161b3a92dc..8a38301dc7d8038a4cb637784dd1c42d192b8fcf 100644 --- a/src/plugins/macros/actionmacrohandler.cpp +++ b/src/plugins/macros/actionmacrohandler.cpp @@ -31,26 +31,27 @@ #include "macroevent.h" #include "macro.h" -#include <texteditor/texteditorconstants.h> - -#include <coreplugin/icore.h> #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/command.h> #include <coreplugin/coreconstants.h> -#include <coreplugin/id.h> #include <coreplugin/icontext.h> +#include <coreplugin/icore.h> +#include <coreplugin/id.h> -#include <QObject> +#include <texteditor/texteditorconstants.h> + +#include <QAction> #include <QEvent> +#include <QObject> +#include <QShortcut> #include <QSignalMapper> -#include <QtAlgorithms> #include <QStringList> +#include <QtAlgorithms> -#include <QAction> -#include <QShortcut> +using namespace Core; -using namespace Macros; -using namespace Macros::Internal; +namespace Macros { +namespace Internal { static const char EVENTNAME[] = "Action"; static quint8 ACTIONNAME = 0; @@ -61,27 +62,25 @@ ActionMacroHandler::ActionMacroHandler(): connect(m_mapper, SIGNAL(mapped(QString)), this, SLOT(addActionEvent(QString))); - connect(Core::ActionManager::instance(), SIGNAL(commandAdded(QString)), + connect(ActionManager::instance(), SIGNAL(commandAdded(QString)), this, SLOT(addCommand(QString))); // Register all existing scriptable actions - QList<Core::Command *> commands = Core::ActionManager::commands(); - foreach (Core::Command *command, commands) { - if (command->isScriptable()) { - QString id = command->id().toString(); - registerCommand(id); - } + QList<Command *> commands = ActionManager::commands(); + foreach (Command *command, commands) { + if (command->isScriptable()) + registerCommand(command->id()); } } bool ActionMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent) { - return (macroEvent.id() == EVENTNAME); + return macroEvent.id() == EVENTNAME; } bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent) { - QAction *action = Core::ActionManager::command(Core::Id(macroEvent.value(ACTIONNAME).toString()))->action(); + QAction *action = ActionManager::command(Id::fromSetting(macroEvent.value(ACTIONNAME)))->action(); if (!action) return false; @@ -89,40 +88,45 @@ bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent) return true; } -void ActionMacroHandler::addActionEvent(const QString &id) +void ActionMacroHandler::addActionEvent(const QString &name) { if (!isRecording()) return; - const Core::Command *cmd = Core::ActionManager::command(Core::Id(id)); - if (cmd->isScriptable(cmd->context())) { + const Id id = Id::fromString(name); + const Command *command = ActionManager::command(id); + if (command->isScriptable(command->context())) { MacroEvent e; e.setId(EVENTNAME); - e.setValue(ACTIONNAME, id); + e.setValue(ACTIONNAME, id.toSetting()); addMacroEvent(e); } } -void ActionMacroHandler::registerCommand(const QString &id) +void ActionMacroHandler::registerCommand(Id id) { if (!m_commandIds.contains(id)) { m_commandIds.insert(id); - QAction* action = Core::ActionManager::command(Core::Id(id))->action(); - if (action) { + const Command *command = ActionManager::command(id); + if (QAction *action = command->action()) { connect(action, SIGNAL(triggered()), m_mapper, SLOT(map())); - m_mapper->setMapping(action, id); + m_mapper->setMapping(action, id.toString()); return; } - QShortcut* shortcut = Core::ActionManager::command(Core::Id(id))->shortcut(); - if (shortcut) { + if (QShortcut *shortcut = command->shortcut()) { connect(shortcut, SIGNAL(activated()), m_mapper, SLOT(map())); - m_mapper->setMapping(shortcut, id); + m_mapper->setMapping(shortcut, id.toString()); } } } -void ActionMacroHandler::addCommand(const QString &id) +void ActionMacroHandler::addCommand(const QString &name) { - if (Core::ActionManager::command(Core::Id(id))->isScriptable()) + const Id id = Id::fromString(name); + const Command *command = ActionManager::command(id); + if (command->isScriptable()) registerCommand(id); } + +} // namespace Internal +} // namespace Macros diff --git a/src/plugins/macros/actionmacrohandler.h b/src/plugins/macros/actionmacrohandler.h index 255d6b28e4cebde2b781c4554648e8ab8068ee5c..02db0fda63ea3fc81fa79952e4a1f6f21b4565ce 100644 --- a/src/plugins/macros/actionmacrohandler.h +++ b/src/plugins/macros/actionmacrohandler.h @@ -32,10 +32,12 @@ #include "imacrohandler.h" +#include <coreplugin/id.h> +#include <coreplugin/actionmanager/actionmanager.h> + #include <QSet> QT_BEGIN_NAMESPACE -class QAction; class QSignalMapper; QT_END_NAMESPACE @@ -53,14 +55,15 @@ public: bool executeEvent(const MacroEvent ¯oEvent); private: - void registerCommand(const QString &id); + void registerCommand(Core::Id id); + Core::Command *command(const QString &id); private slots: void addCommand(const QString &id); void addActionEvent(const QString &id); private: - QSet<QString> m_commandIds; + QSet<Core::Id> m_commandIds; QSignalMapper *m_mapper; }; diff --git a/src/plugins/macros/macroevent.cpp b/src/plugins/macros/macroevent.cpp index 8276a6f03b2fd50c42eca82c887bfbe5ee10f803..acdc1ccd05dfbdc6496116f449ec514480cda340 100644 --- a/src/plugins/macros/macroevent.cpp +++ b/src/plugins/macros/macroevent.cpp @@ -53,7 +53,7 @@ using namespace Macros; class MacroEvent::MacroEventPrivate { public: - QByteArray id; + Core::Id id; QMap<quint8, QVariant> values; }; @@ -98,7 +98,9 @@ void MacroEvent::setValue(quint8 id, const QVariant &value) void MacroEvent::load(QDataStream &stream) { - stream >> d->id; + QByteArray ba; + stream >> ba; + d->id = Core::Id(ba); int count; stream >> count; quint8 id; @@ -112,7 +114,7 @@ void MacroEvent::load(QDataStream &stream) void MacroEvent::save(QDataStream &stream) const { - stream << d->id; + stream << d->id.name(); stream << d->values.count(); QMapIterator<quint8, QVariant> i(d->values); while (i.hasNext()) { @@ -121,12 +123,12 @@ void MacroEvent::save(QDataStream &stream) const } } -const QByteArray & MacroEvent::id() const +Core::Id MacroEvent::id() const { return d->id; } -void MacroEvent::setId(const char *id) +void MacroEvent::setId(Core::Id id) { d->id = id; } diff --git a/src/plugins/macros/macroevent.h b/src/plugins/macros/macroevent.h index 93667fe82e1ab1fc5ab04640996def3528e4145c..263edb4e096cf7afbc26a8de19a9280f3faf8edd 100644 --- a/src/plugins/macros/macroevent.h +++ b/src/plugins/macros/macroevent.h @@ -32,6 +32,8 @@ #include "macros_global.h" +#include <coreplugin/id.h> + #include <QMap> QT_BEGIN_NAMESPACE @@ -50,8 +52,8 @@ public: virtual ~MacroEvent(); MacroEvent& operator=(const MacroEvent &other); - const QByteArray &id() const; - void setId(const char *id); + Core::Id id() const; + void setId(Core::Id id); QVariant value(quint8 id) const; void setValue(quint8 id, const QVariant &value);