forked from qt-creator/qt-creator
Macros: Use ActionBuilder
Change-Id: Iea9d79e97b503122830e281c2997289ab5862803 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -8,9 +8,8 @@
|
|||||||
#include "macrostr.h"
|
#include "macrostr.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
|
|
||||||
@@ -18,10 +17,10 @@
|
|||||||
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
#include <QKeySequence>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
namespace Macros::Internal {
|
namespace Macros::Internal {
|
||||||
|
|
||||||
class MacrosPluginPrivate final
|
class MacrosPluginPrivate final
|
||||||
@@ -47,40 +46,44 @@ public:
|
|||||||
{
|
{
|
||||||
d = new MacrosPluginPrivate;
|
d = new MacrosPluginPrivate;
|
||||||
|
|
||||||
Core::Context textContext(TextEditor::Constants::C_TEXTEDITOR);
|
Context textContext(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
Core::ActionContainer *mtools = Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||||
Core::ActionContainer *mmacrotools = Core::ActionManager::createMenu(Constants::M_TOOLS_MACRO);
|
ActionContainer *mmacrotools = ActionManager::createMenu(Constants::M_TOOLS_MACRO);
|
||||||
QMenu *menu = mmacrotools->menu();
|
QMenu *menu = mmacrotools->menu();
|
||||||
menu->setTitle(Tr::tr("Text Editing &Macros"));
|
menu->setTitle(Tr::tr("Text Editing &Macros"));
|
||||||
menu->setEnabled(true);
|
menu->setEnabled(true);
|
||||||
mtools->addMenu(mmacrotools);
|
mtools->addMenu(mmacrotools);
|
||||||
|
|
||||||
QAction *startMacro = new QAction(Tr::tr("Record Macro"), this);
|
ActionBuilder startMacro(this, Constants::START_MACRO);
|
||||||
Core::Command *command = Core::ActionManager::registerAction(startMacro, Constants::START_MACRO, textContext);
|
startMacro.setText(Tr::tr("Record Macro"));
|
||||||
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? Tr::tr("Ctrl+[") : Tr::tr("Alt+[")));
|
startMacro.setContext(textContext);
|
||||||
mmacrotools->addAction(command);
|
startMacro.setDefaultKeySequence(Tr::tr("Ctrl+["), Tr::tr("Alt+["));
|
||||||
connect(startMacro, &QAction::triggered, &d->macroManager, &MacroManager::startMacro);
|
startMacro.setContainer(Constants::M_TOOLS_MACRO);
|
||||||
|
startMacro.setOnTriggered(this, [this] { d->macroManager.startMacro(); });
|
||||||
|
|
||||||
QAction *endMacro = new QAction(Tr::tr("Stop Recording Macro"), this);
|
ActionBuilder endMacro(this, Constants::END_MACRO);
|
||||||
endMacro->setEnabled(false);
|
endMacro.setText(Tr::tr("Stop Recording Macro"));
|
||||||
command = Core::ActionManager::registerAction(endMacro, Constants::END_MACRO);
|
endMacro.setContext(textContext);
|
||||||
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? Tr::tr("Ctrl+]") : Tr::tr("Alt+]")));
|
endMacro.setEnabled(false);
|
||||||
mmacrotools->addAction(command);
|
endMacro.setDefaultKeySequence(Tr::tr("Ctrl+]"), Tr::tr("Alt+]"));
|
||||||
connect(endMacro, &QAction::triggered, &d->macroManager, &MacroManager::endMacro);
|
endMacro.setContainer(Constants::M_TOOLS_MACRO);
|
||||||
|
endMacro.setOnTriggered(this, [this] { d->macroManager.endMacro(); });
|
||||||
|
|
||||||
QAction *executeLastMacro = new QAction(Tr::tr("Play Last Macro"), this);
|
ActionBuilder executeLastMacro(this, Constants::EXECUTE_LAST_MACRO);
|
||||||
command = Core::ActionManager::registerAction(executeLastMacro, Constants::EXECUTE_LAST_MACRO, textContext);
|
executeLastMacro.setText(Tr::tr("Play Last Macro"));
|
||||||
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+R") : Tr::tr("Alt+R")));
|
executeLastMacro.setContext(textContext);
|
||||||
mmacrotools->addAction(command);
|
executeLastMacro.setDefaultKeySequence(Tr::tr("Meta+R"), Tr::tr("Alt+R"));
|
||||||
connect(executeLastMacro, &QAction::triggered, &d->macroManager, &MacroManager::executeLastMacro);
|
executeLastMacro.setContainer(Constants::M_TOOLS_MACRO);
|
||||||
|
executeLastMacro.setOnTriggered(this, [this] { d->macroManager.executeLastMacro(); });
|
||||||
|
|
||||||
QAction *saveLastMacro = new QAction(Tr::tr("Save Last Macro"), this);
|
ActionBuilder saveLastMacro(this, Constants::SAVE_LAST_MACRO);
|
||||||
saveLastMacro->setEnabled(false);
|
saveLastMacro.setContext(textContext);
|
||||||
command = Core::ActionManager::registerAction(saveLastMacro, Constants::SAVE_LAST_MACRO, textContext);
|
saveLastMacro.setText(Tr::tr("Save Last Macro"));
|
||||||
mmacrotools->addAction(command);
|
saveLastMacro.setEnabled(false);
|
||||||
connect(saveLastMacro, &QAction::triggered, &d->macroManager, &MacroManager::saveLastMacro);
|
saveLastMacro.setContainer(Constants::M_TOOLS_MACRO);
|
||||||
|
saveLastMacro.setOnTriggered(this, [this] { d->macroManager.saveLastMacro(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user