Commit 7b7cf00d authored by Daniel Mensinger's avatar Daniel Mensinger Committed by Friedrich W. H. Kossebau

formater: Avoid code duplication for formatSource

parent 4527ac41
Pipeline #6801 failed with stage
in 60 minutes
......@@ -18,6 +18,9 @@
*/
#include "isourceformatter.h"
#include <interfaces/icore.h>
#include <interfaces/isourceformattercontroller.h>
#include <KLocalizedString>
#include <QVariant>
......@@ -163,6 +166,12 @@ void SourceFormatterStyle::copyDataFrom(SourceFormatterStyle *other)
m_overrideSample = other->overrideSample();
}
QString ISourceFormatter::formatSource(const QString& text, const QUrl &url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) const
{
auto style = ICore::self()->sourceFormatterController()->styleForUrl(url, mime);
return formatSourceWithStyle(style, text, url, mime, leftContext, rightContext);
}
QString ISourceFormatter::optionMapToString(const QMap<QString, QVariant> &map)
{
QString options;
......
......@@ -159,7 +159,7 @@ class KDEVPLATFORMINTERFACES_EXPORT ISourceFormatter
*
* If the source-formatter cannot work correctly with the context, it will just return the input text.
*/
virtual QString formatSource(const QString &text, const QUrl& url, const QMimeType &mime, const QString& leftContext = QString(), const QString& rightContext = QString()) const = 0;
virtual QString formatSource(const QString &text, const QUrl& url, const QMimeType &mime, const QString& leftContext = QString(), const QString& rightContext = QString()) const;
/**
* Format with the given style, this is mostly for the kcm to format the preview text
......
......@@ -24,9 +24,6 @@
#include <KPluginFactory>
#include <interfaces/icore.h>
#include <interfaces/isourceformattercontroller.h>
#include "astyle_formatter.h"
#include "astyle_stringiterator.h"
#include "astyle_preferences.h"
......@@ -262,14 +259,8 @@ QString AStylePlugin::formatSourceWithStyle( SourceFormatterStyle s, const QStri
{
m_formatter->loadStyle( s.content() );
}
return m_formatter->formatSource(text, leftContext, rightContext);
}
QString AStylePlugin::formatSource(const QString& text, const QUrl &url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) const
{
auto style = ICore::self()->sourceFormatterController()->styleForUrl(url, mime);
return formatSourceWithStyle(style, text, url, mime, leftContext, rightContext);
return m_formatter->formatSource(text, leftContext, rightContext);
}
static SourceFormatterStyle::MimeList supportedMimeTypes()
......@@ -355,7 +346,7 @@ AStylePlugin::Indentation AStylePlugin::indentation(const QUrl& url) const
Indentation ret;
ret.indentWidth = m_formatter->option(QStringLiteral("FillCount")).toInt();
QString s = m_formatter->option(QStringLiteral("Fill")).toString();
if(s == QLatin1String("Tabs"))
{
......@@ -365,7 +356,7 @@ AStylePlugin::Indentation AStylePlugin::indentation(const QUrl& url) const
// Don't use tabs at all
ret.indentationTabWidth = -1;
}
return ret;
}
......
......@@ -42,10 +42,6 @@ public:
QString caption() const override;
QString description() const override;
/** Formats using the current style.
*/
QString formatSource(const QString& text, const QUrl &url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) const override;
/** \return A map of predefined styles (a key and a caption for each type)
*/
QVector<KDevelop::SourceFormatterStyle> predefinedStyles() const override;
......
......@@ -203,12 +203,6 @@ QString CustomScriptPlugin::formatSourceWithStyle(SourceFormatterStyle style, co
return KDevelop::extractFormattedTextFromContext(output, text, leftContext, rightContext, tabWidth);
}
QString CustomScriptPlugin::formatSource(const QString& text, const QUrl& url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) const
{
auto style = KDevelop::ICore::self()->sourceFormatterController()->styleForUrl(url, mime);
return formatSourceWithStyle(style, text, url, mime, leftContext, rightContext);
}
static QVector<SourceFormatterStyle> stylesFromLanguagePlugins()
{
QVector<KDevelop::SourceFormatterStyle> styles;
......
......@@ -45,10 +45,6 @@ public:
QString caption() const override;
QString description() const override;
/** Formats using the current style.
*/
QString formatSource(const QString& text, const QUrl& url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) const override;
QString formatSourceWithStyle(KDevelop::SourceFormatterStyle, const QString& text,
const QUrl& url,
const QMimeType& mime,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment