forked from qt-creator/qt-creator
Macros: Use Qt5-style connects
The heavy lifting was done by clazy. Change-Id: I0154e09c1a9e028f3a80772c4c07751f4e282091 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
34a7ff07b7
commit
8641a5e956
@@ -48,12 +48,8 @@ namespace Internal {
|
|||||||
static const char EVENTNAME[] = "Action";
|
static const char EVENTNAME[] = "Action";
|
||||||
static quint8 ACTIONNAME = 0;
|
static quint8 ACTIONNAME = 0;
|
||||||
|
|
||||||
ActionMacroHandler::ActionMacroHandler():
|
ActionMacroHandler::ActionMacroHandler()
|
||||||
m_mapper(new QSignalMapper(this))
|
|
||||||
{
|
{
|
||||||
connect(m_mapper, SIGNAL(mapped(QString)),
|
|
||||||
this, SLOT(addActionEvent(QString)));
|
|
||||||
|
|
||||||
connect(ActionManager::instance(), &ActionManager::commandAdded,
|
connect(ActionManager::instance(), &ActionManager::commandAdded,
|
||||||
this, &ActionMacroHandler::addCommand);
|
this, &ActionMacroHandler::addCommand);
|
||||||
|
|
||||||
@@ -80,30 +76,23 @@ bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionMacroHandler::addActionEvent(const QString &name)
|
|
||||||
{
|
|
||||||
if (!isRecording())
|
|
||||||
return;
|
|
||||||
|
|
||||||
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.toSetting());
|
|
||||||
addMacroEvent(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionMacroHandler::registerCommand(Id id)
|
void ActionMacroHandler::registerCommand(Id id)
|
||||||
{
|
{
|
||||||
if (!m_commandIds.contains(id)) {
|
if (!m_commandIds.contains(id)) {
|
||||||
m_commandIds.insert(id);
|
m_commandIds.insert(id);
|
||||||
const Command *command = ActionManager::command(id);
|
const Command *command = ActionManager::command(id);
|
||||||
if (QAction *action = command->action()) {
|
if (QAction *action = command->action()) {
|
||||||
connect(action, SIGNAL(triggered()), m_mapper, SLOT(map()));
|
connect(action, &QAction::triggered, this, [this, id, command]() {
|
||||||
m_mapper->setMapping(action, id.toString());
|
if (!isRecording())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (command->isScriptable(command->context())) {
|
||||||
|
MacroEvent e;
|
||||||
|
e.setId(EVENTNAME);
|
||||||
|
e.setValue(ACTIONNAME, id.toSetting());
|
||||||
|
addMacroEvent(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,6 @@
|
|||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QSignalMapper;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Macros {
|
namespace Macros {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -49,9 +45,6 @@ public:
|
|||||||
bool canExecuteEvent(const MacroEvent ¯oEvent);
|
bool canExecuteEvent(const MacroEvent ¯oEvent);
|
||||||
bool executeEvent(const MacroEvent ¯oEvent);
|
bool executeEvent(const MacroEvent ¯oEvent);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void addActionEvent(const QString &id);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void registerCommand(Core::Id id);
|
void registerCommand(Core::Id id);
|
||||||
Core::Command *command(const QString &id);
|
Core::Command *command(const QString &id);
|
||||||
@@ -59,7 +52,6 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<Core::Id> m_commandIds;
|
QSet<Core::Id> m_commandIds;
|
||||||
QSignalMapper *m_mapper;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ static const quint8 RESET = 5;
|
|||||||
FindMacroHandler::FindMacroHandler():
|
FindMacroHandler::FindMacroHandler():
|
||||||
IMacroHandler()
|
IMacroHandler()
|
||||||
{
|
{
|
||||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||||
this, SLOT(changeEditor(Core::IEditor*)));
|
this, &FindMacroHandler::changeEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FindMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
bool FindMacroHandler::canExecuteEvent(const MacroEvent ¯oEvent)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public:
|
|||||||
bool canExecuteEvent(const MacroEvent ¯oEvent);
|
bool canExecuteEvent(const MacroEvent ¯oEvent);
|
||||||
bool executeEvent(const MacroEvent ¯oEvent);
|
bool executeEvent(const MacroEvent ¯oEvent);
|
||||||
|
|
||||||
public slots:
|
|
||||||
void findIncremental(const QString &txt, Core::FindFlags findFlags);
|
void findIncremental(const QString &txt, Core::FindFlags findFlags);
|
||||||
void findStep(const QString &txt, Core::FindFlags findFlags);
|
void findStep(const QString &txt, Core::FindFlags findFlags);
|
||||||
void replace(const QString &before, const QString &after, Core::FindFlags findFlags);
|
void replace(const QString &before, const QString &after, Core::FindFlags findFlags);
|
||||||
@@ -54,7 +53,7 @@ public slots:
|
|||||||
void replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags);
|
void replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags);
|
||||||
void resetIncrementalSearch();
|
void resetIncrementalSearch();
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void changeEditor(Core::IEditor *editor);
|
void changeEditor(Core::IEditor *editor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -102,8 +102,6 @@ public:
|
|||||||
|
|
||||||
QList<IMacroHandler*> handlers;
|
QList<IMacroHandler*> handlers;
|
||||||
|
|
||||||
QSignalMapper *mapper;
|
|
||||||
|
|
||||||
ActionMacroHandler *actionHandler;
|
ActionMacroHandler *actionHandler;
|
||||||
TextEditorMacroHandler *textEditorHandler;
|
TextEditorMacroHandler *textEditorHandler;
|
||||||
FindMacroHandler *findHandler;
|
FindMacroHandler *findHandler;
|
||||||
@@ -120,11 +118,8 @@ public:
|
|||||||
MacroManager::MacroManagerPrivate::MacroManagerPrivate(MacroManager *qq):
|
MacroManager::MacroManagerPrivate::MacroManagerPrivate(MacroManager *qq):
|
||||||
q(qq),
|
q(qq),
|
||||||
currentMacro(0),
|
currentMacro(0),
|
||||||
isRecording(false),
|
isRecording(false)
|
||||||
mapper(new QSignalMapper(qq))
|
|
||||||
{
|
{
|
||||||
connect(mapper, SIGNAL(mapped(QString)), q, SLOT(executeMacro(QString)));
|
|
||||||
|
|
||||||
// Load existing macros
|
// Load existing macros
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
@@ -164,8 +159,9 @@ void MacroManager::MacroManagerPrivate::addMacro(Macro *macro)
|
|||||||
Core::Command *command = Core::ActionManager::registerAction(
|
Core::Command *command = Core::ActionManager::registerAction(
|
||||||
action, makeId(macro->displayName()), context);
|
action, makeId(macro->displayName()), context);
|
||||||
command->setAttribute(Core::Command::CA_UpdateText);
|
command->setAttribute(Core::Command::CA_UpdateText);
|
||||||
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
|
connect(action, &QAction::triggered, q, [this, macro]() {
|
||||||
mapper->setMapping(action, macro->displayName());
|
q->executeMacro(macro->displayName());
|
||||||
|
});
|
||||||
|
|
||||||
// Add macro to the map
|
// Add macro to the map
|
||||||
macros[macro->displayName()] = macro;
|
macros[macro->displayName()] = macro;
|
||||||
|
|||||||
@@ -52,13 +52,14 @@ public:
|
|||||||
|
|
||||||
static QString macrosDirectory();
|
static QString macrosDirectory();
|
||||||
|
|
||||||
public slots:
|
|
||||||
void startMacro();
|
void startMacro();
|
||||||
void endMacro();
|
|
||||||
void executeLastMacro();
|
void executeLastMacro();
|
||||||
void saveLastMacro();
|
void saveLastMacro();
|
||||||
bool executeMacro(const QString &name);
|
bool executeMacro(const QString &name);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void endMacro();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Internal::MacroOptionsWidget;
|
friend class Internal::MacroOptionsWidget;
|
||||||
|
|
||||||
|
|||||||
@@ -52,14 +52,12 @@ public:
|
|||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void remove();
|
void remove();
|
||||||
void changeCurrentItem(QTreeWidgetItem *current);
|
void changeCurrentItem(QTreeWidgetItem *current);
|
||||||
|
|
||||||
private:
|
|
||||||
void createTable();
|
void createTable();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void changeDescription(const QString &description);
|
void changeDescription(const QString &description);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ static quint8 COUNT = 5;
|
|||||||
TextEditorMacroHandler::TextEditorMacroHandler():
|
TextEditorMacroHandler::TextEditorMacroHandler():
|
||||||
IMacroHandler()
|
IMacroHandler()
|
||||||
{
|
{
|
||||||
const QObject *editorManager = Core::EditorManager::instance();
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||||
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
connect(editorManager, &Core::EditorManager::currentEditorChanged,
|
||||||
this, SLOT(changeEditor(Core::IEditor*)));
|
this, &TextEditorMacroHandler::changeEditor);
|
||||||
connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)),
|
connect(editorManager, &Core::EditorManager::editorAboutToClose,
|
||||||
this, SLOT(closeEditor(Core::IEditor*)));
|
this, &TextEditorMacroHandler::closeEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorMacroHandler::startRecording(Macro *macro)
|
void TextEditorMacroHandler::startRecording(Macro *macro)
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ public:
|
|||||||
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
public slots:
|
|
||||||
void changeEditor(Core::IEditor *editor);
|
void changeEditor(Core::IEditor *editor);
|
||||||
void closeEditor(Core::IEditor *editor);
|
void closeEditor(Core::IEditor *editor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user