2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Nicolas Arnaud-Cormos
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-20 11:10:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
#include "macromanager.h"
|
|
|
|
|
|
|
|
|
|
#include "macrosconstants.h"
|
2011-01-24 12:29:48 +01:00
|
|
|
#include "macroevent.h"
|
2010-12-20 10:35:30 +01:00
|
|
|
#include "macro.h"
|
|
|
|
|
#include "imacrohandler.h"
|
|
|
|
|
#include "savedialog.h"
|
|
|
|
|
#include "actionmacrohandler.h"
|
|
|
|
|
#include "texteditormacrohandler.h"
|
|
|
|
|
#include "findmacrohandler.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>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2014-02-28 17:33:48 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QList>
|
2011-01-20 14:03:07 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QMessageBox>
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
namespace Macros {
|
|
|
|
|
namespace Internal {
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\namespace Macros
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The Macros namespace contains support for macros in \QC.
|
2010-12-20 10:35:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
|
|
\class Macro::MacroManager
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The MacroManager class implements a manager for macros.
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2013-09-06 17:23:10 +02:00
|
|
|
The MacroManager manages all macros, loads them on startup, keeps track of the
|
|
|
|
|
current macro, and creates new macros.
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
There are two important functions in this class that can be used outside the Macros plugin:
|
2010-12-20 10:35:30 +01:00
|
|
|
\list
|
2013-02-06 08:50:23 +01:00
|
|
|
\li registerEventHandler: add a new event handler
|
|
|
|
|
\li registerAction: add a macro event when this action is triggered
|
2010-12-20 10:35:30 +01:00
|
|
|
\endlist
|
|
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
This class is a singleton and can be accessed using the instance function.
|
2010-12-20 10:35:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void registerAction(QAction *action, const QString &id)
|
|
|
|
|
|
2013-09-06 17:23:10 +02:00
|
|
|
Appends \a action to the list of actions registered in a macro. \a id is
|
2010-12-20 10:35:30 +01:00
|
|
|
the action id passed to the ActionManager.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
class MacroManagerPrivate
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MacroManagerPrivate(MacroManager *qq);
|
|
|
|
|
|
|
|
|
|
MacroManager *q;
|
|
|
|
|
QMap<QString, Macro *> macros;
|
2014-02-28 17:33:48 +01:00
|
|
|
QMap<QString, QAction *> actions;
|
2017-02-27 15:47:47 +01:00
|
|
|
Macro *currentMacro = nullptr;
|
|
|
|
|
bool isRecording = false;
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
QList<IMacroHandler*> handlers;
|
|
|
|
|
|
|
|
|
|
ActionMacroHandler *actionHandler;
|
|
|
|
|
TextEditorMacroHandler *textEditorHandler;
|
|
|
|
|
FindMacroHandler *findHandler;
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
void initialize();
|
|
|
|
|
void addMacro(Macro *macro);
|
2010-12-20 10:35:30 +01:00
|
|
|
void removeMacro(const QString &name);
|
|
|
|
|
void changeMacroDescription(Macro *macro, const QString &description);
|
|
|
|
|
|
|
|
|
|
bool executeMacro(Macro *macro);
|
|
|
|
|
void showSaveDialog();
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
MacroManagerPrivate::MacroManagerPrivate(MacroManager *qq):
|
2017-02-27 15:47:47 +01:00
|
|
|
q(qq)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
// Load existing macros
|
|
|
|
|
initialize();
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
actionHandler = new ActionMacroHandler;
|
|
|
|
|
textEditorHandler = new TextEditorMacroHandler;
|
|
|
|
|
findHandler = new FindMacroHandler;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
void MacroManagerPrivate::initialize()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
macros.clear();
|
2020-11-18 22:42:51 +01:00
|
|
|
const QDir dir(MacroManager::macrosDirectory());
|
2010-12-20 10:35:30 +01:00
|
|
|
QStringList filter;
|
2012-11-26 20:55:11 +02:00
|
|
|
filter << QLatin1String("*.") + QLatin1String(Constants::M_EXTENSION);
|
2010-12-20 10:35:30 +01:00
|
|
|
QStringList files = dir.entryList(filter, QDir::Files);
|
|
|
|
|
|
|
|
|
|
foreach (const QString &name, files) {
|
2012-11-26 20:55:11 +02:00
|
|
|
QString fileName = dir.absolutePath() + QLatin1Char('/') + name;
|
2018-11-14 01:41:46 +01:00
|
|
|
auto macro = new Macro;
|
2011-03-30 15:15:15 +02:00
|
|
|
if (macro->loadHeader(fileName))
|
|
|
|
|
addMacro(macro);
|
|
|
|
|
else
|
|
|
|
|
delete macro;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
static Utils::Id makeId(const QString &name)
|
2013-01-16 14:18:35 +01:00
|
|
|
{
|
2020-06-26 13:59:38 +02:00
|
|
|
return Utils::Id(Macros::Constants::PREFIX_MACRO).withSuffix(name);
|
2013-01-16 14:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
void MacroManagerPrivate::addMacro(Macro *macro)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-01-24 11:39:42 +01:00
|
|
|
// Add sortcut
|
|
|
|
|
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
2018-11-14 01:41:46 +01:00
|
|
|
auto action = new QAction(macro->description(), q);
|
2014-02-28 17:33:48 +01:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(
|
|
|
|
|
action, makeId(macro->displayName()), context);
|
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2019-03-20 18:51:16 +01:00
|
|
|
QObject::connect(action, &QAction::triggered, q, [this, macro]() {
|
2016-05-29 00:20:16 +03:00
|
|
|
q->executeMacro(macro->displayName());
|
|
|
|
|
});
|
2011-01-24 11:39:42 +01:00
|
|
|
|
|
|
|
|
// Add macro to the map
|
2010-12-20 10:35:30 +01:00
|
|
|
macros[macro->displayName()] = macro;
|
2014-02-28 17:33:48 +01:00
|
|
|
actions[macro->displayName()] = action;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
void MacroManagerPrivate::removeMacro(const QString &name)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
if (!macros.contains(name))
|
|
|
|
|
return;
|
2011-01-24 11:39:42 +01:00
|
|
|
// Remove shortcut
|
2014-02-28 17:33:48 +01:00
|
|
|
QAction *action = actions.take(name);
|
|
|
|
|
Core::ActionManager::unregisterAction(action, makeId(name));
|
|
|
|
|
delete action;
|
2011-01-24 11:39:42 +01:00
|
|
|
|
|
|
|
|
// Remove macro from the map
|
2010-12-20 10:35:30 +01:00
|
|
|
Macro *macro = macros.take(name);
|
2016-09-26 08:16:48 +02:00
|
|
|
if (macro == currentMacro)
|
2017-02-27 15:47:47 +01:00
|
|
|
currentMacro = nullptr;
|
2010-12-20 10:35:30 +01:00
|
|
|
delete macro;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
void MacroManagerPrivate::changeMacroDescription(Macro *macro, const QString &description)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!macro->load())
|
|
|
|
|
return;
|
2010-12-20 10:35:30 +01:00
|
|
|
macro->setDescription(description);
|
2020-06-02 09:10:40 +02:00
|
|
|
macro->save(macro->fileName(), Core::ICore::dialogParent());
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2014-02-28 17:33:48 +01:00
|
|
|
QAction *action = actions[macro->displayName()];
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
action->setText(description);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
bool MacroManagerPrivate::executeMacro(Macro *macro)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
bool error = !macro->load();
|
2010-12-20 10:35:30 +01:00
|
|
|
foreach (const MacroEvent ¯oEvent, macro->events()) {
|
2011-03-30 15:15:15 +02:00
|
|
|
if (error)
|
|
|
|
|
break;
|
2010-12-20 10:35:30 +01:00
|
|
|
foreach (IMacroHandler *handler, handlers) {
|
|
|
|
|
if (handler->canExecuteEvent(macroEvent)) {
|
|
|
|
|
if (!handler->executeEvent(macroEvent))
|
|
|
|
|
error = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2020-06-02 09:10:40 +02:00
|
|
|
QMessageBox::warning(
|
|
|
|
|
Core::ICore::dialogParent(),
|
|
|
|
|
MacroManager::tr("Playing Macro"),
|
|
|
|
|
MacroManager::tr("An error occurred while replaying the macro, execution stopped."));
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the focus back to the editor
|
|
|
|
|
// TODO: is it really needed??
|
2012-05-08 09:43:14 +02:00
|
|
|
if (Core::IEditor *current = Core::EditorManager::currentEditor())
|
|
|
|
|
current->widget()->setFocus(Qt::OtherFocusReason);
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
return !error;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
void MacroManagerPrivate::showSaveDialog()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2020-06-02 09:10:40 +02:00
|
|
|
SaveDialog dialog(Core::ICore::dialogParent());
|
2010-12-20 10:35:30 +01:00
|
|
|
if (dialog.exec()) {
|
|
|
|
|
if (dialog.name().isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
// Save in the resource path
|
2020-11-18 22:42:51 +01:00
|
|
|
const QString fileName = MacroManager::macrosDirectory() + QLatin1Char('/') + dialog.name()
|
|
|
|
|
+ QLatin1Char('.') + QLatin1String(Constants::M_EXTENSION);
|
2010-12-20 10:35:30 +01:00
|
|
|
currentMacro->setDescription(dialog.description());
|
2020-06-02 09:10:40 +02:00
|
|
|
currentMacro->save(fileName, Core::ICore::dialogParent());
|
2010-12-20 10:35:30 +01:00
|
|
|
addMacro(currentMacro);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- MacroManager ------------
|
2019-03-20 18:51:16 +01:00
|
|
|
MacroManager *m_instance = nullptr;
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2019-03-20 18:51:16 +01:00
|
|
|
MacroManager::MacroManager() :
|
2010-12-20 10:35:30 +01:00
|
|
|
d(new MacroManagerPrivate(this))
|
|
|
|
|
{
|
2013-08-02 12:33:17 +02:00
|
|
|
m_instance = this;
|
2010-12-20 10:35:30 +01:00
|
|
|
registerMacroHandler(d->actionHandler);
|
|
|
|
|
registerMacroHandler(d->findHandler);
|
|
|
|
|
registerMacroHandler(d->textEditorHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MacroManager::~MacroManager()
|
|
|
|
|
{
|
|
|
|
|
// Cleanup macro
|
|
|
|
|
QStringList macroList = d->macros.keys();
|
|
|
|
|
foreach (const QString &name, macroList)
|
|
|
|
|
d->removeMacro(name);
|
|
|
|
|
|
|
|
|
|
// Cleanup handlers
|
|
|
|
|
qDeleteAll(d->handlers);
|
|
|
|
|
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::startMacro()
|
|
|
|
|
{
|
|
|
|
|
d->isRecording = true;
|
|
|
|
|
// Delete anonymous macro
|
|
|
|
|
if (d->currentMacro && d->currentMacro->displayName().isEmpty())
|
|
|
|
|
delete d->currentMacro;
|
|
|
|
|
d->currentMacro = new Macro;
|
|
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::command(Constants::START_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::END_MACRO)->action()->setEnabled(true);
|
|
|
|
|
Core::ActionManager::command(Constants::EXECUTE_LAST_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::SAVE_LAST_MACRO)->action()->setEnabled(false);
|
2010-12-20 10:35:30 +01:00
|
|
|
foreach (IMacroHandler *handler, d->handlers)
|
|
|
|
|
handler->startRecording(d->currentMacro);
|
|
|
|
|
|
2013-12-12 07:52:07 +02:00
|
|
|
QString endShortcut = Core::ActionManager::command(Constants::END_MACRO)->keySequence().toString();
|
|
|
|
|
QString executeShortcut = Core::ActionManager::command(Constants::EXECUTE_LAST_MACRO)->keySequence().toString();
|
2013-10-09 16:42:35 +02:00
|
|
|
QString help = tr("Macro mode. Type \"%1\" to stop recording and \"%2\" to play the macro.")
|
2010-12-20 10:35:30 +01:00
|
|
|
.arg(endShortcut).arg(executeShortcut);
|
2017-03-18 22:21:21 +02:00
|
|
|
Core::EditorManager::showEditorStatusBar(Constants::M_STATUS_BUFFER, help,
|
|
|
|
|
tr("Stop Recording Macro"),
|
|
|
|
|
this, [this] { endMacro(); });
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::endMacro()
|
|
|
|
|
{
|
2013-08-29 15:46:04 +02:00
|
|
|
Core::EditorManager::hideEditorStatusBar(QLatin1String(Constants::M_STATUS_BUFFER));
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::command(Constants::START_MACRO)->action()->setEnabled(true);
|
|
|
|
|
Core::ActionManager::command(Constants::END_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::EXECUTE_LAST_MACRO)->action()->setEnabled(true);
|
|
|
|
|
Core::ActionManager::command(Constants::SAVE_LAST_MACRO)->action()->setEnabled(true);
|
2010-12-20 10:35:30 +01:00
|
|
|
foreach (IMacroHandler *handler, d->handlers)
|
|
|
|
|
handler->endRecordingMacro(d->currentMacro);
|
|
|
|
|
|
|
|
|
|
d->isRecording = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::executeLastMacro()
|
|
|
|
|
{
|
2011-07-26 13:42:34 +02:00
|
|
|
if (!d->currentMacro)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// make sure the macro doesn't accidentally invoke a macro action
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::command(Constants::START_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::END_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::EXECUTE_LAST_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::SAVE_LAST_MACRO)->action()->setEnabled(false);
|
2011-07-26 13:42:34 +02:00
|
|
|
|
|
|
|
|
d->executeMacro(d->currentMacro);
|
|
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::command(Constants::START_MACRO)->action()->setEnabled(true);
|
|
|
|
|
Core::ActionManager::command(Constants::END_MACRO)->action()->setEnabled(false);
|
|
|
|
|
Core::ActionManager::command(Constants::EXECUTE_LAST_MACRO)->action()->setEnabled(true);
|
|
|
|
|
Core::ActionManager::command(Constants::SAVE_LAST_MACRO)->action()->setEnabled(true);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MacroManager::executeMacro(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
// Don't execute macro while recording
|
|
|
|
|
if (d->isRecording || !d->macros.contains(name))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Macro *macro = d->macros.value(name);
|
|
|
|
|
if (!d->executeMacro(macro))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Delete anonymous macro
|
|
|
|
|
if (d->currentMacro && d->currentMacro->displayName().isEmpty())
|
|
|
|
|
delete d->currentMacro;
|
|
|
|
|
d->currentMacro = macro;
|
2011-02-07 11:34:01 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::command(Constants::SAVE_LAST_MACRO)->action()->setEnabled(true);
|
2011-02-07 11:34:01 +01:00
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::deleteMacro(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
Macro *macro = d->macros.value(name);
|
|
|
|
|
if (macro) {
|
|
|
|
|
QString fileName = macro->fileName();
|
|
|
|
|
d->removeMacro(name);
|
|
|
|
|
QFile::remove(fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 12:33:17 +02:00
|
|
|
const QMap<QString,Macro*> &MacroManager::macros()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2013-08-02 12:33:17 +02:00
|
|
|
return m_instance->d->macros;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::registerMacroHandler(IMacroHandler *handler)
|
|
|
|
|
{
|
2013-08-02 12:33:17 +02:00
|
|
|
m_instance->d->handlers.prepend(handler);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MacroManager *MacroManager::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 11:39:42 +01:00
|
|
|
void MacroManager::changeMacro(const QString &name, const QString &description)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
if (!d->macros.contains(name))
|
|
|
|
|
return;
|
|
|
|
|
Macro *macro = d->macros.value(name);
|
|
|
|
|
|
|
|
|
|
// Change description
|
|
|
|
|
if (macro->description() != description)
|
|
|
|
|
d->changeMacroDescription(macro, description);
|
|
|
|
|
}
|
2011-02-07 11:34:01 +01:00
|
|
|
|
2013-08-23 14:33:43 +02:00
|
|
|
void MacroManager::saveLastMacro()
|
2011-02-07 11:34:01 +01:00
|
|
|
{
|
2020-01-15 19:10:34 +01:00
|
|
|
if (!d->currentMacro->events().isEmpty())
|
2011-02-07 11:34:01 +01:00
|
|
|
d->showSaveDialog();
|
|
|
|
|
}
|
2011-02-07 11:34:02 +01:00
|
|
|
|
2013-08-23 14:33:43 +02:00
|
|
|
QString MacroManager::macrosDirectory()
|
2011-02-07 11:34:02 +01:00
|
|
|
{
|
2021-04-22 16:15:26 +02:00
|
|
|
const QString path = Core::ICore::userResourcePath().pathAppended("macros").toString();
|
2011-02-07 11:34:02 +01:00
|
|
|
if (QFile::exists(path) || QDir().mkpath(path))
|
|
|
|
|
return path;
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
2019-03-20 18:51:16 +01:00
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Macros
|