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
|
SOURCES
|
||||||
artisticstyle/artisticstyle.cpp artisticstyle/artisticstyle.h
|
artisticstyle/artisticstyle.cpp artisticstyle/artisticstyle.h
|
||||||
beautifier.qrc
|
beautifier.qrc
|
||||||
beautifierabstracttool.h
|
|
||||||
beautifierconstants.h
|
beautifierconstants.h
|
||||||
beautifierplugin.cpp beautifierplugin.h
|
beautifierplugin.cpp beautifierplugin.h
|
||||||
beautifiertool.cpp beautifiertool.h
|
beautifiertool.cpp beautifiertool.h
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../beautifierabstracttool.h"
|
#include "../beautifiertool.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Beautifier::Internal {
|
namespace Beautifier::Internal {
|
||||||
|
|
||||||
class ArtisticStyle : public BeautifierAbstractTool
|
class ArtisticStyle : public BeautifierTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ArtisticStyle();
|
ArtisticStyle();
|
||||||
|
@@ -12,7 +12,6 @@ QtcPlugin {
|
|||||||
|
|
||||||
files: [
|
files: [
|
||||||
"beautifier.qrc",
|
"beautifier.qrc",
|
||||||
"beautifierabstracttool.h",
|
|
||||||
"beautifierconstants.h",
|
"beautifierconstants.h",
|
||||||
"beautifierplugin.cpp",
|
"beautifierplugin.cpp",
|
||||||
"beautifierplugin.h",
|
"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;
|
ClangFormat clangFormatBeautifier;
|
||||||
Uncrustify uncrustifyBeautifier;
|
Uncrustify uncrustifyBeautifier;
|
||||||
|
|
||||||
BeautifierAbstractTool *m_tools[3] {
|
BeautifierTool *m_tools[3] {
|
||||||
&artisticStyleBeautifier,
|
&artisticStyleBeautifier,
|
||||||
&uncrustifyBeautifier,
|
&uncrustifyBeautifier,
|
||||||
&clangFormatBeautifier
|
&clangFormatBeautifier
|
||||||
@@ -105,7 +105,7 @@ ExtensionSystem::IPlugin::ShutdownFlag BeautifierPlugin::aboutToShutdown()
|
|||||||
|
|
||||||
BeautifierPluginPrivate::BeautifierPluginPrivate()
|
BeautifierPluginPrivate::BeautifierPluginPrivate()
|
||||||
{
|
{
|
||||||
for (BeautifierAbstractTool *tool : m_tools)
|
for (BeautifierTool *tool : m_tools)
|
||||||
generalSettings.autoFormatTools.addOption(tool->id());
|
generalSettings.autoFormatTools.addOption(tool->id());
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
@@ -119,7 +119,7 @@ BeautifierPluginPrivate::BeautifierPluginPrivate()
|
|||||||
|
|
||||||
void BeautifierPluginPrivate::updateActions(Core::IEditor *editor)
|
void BeautifierPluginPrivate::updateActions(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
for (BeautifierAbstractTool *tool : m_tools)
|
for (BeautifierTool *tool : m_tools)
|
||||||
tool->updateActions(editor);
|
tool->updateActions(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ void BeautifierPluginPrivate::autoFormatOnSave(Core::IDocument *document)
|
|||||||
// Find tool to use by id and format file!
|
// Find tool to use by id and format file!
|
||||||
const QString id = generalSettings.autoFormatTools.stringValue();
|
const QString id = generalSettings.autoFormatTools.stringValue();
|
||||||
auto tool = std::find_if(std::begin(m_tools), std::end(m_tools),
|
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 != std::end(m_tools)) {
|
||||||
if (!(*tool)->isApplicable(document))
|
if (!(*tool)->isApplicable(document))
|
||||||
return;
|
return;
|
||||||
|
@@ -5,12 +5,15 @@
|
|||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
|
#include <texteditor/command.h>
|
||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -22,9 +25,30 @@ class QRegularExpression;
|
|||||||
class QVersionNumber;
|
class QVersionNumber;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class IDocument; }
|
namespace Core {
|
||||||
|
class IDocument;
|
||||||
|
class IEditor;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Beautifier::Internal {
|
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 VersionUpdater;
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../beautifierabstracttool.h"
|
#include "../beautifiertool.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Beautifier::Internal {
|
namespace Beautifier::Internal {
|
||||||
|
|
||||||
class ClangFormat : public BeautifierAbstractTool
|
class ClangFormat : public BeautifierTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClangFormat();
|
ClangFormat();
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../beautifierabstracttool.h"
|
#include "../beautifiertool.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
@@ -11,7 +11,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Beautifier::Internal {
|
namespace Beautifier::Internal {
|
||||||
|
|
||||||
class Uncrustify : public BeautifierAbstractTool
|
class Uncrustify : public BeautifierTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Uncrustify();
|
Uncrustify();
|
||||||
|
Reference in New Issue
Block a user