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