File indexing completed on 2024-04-28 04:38:29

0001 /*
0002     SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr>
0003     SPDX-FileCopyrightText: 2011 David Nolden <david.nolden.kdevelop@art-master.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef CUSTOMSCRIPTPLUGIN_H
0009 #define CUSTOMSCRIPTPLUGIN_H
0010 
0011 #include <interfaces/iplugin.h>
0012 #include <interfaces/isourceformatter.h>
0013 #include <QVBoxLayout>
0014 #include <QLabel>
0015 #include <QLineEdit>
0016 #include <QPushButton>
0017 
0018 class QTimer;
0019 
0020 class CustomScriptPlugin
0021     : public KDevelop::IPlugin
0022     , public KDevelop::ISourceFormatter
0023 {
0024     Q_OBJECT
0025     Q_INTERFACES(KDevelop::ISourceFormatter)
0026 public:
0027     explicit CustomScriptPlugin(QObject* parent, const QVariantList& = QVariantList());
0028     ~CustomScriptPlugin() override;
0029 
0030     QString name() const override;
0031     QString caption() const override;
0032     QString description() const override;
0033     QString usageHint() const override;
0034 
0035     QString formatSourceWithStyle(const KDevelop::SourceFormatterStyle& style,
0036                                   const QString& text,
0037                                   const QUrl& url,
0038                                   const QMimeType& mime,
0039                                   const QString& leftContext = QString(),
0040                                   const QString& rightContext = QString()) const override;
0041 
0042     /** \return A map of predefined styles (a key and a caption for each type)
0043      */
0044     QVector<KDevelop::SourceFormatterStyle> predefinedStyles() const override;
0045 
0046     bool hasEditStyleWidget() const override;
0047 
0048     /** \return The widget to edit a style.
0049      */
0050     KDevelop::SettingsWidgetPtr editStyleWidget(const QMimeType& mime) const override;
0051 
0052     /** \return The text used in the config dialog to preview the current style.
0053      */
0054     QString previewText(const KDevelop::SourceFormatterStyle& style, const QMimeType& mime) const override;
0055 
0056     Indentation indentation(const KDevelop::SourceFormatterStyle& style, const QUrl& url,
0057                             const QMimeType& mime) const override;
0058 
0059 private:
0060     QStringList computeIndentationFromSample(const KDevelop::SourceFormatterStyle& style, const QUrl& url,
0061                                              const QMimeType& mime) const;
0062 };
0063 
0064 class CustomScriptPreferences
0065     : public KDevelop::SettingsWidget
0066 {
0067     Q_OBJECT
0068 public:
0069     CustomScriptPreferences();
0070 
0071     void load (const KDevelop::SourceFormatterStyle& style) override;
0072 
0073     QString save() const override;
0074 private:
0075     QVBoxLayout* m_vLayout;
0076     QLabel* m_captionLabel;
0077     QHBoxLayout* m_hLayout;
0078     QLabel* m_commandLabel;
0079     QLineEdit* m_commandEdit;
0080     QLabel* m_bottomLabel;
0081     QTimer* m_updateTimer;
0082     QPushButton* m_moreVariablesButton;
0083     KDevelop::SourceFormatterStyle m_style;
0084 
0085     void updateTimeout();
0086     void moreVariablesClicked (bool);
0087 };
0088 
0089 #endif // CUSTOMSCRIPTPLUGIN_H