forked from qt-creator/qt-creator
Beautifier: Move functions from settings to tools [2/3]
Change-Id: Ie0773c99d9f2c814da124259c015d7d0fdc1b497 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -4,7 +4,6 @@ add_qtc_plugin(Beautifier
|
||||
SOURCES
|
||||
artisticstyle/artisticstyle.cpp artisticstyle/artisticstyle.h
|
||||
beautifier.qrc
|
||||
beautifierabstracttool.h
|
||||
beautifierconstants.h
|
||||
beautifierplugin.cpp beautifierplugin.h
|
||||
beautifiertool.cpp beautifiertool.h
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../beautifierabstracttool.h"
|
||||
#include "../beautifiertool.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class ArtisticStyle : public BeautifierAbstractTool
|
||||
class ArtisticStyle : public BeautifierTool
|
||||
{
|
||||
public:
|
||||
ArtisticStyle();
|
||||
|
@@ -12,7 +12,6 @@ QtcPlugin {
|
||||
|
||||
files: [
|
||||
"beautifier.qrc",
|
||||
"beautifierabstracttool.h",
|
||||
"beautifierconstants.h",
|
||||
"beautifierplugin.cpp",
|
||||
"beautifierplugin.h",
|
||||
|
@@ -1,35 +0,0 @@
|
||||
// Copyright (C) 2016 Lorenz Haas
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <texteditor/command.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Core {
|
||||
class IDocument;
|
||||
class IEditor;
|
||||
}
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class BeautifierAbstractTool : public QObject
|
||||
{
|
||||
public:
|
||||
BeautifierAbstractTool() = default;
|
||||
|
||||
virtual QString id() const = 0;
|
||||
virtual void updateActions(Core::IEditor *editor) = 0;
|
||||
|
||||
/**
|
||||
* Returns the tool's command to format an entire file.
|
||||
*
|
||||
* @note The received command may be invalid.
|
||||
*/
|
||||
virtual TextEditor::Command command() const = 0;
|
||||
|
||||
virtual bool isApplicable(const Core::IDocument *document) const = 0;
|
||||
};
|
||||
|
||||
} // Beautifier::Internal
|
@@ -74,7 +74,7 @@ public:
|
||||
ClangFormat clangFormatBeautifier;
|
||||
Uncrustify uncrustifyBeautifier;
|
||||
|
||||
BeautifierAbstractTool *m_tools[3] {
|
||||
BeautifierTool *m_tools[3] {
|
||||
&artisticStyleBeautifier,
|
||||
&uncrustifyBeautifier,
|
||||
&clangFormatBeautifier
|
||||
@@ -105,7 +105,7 @@ ExtensionSystem::IPlugin::ShutdownFlag BeautifierPlugin::aboutToShutdown()
|
||||
|
||||
BeautifierPluginPrivate::BeautifierPluginPrivate()
|
||||
{
|
||||
for (BeautifierAbstractTool *tool : m_tools)
|
||||
for (BeautifierTool *tool : m_tools)
|
||||
generalSettings.autoFormatTools.addOption(tool->id());
|
||||
|
||||
updateActions();
|
||||
@@ -119,7 +119,7 @@ BeautifierPluginPrivate::BeautifierPluginPrivate()
|
||||
|
||||
void BeautifierPluginPrivate::updateActions(Core::IEditor *editor)
|
||||
{
|
||||
for (BeautifierAbstractTool *tool : m_tools)
|
||||
for (BeautifierTool *tool : m_tools)
|
||||
tool->updateActions(editor);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ void BeautifierPluginPrivate::autoFormatOnSave(Core::IDocument *document)
|
||||
// Find tool to use by id and format file!
|
||||
const QString id = generalSettings.autoFormatTools.stringValue();
|
||||
auto tool = std::find_if(std::begin(m_tools), std::end(m_tools),
|
||||
[&id](const BeautifierAbstractTool *t){return t->id() == id;});
|
||||
[&id](const BeautifierTool *t){return t->id() == id;});
|
||||
if (tool != std::end(m_tools)) {
|
||||
if (!(*tool)->isApplicable(document))
|
||||
return;
|
||||
|
@@ -5,12 +5,15 @@
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <texteditor/command.h>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -22,10 +25,31 @@ class QRegularExpression;
|
||||
class QVersionNumber;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class IDocument; }
|
||||
namespace Core {
|
||||
class IDocument;
|
||||
class IEditor;
|
||||
}
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class BeautifierTool : public QObject
|
||||
{
|
||||
public:
|
||||
BeautifierTool() = default;
|
||||
|
||||
virtual QString id() const = 0;
|
||||
virtual void updateActions(Core::IEditor *editor) = 0;
|
||||
|
||||
/**
|
||||
* Returns the tool's command to format an entire file.
|
||||
*
|
||||
* @note The received command may be invalid.
|
||||
*/
|
||||
virtual TextEditor::Command command() const = 0;
|
||||
|
||||
virtual bool isApplicable(const Core::IDocument *document) const = 0;
|
||||
};
|
||||
|
||||
class VersionUpdater;
|
||||
|
||||
class AbstractSettings : public Utils::AspectContainer
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../beautifierabstracttool.h"
|
||||
#include "../beautifiertool.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class ClangFormat : public BeautifierAbstractTool
|
||||
class ClangFormat : public BeautifierTool
|
||||
{
|
||||
public:
|
||||
ClangFormat();
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../beautifierabstracttool.h"
|
||||
#include "../beautifiertool.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class Uncrustify : public BeautifierAbstractTool
|
||||
class Uncrustify : public BeautifierTool
|
||||
{
|
||||
public:
|
||||
Uncrustify();
|
||||
|
Reference in New Issue
Block a user