Changeset View
Changeset View
Standalone View
Standalone View
formatters/customscript/customscript_plugin.h
Show All 24 Lines | |||||
25 | #include <interfaces/iplugin.h> | 25 | #include <interfaces/iplugin.h> | ||
26 | #include <interfaces/isourceformatter.h> | 26 | #include <interfaces/isourceformatter.h> | ||
27 | #include <QVBoxLayout> | 27 | #include <QVBoxLayout> | ||
28 | #include <QLabel> | 28 | #include <QLabel> | ||
29 | #include <QLineEdit> | 29 | #include <QLineEdit> | ||
30 | #include <QTimer> | 30 | #include <QTimer> | ||
31 | #include <QPushButton> | 31 | #include <QPushButton> | ||
32 | 32 | | |||
33 | class CustomScriptPlugin : public KDevelop::IPlugin, public KDevelop::ISourceFormatter | 33 | class CustomScriptPlugin | ||
34 | : public KDevelop::IPlugin | ||||
35 | , public KDevelop::ISourceFormatter | ||||
34 | { | 36 | { | ||
35 | Q_OBJECT | 37 | Q_OBJECT | ||
36 | Q_INTERFACES(KDevelop::ISourceFormatter) | 38 | Q_INTERFACES(KDevelop::ISourceFormatter) | ||
37 | | ||||
38 | public: | 39 | public: | ||
39 | explicit CustomScriptPlugin(QObject *parent, const QVariantList & = QVariantList()); | 40 | explicit CustomScriptPlugin(QObject* parent, const QVariantList& = QVariantList()); | ||
40 | ~CustomScriptPlugin() override; | 41 | ~CustomScriptPlugin() override; | ||
41 | 42 | | |||
42 | QString name() override; | 43 | QString name() override; | ||
43 | QString caption() override; | 44 | QString caption() override; | ||
44 | QString description() override; | 45 | QString description() override; | ||
45 | 46 | | |||
46 | /** Formats using the current style. | 47 | /** Formats using the current style. | ||
47 | */ | 48 | */ | ||
48 | QString formatSource(const QString &text, const QUrl &url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) override; | 49 | QString formatSource(const QString& text, const QUrl& url, const QMimeType& mime, const QString& leftContext, const QString& rightContext) override; | ||
49 | 50 | | |||
50 | QString formatSourceWithStyle(KDevelop::SourceFormatterStyle, const QString& text, | 51 | QString formatSourceWithStyle(KDevelop::SourceFormatterStyle, const QString& text, | ||
51 | const QUrl &url, | 52 | const QUrl& url, | ||
52 | const QMimeType& mime, | 53 | const QMimeType& mime, | ||
53 | const QString& leftContext = QString(), | 54 | const QString& leftContext = QString(), | ||
54 | const QString& rightContext = QString()) override; | 55 | const QString& rightContext = QString()) override; | ||
55 | 56 | | |||
56 | /** \return A map of predefined styles (a key and a caption for each type) | 57 | /** \return A map of predefined styles (a key and a caption for each type) | ||
57 | */ | 58 | */ | ||
58 | QList<KDevelop::SourceFormatterStyle> predefinedStyles() override; | 59 | QList<KDevelop::SourceFormatterStyle> predefinedStyles() override; | ||
59 | 60 | | |||
60 | /** \return The widget to edit a style. | 61 | /** \return The widget to edit a style. | ||
61 | */ | 62 | */ | ||
62 | KDevelop::SettingsWidget* editStyleWidget(const QMimeType& mime) override; | 63 | KDevelop::SettingsWidget* editStyleWidget(const QMimeType& mime) override; | ||
63 | 64 | | |||
64 | /** \return The text used in the config dialog to preview the current style. | 65 | /** \return The text used in the config dialog to preview the current style. | ||
65 | */ | 66 | */ | ||
66 | QString previewText(const KDevelop::SourceFormatterStyle& style, const QMimeType& mime) override; | 67 | QString previewText(const KDevelop::SourceFormatterStyle& style, const QMimeType& mime) override; | ||
67 | 68 | | |||
68 | /** \return The indentation of the currently selected style. | 69 | /** \return The indentation of the currently selected style. | ||
69 | */ | 70 | */ | ||
70 | Indentation indentation(const QUrl &url) override; | 71 | Indentation indentation(const QUrl& url) override; | ||
71 | | ||||
72 | private: | 72 | private: | ||
73 | QStringList computeIndentationFromSample(const QUrl &url); | 73 | QStringList computeIndentationFromSample(const QUrl& url); | ||
74 | 74 | | |||
75 | QStringList m_options; | 75 | QStringList m_options; | ||
76 | KDevelop::SourceFormatterStyle m_currentStyle; | 76 | KDevelop::SourceFormatterStyle m_currentStyle; | ||
77 | KDevelop::SourceFormatterStyle predefinedStyle(const QString& name); | 77 | KDevelop::SourceFormatterStyle predefinedStyle(const QString& name); | ||
78 | }; | 78 | }; | ||
79 | 79 | | |||
80 | class CustomScriptPreferences : public KDevelop::SettingsWidget { | 80 | class CustomScriptPreferences | ||
81 | : public KDevelop::SettingsWidget | ||||
82 | { | ||||
81 | Q_OBJECT | 83 | Q_OBJECT | ||
82 | public: | 84 | public: | ||
83 | CustomScriptPreferences() ; | 85 | CustomScriptPreferences(); | ||
84 | 86 | | |||
85 | void load ( const KDevelop::SourceFormatterStyle& style ) override ; | 87 | void load (const KDevelop::SourceFormatterStyle& style) override; | ||
86 | 88 | | |||
87 | QString save() override ; | 89 | QString save() override; | ||
88 | private: | 90 | private: | ||
89 | QVBoxLayout* m_vLayout; | 91 | QVBoxLayout* m_vLayout; | ||
90 | QLabel* m_captionLabel; | 92 | QLabel* m_captionLabel; | ||
91 | QHBoxLayout* m_hLayout; | 93 | QHBoxLayout* m_hLayout; | ||
92 | QLabel* m_commandLabel; | 94 | QLabel* m_commandLabel; | ||
93 | QLineEdit* m_commandEdit; | 95 | QLineEdit* m_commandEdit; | ||
94 | QLabel* m_bottomLabel; | 96 | QLabel* m_bottomLabel; | ||
95 | QTimer* m_updateTimer; | 97 | QTimer* m_updateTimer; | ||
96 | QPushButton* m_moreVariablesButton; | 98 | QPushButton* m_moreVariablesButton; | ||
97 | KDevelop::SourceFormatterStyle m_style; | 99 | KDevelop::SourceFormatterStyle m_style; | ||
98 | | ||||
99 | private slots: | 100 | private slots: | ||
100 | void textEdited ( QString ) { | 101 | void textEdited(QString) | ||
102 | { | ||||
101 | m_updateTimer->start(1000); | 103 | m_updateTimer->start(1000); | ||
102 | } | 104 | } | ||
103 | 105 | | |||
104 | void updateTimeout(); | 106 | void updateTimeout(); | ||
105 | void moreVariablesClicked ( bool ); | 107 | void moreVariablesClicked (bool); | ||
106 | }; | 108 | }; | ||
107 | 109 | | |||
108 | | ||||
109 | #endif // CUSTOMSCRIPTPLUGIN_H | 110 | #endif // CUSTOMSCRIPTPLUGIN_H | ||
110 | 111 | | |||
111 | // kate: indent-mode cstyle; space-indent off; tab-width 4; | 112 | // kate: indent-mode cstyle; space-indent off; tab-width 4; |