1 | /* |
2 | SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H |
8 | #define KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H |
9 | |
10 | #include <QDialog> |
11 | #include <QHash> |
12 | #include <QList> |
13 | #include <QPointer> |
14 | #include <QString> |
15 | |
16 | class QListView; |
17 | class QLineEdit; |
18 | class QSortFilterProxyModel; |
19 | class VariableItemModel; |
20 | class TextEditButton; |
21 | |
22 | namespace KTextEditor |
23 | { |
24 | class View; |
25 | class Variable; |
26 | } |
27 | |
28 | /** |
29 | * Helper for macro expansion. |
30 | */ |
31 | namespace KateMacroExpander |
32 | { |
33 | /** |
34 | * Expands the @p input text based on the @p view. |
35 | * @return the expanded text. |
36 | */ |
37 | QString expandMacro(const QString &input, KTextEditor::View *view); |
38 | } |
39 | |
40 | /** |
41 | * Helper dialog that shows a non-modal dialog listing all available |
42 | * variables. If the user selects a variable, the variable is inserted |
43 | * into the respective widget. |
44 | */ |
45 | class KateVariableExpansionDialog : public QDialog |
46 | { |
47 | public: |
48 | KateVariableExpansionDialog(QWidget *parent); |
49 | ~KateVariableExpansionDialog() override; |
50 | |
51 | /** |
52 | * Adds @p variable to the expansion list view. |
53 | */ |
54 | void addVariable(const KTextEditor::Variable &variable); |
55 | |
56 | /** |
57 | * Returns true if no variables were added at all to the dialog. |
58 | */ |
59 | int isEmpty() const; |
60 | |
61 | /** |
62 | * Adds @p widget to the list of widgets that trigger showing this dialog. |
63 | */ |
64 | void addWidget(QWidget *widget); |
65 | |
66 | protected: |
67 | /** |
68 | * Reimplemented for the following reasons: |
69 | * - Show this dialog if one of the widgets added with addWidget() has focus. |
70 | * - Catch the resize-event for widgets (e.g. QTextEdit) where we manually |
71 | * added a clickable action in the corner |
72 | */ |
73 | bool eventFilter(QObject *watched, QEvent *event) override; |
74 | |
75 | /** |
76 | * Called whenever a widget was deleted. If all widgets are deleted, |
77 | * this dialog deletes itself via deleteLater(). |
78 | */ |
79 | void onObjectDeleted(QObject *object); |
80 | |
81 | private: |
82 | QAction *m_showAction; |
83 | QHash<QWidget *, QPointer<TextEditButton>> m_textEditButtons; |
84 | QList<QObject *> m_widgets; |
85 | QList<KTextEditor::Variable> m_variables; |
86 | VariableItemModel *m_variableModel; |
87 | QSortFilterProxyModel *m_filterModel; |
88 | QListView *m_listView; |
89 | QLineEdit *m_filterEdit; |
90 | }; |
91 | |
92 | #endif // KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H |
93 | |
94 | // kate: space-indent on; indent-width 4; replace-tabs on; |
95 | |