2010-12-20 10:35:30 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 Nicolas Arnaud-Cormos
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-20 11:10:30 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-12-20 10:35:30 +01:00
|
|
|
#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 <QSignalMapper>
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
using namespace Macros::Internal;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-23 14:33:43 +02:00
|
|
|
class MacroManager::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;
|
2010-12-20 10:35:30 +01:00
|
|
|
Macro *currentMacro;
|
|
|
|
|
bool isRecording;
|
|
|
|
|
|
|
|
|
|
QList<IMacroHandler*> handlers;
|
|
|
|
|
|
|
|
|
|
QSignalMapper *mapper;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MacroManager::MacroManagerPrivate::MacroManagerPrivate(MacroManager *qq):
|
|
|
|
|
q(qq),
|
|
|
|
|
currentMacro(0),
|
|
|
|
|
isRecording(false),
|
2011-01-24 11:39:42 +01:00
|
|
|
mapper(new QSignalMapper(qq))
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
connect(mapper, SIGNAL(mapped(QString)), q, SLOT(executeMacro(QString)));
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
void MacroManager::MacroManagerPrivate::initialize()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
macros.clear();
|
2011-02-07 11:34:02 +01:00
|
|
|
QDir dir(q->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;
|
2010-12-20 10:35:30 +01:00
|
|
|
Macro *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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 14:18:35 +01:00
|
|
|
static Core::Id makeId(const QString &name)
|
|
|
|
|
{
|
2013-08-23 14:33:43 +02:00
|
|
|
return Core::Id(Macros::Constants::PREFIX_MACRO).withSuffix(name);
|
2013-01-16 14:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
void MacroManager::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);
|
2014-02-28 17:33:48 +01:00
|
|
|
QAction *action = new QAction(macro->description(), q);
|
|
|
|
|
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());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::MacroManagerPrivate::removeMacro(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
delete macro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::MacroManagerPrivate::changeMacroDescription(Macro *macro, const QString &description)
|
|
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!macro->load())
|
|
|
|
|
return;
|
2010-12-20 10:35:30 +01:00
|
|
|
macro->setDescription(description);
|
2012-01-24 15:36:40 +01:00
|
|
|
macro->save(macro->fileName(), Core::ICore::mainWindow());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MacroManager::MacroManagerPrivate::executeMacro(Macro *macro)
|
|
|
|
|
{
|
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) {
|
2012-01-24 15:36:40 +01:00
|
|
|
QMessageBox::warning(Core::ICore::mainWindow(),
|
2011-02-07 11:34:00 +01:00
|
|
|
tr("Playing Macro"),
|
2011-04-19 15:42:14 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroManager::MacroManagerPrivate::showSaveDialog()
|
|
|
|
|
{
|
2012-07-19 15:31:22 +04:00
|
|
|
QWidget *mainWindow = Core::ICore::mainWindow();
|
2010-12-20 10:35:30 +01:00
|
|
|
SaveDialog dialog(mainWindow);
|
|
|
|
|
if (dialog.exec()) {
|
|
|
|
|
if (dialog.name().isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
// Save in the resource path
|
2012-11-26 20:55:11 +02:00
|
|
|
QString fileName = q->macrosDirectory() + QLatin1Char('/') + dialog.name()
|
|
|
|
|
+ QLatin1Char('.') + QLatin1String(Constants::M_EXTENSION);
|
2010-12-20 10:35:30 +01:00
|
|
|
currentMacro->setDescription(dialog.description());
|
2011-03-30 15:15:15 +02:00
|
|
|
currentMacro->save(fileName, mainWindow);
|
2010-12-20 10:35:30 +01:00
|
|
|
addMacro(currentMacro);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- MacroManager ------------
|
|
|
|
|
MacroManager *MacroManager::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
MacroManager::MacroManager(QObject *parent) :
|
|
|
|
|
QObject(parent),
|
|
|
|
|
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);
|
2013-08-29 15:46:04 +02:00
|
|
|
Core::EditorManager::showEditorStatusBar(
|
2010-12-20 10:35:30 +01:00
|
|
|
QLatin1String(Constants::M_STATUS_BUFFER),
|
|
|
|
|
help,
|
2011-02-07 11:34:00 +01:00
|
|
|
tr("Stop Recording Macro"), this, SLOT(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
|
|
|
{
|
|
|
|
|
if (d->currentMacro->events().count())
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
const QString &path =
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ICore::userResourcePath() + QLatin1String("/macros");
|
2011-02-07 11:34:02 +01:00
|
|
|
if (QFile::exists(path) || QDir().mkpath(path))
|
|
|
|
|
return path;
|
|
|
|
|
return QString();
|
|
|
|
|
}
|