1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>
SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KDEVPLATFORM_ISOURCEFORMATTERCONTROLLER_H
#define KDEVPLATFORM_ISOURCEFORMATTERCONTROLLER_H
#include "interfacesexport.h"
#include <QObject>
#include <QString>
#include <memory>
class QUrl;
namespace KDevelop {
class IFileFormatter
{
Q_DISABLE_COPY_MOVE(IFileFormatter)
public:
IFileFormatter() = default;
virtual ~IFileFormatter() = default;
/**
* Format text using packaged source formatter and style.
* @param text the text to format
* @param leftContext the context at the left side of the text.
* If it is in another line, it must end with a newline.
* @param rightContext the context at the right side of the text.
* If it is in the next line, it must start with a newline.
*
* @note If the source formatter cannot work correctly with the context,
* it will just return the input text.
*/
virtual QString format(const QString& text, const QString& leftContext = QString(),
const QString& rightContext = QString()) const = 0;
};
/** \short An interface to the controller managing all source formatter plugins
*/
class KDEVPLATFORMINTERFACES_EXPORT ISourceFormatterController : public QObject
{
Q_OBJECT
public:
explicit ISourceFormatterController(QObject* parent = nullptr);
~ISourceFormatterController() override;
using FileFormatterPtr = std::unique_ptr<IFileFormatter>;
/**
* Read user configuration for the given URL and package it into a file formatter object.
* @param url the URL of a document to be formatted
* @return the requested file formatter object or nullptr if no formatter is
* configured for @p url
*/
virtual FileFormatterPtr fileFormatter(const QUrl& url) const = 0;
///\return @c true if there are formatters at all, @c false otherwise
virtual bool hasFormatters() const = 0;
/**
* Disable source formatting
* Once disabled, source formatting cannot be reenabled. Call this from within tests.
*/
virtual void disableSourceFormatting() = 0;
///\return Whether or not source formatting is enabled
virtual bool sourceFormattingEnabled() = 0;
Q_SIGNALS:
void hasFormattersChanged(bool hasFormatters);
};
}
#endif // KDEVPLATFORM_ISOURCEFORMATTERCONTROLLER_H
|