Macro: Inline SaveDialog

Not worth the file pair.

Also modernize MacroManager a bit.

Change-Id: I88f6add3147390e3900beebacc4a3f5255eac7ea
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-11-10 15:12:09 +01:00
parent 82c77b1304
commit d74a85bbac
6 changed files with 62 additions and 116 deletions

View File

@@ -14,6 +14,5 @@ add_qtc_plugin(Macros
macrosplugin.cpp macrosplugin.h macrosplugin.cpp macrosplugin.h
macrotextfind.cpp macrotextfind.h macrotextfind.cpp macrotextfind.h
macrostr.h macrostr.h
savedialog.cpp savedialog.h
texteditormacrohandler.cpp texteditormacrohandler.h texteditormacrohandler.cpp texteditormacrohandler.h
) )

View File

@@ -10,32 +10,34 @@
#include "macroevent.h" #include "macroevent.h"
#include "macrosconstants.h" #include "macrosconstants.h"
#include "macrostr.h" #include "macrostr.h"
#include "savedialog.h"
#include "texteditormacrohandler.h" #include "texteditormacrohandler.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <coreplugin/coreconstants.h> #include <utils/layoutbuilder.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>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QAction>
#include <QDialogButtonBox>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileInfo>
#include <QList>
#include <QAction>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo>
#include <QLineEdit>
#include <QList>
#include <QMessageBox> #include <QMessageBox>
#include <QRegularExpressionValidator>
namespace Macros { namespace Macros::Internal {
namespace Internal {
/*! /*!
\namespace Macros \namespace Macros
@@ -202,9 +204,47 @@ bool MacroManagerPrivate::executeMacro(Macro *macro)
return !error; return !error;
} }
class SaveDialog : public QDialog
{
public:
SaveDialog()
: QDialog(Core::ICore::dialogParent())
{
resize(219, 91);
setWindowTitle(Tr::tr("Save Macro"));
m_name = new QLineEdit;
m_name->setValidator(new QRegularExpressionValidator(QRegularExpression("\\w*"), this));
m_description = new QLineEdit;
auto buttonBox = new QDialogButtonBox;
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save);
using namespace Layouting;
Form {
Tr::tr("Name:"), m_name, br,
Tr::tr("Description:"), m_description, br,
buttonBox
}.attachTo(this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
QString name() const { return m_name->text(); }
QString description() const { return m_description->text(); }
private:
QLineEdit *m_name;
QLineEdit *m_description;
};
void MacroManagerPrivate::showSaveDialog() void MacroManagerPrivate::showSaveDialog()
{ {
SaveDialog dialog(Core::ICore::dialogParent()); SaveDialog dialog;
if (dialog.exec()) { if (dialog.exec()) {
if (dialog.name().isEmpty()) if (dialog.name().isEmpty())
return; return;
@@ -376,5 +416,4 @@ QString MacroManager::macrosDirectory()
return QString(); return QString();
} }
} // Internal } // Macros::Internal
} // Macros

View File

@@ -6,20 +6,17 @@
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
namespace Macros { namespace Macros::Internal {
namespace Internal {
class IMacroHandler; class IMacroHandler;
class Macro; class Macro;
class MacroOptionsWidget; class MacroOptionsWidget;
class MacroManager : public QObject class MacroManager final : public QObject
{ {
Q_OBJECT
public: public:
MacroManager(); MacroManager();
~MacroManager() override; ~MacroManager() final;
static MacroManager *instance(); static MacroManager *instance();
@@ -35,15 +32,13 @@ public:
bool executeMacro(const QString &name); bool executeMacro(const QString &name);
void endMacro(); void endMacro();
protected: private:
friend class Internal::MacroOptionsWidget; friend class Internal::MacroOptionsWidget;
void deleteMacro(const QString &name); void deleteMacro(const QString &name);
void changeMacro(const QString &name, const QString &description); void changeMacro(const QString &name, const QString &description);
private:
class MacroManagerPrivate *d; class MacroManagerPrivate *d;
}; };
} // namespace Internal } // namespace Macros::Internal
} // namespace Macros

View File

@@ -34,8 +34,6 @@ QtcPlugin {
"macrostr.h", "macrostr.h",
"macrotextfind.cpp", "macrotextfind.cpp",
"macrotextfind.h", "macrotextfind.h",
"savedialog.cpp",
"savedialog.h",
"texteditormacrohandler.cpp", "texteditormacrohandler.cpp",
"texteditormacrohandler.h", "texteditormacrohandler.h",
] ]

View File

@@ -1,55 +0,0 @@
// Copyright (C) 2016 Nicolas Arnaud-Cormos
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "savedialog.h"
#include "macrostr.h"
#include <utils/layoutbuilder.h>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <QRegularExpressionValidator>
namespace Macros::Internal {
SaveDialog::SaveDialog(QWidget *parent) :
QDialog(parent)
{
resize(219, 91);
setWindowTitle(Tr::tr("Save Macro"));
m_name = new QLineEdit;
m_name->setValidator(new QRegularExpressionValidator(QRegularExpression(QLatin1String("\\w*")), this));
m_description = new QLineEdit;
auto buttonBox = new QDialogButtonBox;
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save);
using namespace Layouting;
Form {
Tr::tr("Name:"), m_name, br,
Tr::tr("Description:"), m_description, br,
buttonBox
}.attachTo(this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
SaveDialog::~SaveDialog() = default;
QString SaveDialog::name() const
{
return m_name->text();
}
QString SaveDialog::description() const
{
return m_description->text();
}
} // Macros::Internal

View File

@@ -1,30 +0,0 @@
// Copyright (C) 2016 Nicolas Arnaud-Cormos
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <QDialog>
QT_BEGIN_NAMESPACE
class QLineEdit;
QT_END_NAMESPACE
namespace Macros::Internal {
class SaveDialog : public QDialog
{
Q_OBJECT
public:
explicit SaveDialog(QWidget *parent = nullptr);
~SaveDialog() override;
QString name() const;
QString description() const;
private:
QLineEdit *m_name;
QLineEdit *m_description;
};
} // Macros::Internal