forked from qt-creator/qt-creator
Macros: Use Core::Id instead of strings in some places
Change-Id: Ib6c23db2b6a37a2dfd831da76c15c6fba8113ff6 Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
This commit is contained in:
committed by
Nicolas Arnaud-Cormos
parent
14e4c19c2c
commit
a31dd26e48
@@ -31,26 +31,27 @@
|
|||||||
#include "macroevent.h"
|
#include "macroevent.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/id.h>
|
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/id.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <QEvent>
|
|
||||||
#include <QSignalMapper>
|
|
||||||
#include <QtAlgorithms>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QObject>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
#include <QSignalMapper>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QtAlgorithms>
|
||||||
|
|
||||||
using namespace Macros;
|
using namespace Core;
|
||||||
using namespace Macros::Internal;
|
|
||||||
|
namespace Macros {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
static const char EVENTNAME[] = "Action";
|
static const char EVENTNAME[] = "Action";
|
||||||
static quint8 ACTIONNAME = 0;
|
static quint8 ACTIONNAME = 0;
|
||||||
@@ -61,27 +62,25 @@ ActionMacroHandler::ActionMacroHandler():
|
|||||||
connect(m_mapper, SIGNAL(mapped(QString)),
|
connect(m_mapper, SIGNAL(mapped(QString)),
|
||||||
this, SLOT(addActionEvent(QString)));
|
this, SLOT(addActionEvent(QString)));
|
||||||
|
|
||||||
connect(Core::ActionManager::instance(), SIGNAL(commandAdded(QString)),
|
connect(ActionManager::instance(), SIGNAL(commandAdded(QString)),
|
||||||
this, SLOT(addCommand(QString)));
|
this, SLOT(addCommand(QString)));
|
||||||
|
|
||||||
// Register all existing scriptable actions
|
// Register all existing scriptable actions
|
||||||
QList<Core::Command *> commands = Core::ActionManager::commands();
|
QList<Command *> commands = ActionManager::commands();
|
||||||
foreach (Core::Command *command, commands) {
|
foreach (Command *command, commands) {
|
||||||
if (command->isScriptable()) {
|
if (command->isScriptable())
|
||||||
QString id = command->id().toString();
|
registerCommand(command->id());
|
||||||
registerCommand(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
bool ActionMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
||||||
{
|
{
|
||||||
return (macroEvent.id() == EVENTNAME);
|
return macroEvent.id() == EVENTNAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent)
|
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)
|
if (!action)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -89,40 +88,45 @@ bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionMacroHandler::addActionEvent(const QString &id)
|
void ActionMacroHandler::addActionEvent(const QString &name)
|
||||||
{
|
{
|
||||||
if (!isRecording())
|
if (!isRecording())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Core::Command *cmd = Core::ActionManager::command(Core::Id(id));
|
const Id id = Id::fromString(name);
|
||||||
if (cmd->isScriptable(cmd->context())) {
|
const Command *command = ActionManager::command(id);
|
||||||
|
if (command->isScriptable(command->context())) {
|
||||||
MacroEvent e;
|
MacroEvent e;
|
||||||
e.setId(EVENTNAME);
|
e.setId(EVENTNAME);
|
||||||
e.setValue(ACTIONNAME, id);
|
e.setValue(ACTIONNAME, id.toSetting());
|
||||||
addMacroEvent(e);
|
addMacroEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionMacroHandler::registerCommand(const QString &id)
|
void ActionMacroHandler::registerCommand(Id id)
|
||||||
{
|
{
|
||||||
if (!m_commandIds.contains(id)) {
|
if (!m_commandIds.contains(id)) {
|
||||||
m_commandIds.insert(id);
|
m_commandIds.insert(id);
|
||||||
QAction* action = Core::ActionManager::command(Core::Id(id))->action();
|
const Command *command = ActionManager::command(id);
|
||||||
if (action) {
|
if (QAction *action = command->action()) {
|
||||||
connect(action, SIGNAL(triggered()), m_mapper, SLOT(map()));
|
connect(action, SIGNAL(triggered()), m_mapper, SLOT(map()));
|
||||||
m_mapper->setMapping(action, id);
|
m_mapper->setMapping(action, id.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QShortcut* shortcut = Core::ActionManager::command(Core::Id(id))->shortcut();
|
if (QShortcut *shortcut = command->shortcut()) {
|
||||||
if (shortcut) {
|
|
||||||
connect(shortcut, SIGNAL(activated()), m_mapper, SLOT(map()));
|
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);
|
registerCommand(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Macros
|
||||||
|
@@ -32,10 +32,12 @@
|
|||||||
|
|
||||||
#include "imacrohandler.h"
|
#include "imacrohandler.h"
|
||||||
|
|
||||||
|
#include <coreplugin/id.h>
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
|
||||||
class QSignalMapper;
|
class QSignalMapper;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -53,14 +55,15 @@ public:
|
|||||||
bool executeEvent(const MacroEvent ¯oEvent);
|
bool executeEvent(const MacroEvent ¯oEvent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void registerCommand(const QString &id);
|
void registerCommand(Core::Id id);
|
||||||
|
Core::Command *command(const QString &id);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addCommand(const QString &id);
|
void addCommand(const QString &id);
|
||||||
void addActionEvent(const QString &id);
|
void addActionEvent(const QString &id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<QString> m_commandIds;
|
QSet<Core::Id> m_commandIds;
|
||||||
QSignalMapper *m_mapper;
|
QSignalMapper *m_mapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ using namespace Macros;
|
|||||||
class MacroEvent::MacroEventPrivate
|
class MacroEvent::MacroEventPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QByteArray id;
|
Core::Id id;
|
||||||
QMap<quint8, QVariant> values;
|
QMap<quint8, QVariant> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,7 +98,9 @@ void MacroEvent::setValue(quint8 id, const QVariant &value)
|
|||||||
|
|
||||||
void MacroEvent::load(QDataStream &stream)
|
void MacroEvent::load(QDataStream &stream)
|
||||||
{
|
{
|
||||||
stream >> d->id;
|
QByteArray ba;
|
||||||
|
stream >> ba;
|
||||||
|
d->id = Core::Id(ba);
|
||||||
int count;
|
int count;
|
||||||
stream >> count;
|
stream >> count;
|
||||||
quint8 id;
|
quint8 id;
|
||||||
@@ -112,7 +114,7 @@ void MacroEvent::load(QDataStream &stream)
|
|||||||
|
|
||||||
void MacroEvent::save(QDataStream &stream) const
|
void MacroEvent::save(QDataStream &stream) const
|
||||||
{
|
{
|
||||||
stream << d->id;
|
stream << d->id.name();
|
||||||
stream << d->values.count();
|
stream << d->values.count();
|
||||||
QMapIterator<quint8, QVariant> i(d->values);
|
QMapIterator<quint8, QVariant> i(d->values);
|
||||||
while (i.hasNext()) {
|
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;
|
return d->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroEvent::setId(const char *id)
|
void MacroEvent::setId(Core::Id id)
|
||||||
{
|
{
|
||||||
d->id = id;
|
d->id = id;
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include "macros_global.h"
|
#include "macros_global.h"
|
||||||
|
|
||||||
|
#include <coreplugin/id.h>
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -50,8 +52,8 @@ public:
|
|||||||
virtual ~MacroEvent();
|
virtual ~MacroEvent();
|
||||||
MacroEvent& operator=(const MacroEvent &other);
|
MacroEvent& operator=(const MacroEvent &other);
|
||||||
|
|
||||||
const QByteArray &id() const;
|
Core::Id id() const;
|
||||||
void setId(const char *id);
|
void setId(Core::Id id);
|
||||||
|
|
||||||
QVariant value(quint8 id) const;
|
QVariant value(quint8 id) const;
|
||||||
void setValue(quint8 id, const QVariant &value);
|
void setValue(quint8 id, const QVariant &value);
|
||||||
|
Reference in New Issue
Block a user