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 "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 <QEvent>
|
||||
#include <QSignalMapper>
|
||||
#include <QtAlgorithms>
|
||||
#include <QStringList>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QEvent>
|
||||
#include <QObject>
|
||||
#include <QShortcut>
|
||||
#include <QSignalMapper>
|
||||
#include <QStringList>
|
||||
#include <QtAlgorithms>
|
||||
|
||||
using namespace Macros;
|
||||
using namespace Macros::Internal;
|
||||
using namespace Core;
|
||||
|
||||
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
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user