File indexing completed on 2024-04-28 05:49:17
0001 /*************************************************************************** 0002 plugin_katesymbolviewer.h - description 0003 ------------------- 0004 begin : Apr 2 2003 0005 author : 2003 Massimo Callegari 0006 email : massimocallegari@yahoo.it 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * * 0013 ***************************************************************************/ 0014 0015 #pragma once 0016 0017 #include <KTextEditor/ConfigPage> 0018 #include <KTextEditor/MainWindow> 0019 #include <KTextEditor/Plugin> 0020 #include <KTextEditor/View> 0021 0022 #include <QCheckBox> 0023 #include <QMenu> 0024 0025 #include <QList> 0026 #include <QSet> 0027 #include <QTimer> 0028 #include <QTreeWidget> 0029 0030 #include <KLocalizedString> 0031 0032 enum class Symbol { Function, Class, Method }; 0033 0034 class KLineEdit; 0035 0036 /** 0037 * Plugin's config page 0038 */ 0039 class KatePluginSymbolViewerConfigPage : public KTextEditor::ConfigPage 0040 { 0041 Q_OBJECT 0042 0043 friend class KatePluginSymbolViewer; 0044 0045 public: 0046 explicit KatePluginSymbolViewerConfigPage(QObject *parent = nullptr, QWidget *parentWidget = nullptr); 0047 ~KatePluginSymbolViewerConfigPage() override; 0048 0049 /** 0050 * Reimplemented from KTextEditor::ConfigPage 0051 * just emits configPageApplyRequest( this ). 0052 */ 0053 QString name() const override; 0054 QString fullName() const override; 0055 QIcon icon() const override; 0056 0057 void apply() override; 0058 void reset() override 0059 { 0060 ; 0061 } 0062 void defaults() override 0063 { 0064 ; 0065 } 0066 0067 Q_SIGNALS: 0068 /** 0069 * Ask the plugin to set initial values 0070 */ 0071 void configPageApplyRequest(KatePluginSymbolViewerConfigPage *); 0072 0073 /** 0074 * Ask the plugin to apply changes 0075 */ 0076 void configPageInitRequest(KatePluginSymbolViewerConfigPage *); 0077 0078 private: 0079 QCheckBox *viewReturns; 0080 QCheckBox *expandTree; 0081 QCheckBox *treeView; 0082 QCheckBox *sortSymbols; 0083 }; 0084 0085 class KatePluginSymbolViewer; 0086 0087 class KatePluginSymbolViewerView : public QObject, public KXMLGUIClient 0088 { 0089 Q_OBJECT 0090 0091 friend class KatePluginSymbolViewer; 0092 0093 public: 0094 KatePluginSymbolViewerView(KatePluginSymbolViewer *plugin, KTextEditor::MainWindow *mw); 0095 ~KatePluginSymbolViewerView() override; 0096 0097 public Q_SLOTS: 0098 void displayOptionChanged(); 0099 void parseSymbols(); 0100 void slotDocChanged(); 0101 void goToSymbol(QTreeWidgetItem *); 0102 void slotShowContextMenu(const QPoint &); 0103 void cursorPositionChanged(); 0104 QTreeWidgetItem *newActveItem(int &currMinLine, int currLine, QTreeWidgetItem *item); 0105 void updateCurrTreeItem(); 0106 void slotDocEdited(); 0107 void slotFilterChange(const QString &); 0108 0109 protected: 0110 bool eventFilter(QObject *obj, QEvent *ev) override; 0111 0112 private: 0113 KTextEditor::MainWindow *m_mainWindow; 0114 KatePluginSymbolViewer *m_plugin; 0115 KLineEdit *m_filter; 0116 QMenu *m_popup; 0117 QWidget *m_toolview; 0118 QTreeWidget *m_symbols; 0119 QAction *m_treeOn; // FIXME Rename other actions accordingly 0120 QAction *m_sort; // m_sortOn etc 0121 QAction *m_macro; 0122 QAction *m_struct; 0123 QAction *m_func; 0124 QAction *m_typesOn; 0125 QAction *m_expandOn; 0126 0127 const QIcon m_icon_block = QIcon::fromTheme(QStringLiteral("code-block")); 0128 const QIcon m_icon_class = QIcon::fromTheme(QStringLiteral("code-class")); 0129 const QIcon m_icon_context = QIcon::fromTheme(QStringLiteral("code-context")); 0130 const QIcon m_icon_function = QIcon::fromTheme(QStringLiteral("code-function")); 0131 const QIcon m_icon_typedef = QIcon::fromTheme(QStringLiteral("code-typedef")); 0132 const QIcon m_icon_variable = QIcon::fromTheme(QStringLiteral("code-variable")); 0133 0134 QTimer m_updateTimer; 0135 QTimer m_currItemTimer; 0136 int m_oldCursorLine = 0; 0137 0138 void updatePixmapScroll(); 0139 0140 bool filterSymbols(QTreeWidgetItem *, const QString &); 0141 0142 void parseCppSymbols(void); 0143 void parseTclSymbols(void); 0144 void parseFortranSymbols(void); 0145 void parsePerlSymbols(void); 0146 void parsePythonSymbols(void); 0147 void parseRubySymbols(void); 0148 void parseXsltSymbols(void); 0149 void parseXMLSymbols(void); 0150 void parsePhpSymbols(void); 0151 void parseBashSymbols(void); 0152 void parseEcmaSymbols(void); 0153 void parseJuliaSymbols(void); 0154 }; 0155 0156 class KatePluginSymbolViewer : public KTextEditor::Plugin 0157 { 0158 friend class KatePluginSymbolViewerView; 0159 0160 Q_OBJECT 0161 public: 0162 explicit KatePluginSymbolViewer(QObject *parent = nullptr, const QVariantList & = QVariantList()); 0163 ~KatePluginSymbolViewer() override; 0164 0165 QObject *createView(KTextEditor::MainWindow *mainWindow) override; 0166 0167 int configPages() const override 0168 { 0169 return 1; 0170 } 0171 KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override; 0172 0173 public Q_SLOTS: 0174 void applyConfig(KatePluginSymbolViewerConfigPage *p); 0175 0176 private: 0177 QSet<KatePluginSymbolViewerView *> m_views; 0178 };