File indexing completed on 2024-05-05 05:51:26
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2010 Thomas Fjellstrom <thomas@fjellstrom.ca> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QTimer> 0010 0011 #include <KTextEditor/Plugin> 0012 #include <ktexteditor/document.h> 0013 #include <ktexteditor/editor.h> 0014 #include <ktexteditor/mainwindow.h> 0015 #include <ktexteditor/sessionconfiginterface.h> 0016 0017 #include "katefiletreepluginsettings.h" 0018 0019 #include <KXMLGUIClient> 0020 0021 class QToolBar; 0022 0023 class KateFileTree; 0024 class KateFileTreeModel; 0025 class KateFileTreeProxyModel; 0026 class KateFileTreeConfigPage; 0027 class KateFileTreePluginView; 0028 0029 class QLineEdit; 0030 0031 class KateFileTreePlugin : public KTextEditor::Plugin 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 explicit KateFileTreePlugin(QObject *parent = nullptr, const QVariantList & = QVariantList()); 0037 ~KateFileTreePlugin() override; 0038 0039 QObject *createView(KTextEditor::MainWindow *mainWindow) override; 0040 0041 int configPages() const override; 0042 KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override; 0043 0044 const KateFileTreePluginSettings &settings(); 0045 0046 void applyConfig(bool shadingEnabled, 0047 const QColor &viewShade, 0048 const QColor &editShade, 0049 bool listMode, 0050 int sortRole, 0051 bool showFullPath, 0052 bool showToolbar, 0053 bool closeButton, 0054 bool middleClickToClose); 0055 0056 public Q_SLOTS: 0057 void viewDestroyed(QObject *view); 0058 0059 private: 0060 QList<KateFileTreePluginView *> m_views; 0061 KateFileTreePluginSettings m_settings; 0062 }; 0063 0064 class KateFileTreePluginView : public QObject, public KXMLGUIClient, public KTextEditor::SessionConfigInterface 0065 { 0066 Q_OBJECT 0067 0068 Q_INTERFACES(KTextEditor::SessionConfigInterface) 0069 0070 public: 0071 /** 0072 * Constructor. 0073 */ 0074 KateFileTreePluginView(KTextEditor::MainWindow *mainWindow, KateFileTreePlugin *plug); 0075 0076 /** 0077 * Virtual destructor. 0078 */ 0079 ~KateFileTreePluginView() override; 0080 0081 void readSessionConfig(const KConfigGroup &config) override; 0082 void writeSessionConfig(KConfigGroup &config) override; 0083 0084 /** 0085 * The file tree model. 0086 * @return the file tree model 0087 */ 0088 KateFileTreeModel *model() const; 0089 /** 0090 * The file tree proxy model. 0091 * @return the file tree proxy model 0092 */ 0093 KateFileTreeProxyModel *proxy() const; 0094 /** 0095 * The file tree. 0096 * @return the file tree 0097 */ 0098 KateFileTree *tree() const; 0099 0100 void setToolbarVisible(bool); 0101 void setListMode(bool listMode); 0102 0103 bool hasLocalPrefs() const; 0104 void setHasLocalPrefs(bool); 0105 0106 KTextEditor::MainWindow *mainWindow() const 0107 { 0108 return m_mainWindow; 0109 } 0110 0111 protected: 0112 void setupActions(); 0113 0114 private: 0115 QWidget *m_toolView; 0116 QToolBar *m_toolbar; 0117 KateFileTree *m_fileTree; 0118 KateFileTreeProxyModel *m_proxyModel; 0119 QLineEdit *m_filter; 0120 KateFileTreeModel *m_documentModel; 0121 bool m_hasLocalPrefs = false; 0122 KateFileTreePlugin *m_plug; 0123 KTextEditor::MainWindow *m_mainWindow; 0124 QTimer m_documentsCreatedTimer; 0125 QList<KTextEditor::Document *> m_documentsCreated; 0126 0127 private Q_SLOTS: 0128 void showToolView(); 0129 void hideToolView(); 0130 void showActiveDocument(); 0131 void activateDocument(KTextEditor::Document *); 0132 void viewChanged(KTextEditor::View * = nullptr); 0133 void documentOpened(KTextEditor::Document *); 0134 void documentClosed(KTextEditor::Document *); 0135 void viewModeChanged(bool); 0136 void sortRoleChanged(int); 0137 void slotDocumentsCreated(); 0138 void slotDocumentSave() const; 0139 void slotDocumentSaveAs() const; 0140 0141 void slotWidgetCreated(QWidget *); 0142 void slotWidgetRemoved(QWidget *); 0143 };