2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Nicolas Arnaud-Cormos
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
#include "macrosplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "macrosconstants.h"
|
|
|
|
|
#include "macromanager.h"
|
|
|
|
|
#include "macrooptionspage.h"
|
|
|
|
|
#include "macrolocatorfilter.h"
|
|
|
|
|
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QKeySequence>
|
|
|
|
|
#include <QMenu>
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
namespace Macros {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class MacrosPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MacroManager macroManager;
|
|
|
|
|
MacroOptionsPage optionsPage;
|
|
|
|
|
MacroLocatorFilter locatorFilter;
|
|
|
|
|
};
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
MacrosPlugin::~MacrosPlugin()
|
|
|
|
|
{
|
2019-03-20 18:51:16 +01:00
|
|
|
delete d;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
bool MacrosPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorMessage)
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
d = new MacrosPluginPrivate;
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
Core::Context textContext(TextEditor::Constants::C_TEXTEDITOR);
|
|
|
|
|
|
|
|
|
|
// Menus
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionContainer *mtools = Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
Core::ActionContainer *mmacrotools = Core::ActionManager::createMenu(Constants::M_TOOLS_MACRO);
|
2010-12-20 10:35:30 +01:00
|
|
|
QMenu *menu = mmacrotools->menu();
|
2015-03-17 08:05:50 +01:00
|
|
|
menu->setTitle(tr("Text Editing &Macros"));
|
2010-12-20 10:35:30 +01:00
|
|
|
menu->setEnabled(true);
|
|
|
|
|
mtools->addMenu(mmacrotools);
|
|
|
|
|
|
2011-02-07 11:34:00 +01:00
|
|
|
QAction *startMacro = new QAction(tr("Record Macro"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(startMacro, Constants::START_MACRO, textContext);
|
2018-11-09 13:44:17 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Ctrl+[") : tr("Alt+[")));
|
2010-12-20 10:35:30 +01:00
|
|
|
mmacrotools->addAction(command);
|
2019-03-20 18:51:16 +01:00
|
|
|
connect(startMacro, &QAction::triggered, &d->macroManager, &MacroManager::startMacro);
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2011-02-07 11:34:00 +01:00
|
|
|
QAction *endMacro = new QAction(tr("Stop Recording Macro"), this);
|
2010-12-20 10:35:30 +01:00
|
|
|
endMacro->setEnabled(false);
|
2015-02-19 11:35:47 +01:00
|
|
|
command = Core::ActionManager::registerAction(endMacro, Constants::END_MACRO);
|
2018-11-09 13:44:17 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Ctrl+]") : tr("Alt+]")));
|
2010-12-20 10:35:30 +01:00
|
|
|
mmacrotools->addAction(command);
|
2019-03-20 18:51:16 +01:00
|
|
|
connect(endMacro, &QAction::triggered, &d->macroManager, &MacroManager::endMacro);
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2011-02-07 11:34:00 +01:00
|
|
|
QAction *executeLastMacro = new QAction(tr("Play Last Macro"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(executeLastMacro, Constants::EXECUTE_LAST_MACRO, textContext);
|
2018-02-02 13:39:18 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+R") : tr("Alt+R")));
|
2010-12-20 10:35:30 +01:00
|
|
|
mmacrotools->addAction(command);
|
2019-03-20 18:51:16 +01:00
|
|
|
connect(executeLastMacro, &QAction::triggered, &d->macroManager, &MacroManager::executeLastMacro);
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2011-02-07 11:34:01 +01:00
|
|
|
QAction *saveLastMacro = new QAction(tr("Save Last Macro"), this);
|
|
|
|
|
saveLastMacro->setEnabled(false);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(saveLastMacro, Constants::SAVE_LAST_MACRO, textContext);
|
2011-02-07 11:34:01 +01:00
|
|
|
mmacrotools->addAction(command);
|
2019-03-20 18:51:16 +01:00
|
|
|
connect(saveLastMacro, &QAction::triggered, &d->macroManager, &MacroManager::saveLastMacro);
|
2011-02-07 11:34:01 +01:00
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Macros
|