File indexing completed on 2024-05-05 05:51:25
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 <QIcon> 0010 #include <QTreeView> 0011 #include <QUrl> 0012 0013 namespace KTextEditor 0014 { 0015 class Document; 0016 class MainWindow; 0017 } 0018 0019 class QActionGroup; 0020 0021 class KateFileTreeModel; 0022 class KateFileTreeProxyModel; 0023 0024 class KateFileTree : public QTreeView 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 KateFileTree(KTextEditor::MainWindow *mainWindow, QWidget *parent); 0030 ~KateFileTree() override; 0031 0032 void setModel(QAbstractItemModel *model) override; 0033 void setShowCloseButton(bool show); 0034 void setMiddleClickToClose(bool value); 0035 0036 public Q_SLOTS: 0037 void slotDocumentClose(); 0038 void slotExpandRecursive(); 0039 void slotCollapseRecursive(); 0040 void slotDocumentCloseOther(); 0041 void slotDocumentReload(); 0042 void slotOpenContainingFolder(); 0043 void slotCopyFilename(); 0044 void slotCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous); 0045 void slotDocumentFirst(); 0046 void slotDocumentLast(); 0047 void slotDocumentNext(); 0048 void slotDocumentPrev(); 0049 void slotPrintDocument(); 0050 void slotPrintDocumentPreview(); 0051 void slotResetHistory(); 0052 void slotDocumentDelete(); 0053 0054 protected: 0055 void contextMenuEvent(QContextMenuEvent *event) override; 0056 bool eventFilter(QObject *o, QEvent *e) override; 0057 0058 Q_SIGNALS: 0059 void closeDocument(KTextEditor::Document *); 0060 void activateDocument(KTextEditor::Document *); 0061 0062 void openDocument(const QUrl &); 0063 0064 void viewModeChanged(bool treeMode); 0065 void sortRoleChanged(int); 0066 0067 void closeWidget(QWidget *); 0068 void activateWidget(QWidget *); 0069 0070 private Q_SLOTS: 0071 void mouseClicked(const QModelIndex &index); 0072 0073 void slotTreeMode(); 0074 void slotListMode(); 0075 0076 void slotSortName(); 0077 void slotSortPath(); 0078 void slotSortOpeningOrder(); 0079 void slotFixOpenWithMenu(QMenu *menu); 0080 void slotOpenWithMenuAction(QAction *a); 0081 0082 void slotRenameFile(); 0083 0084 void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); 0085 0086 private: 0087 void closeClicked(const QModelIndex &index); 0088 void setupContextMenuActionGroups(); 0089 using Func = void (KateFileTree::*)(); 0090 QAction *setupOption(QActionGroup *group, 0091 const QIcon &icon, 0092 const QString &text, 0093 const QString &whatisThis, 0094 const Func &slot, 0095 Qt::CheckState checked = Qt::Unchecked); 0096 0097 void addChildrenTolist(const QModelIndex &index, QList<QPersistentModelIndex> *worklist); 0098 0099 QAction *m_filelistCloseDocument; 0100 QAction *m_filelistExpandRecursive; 0101 QAction *m_filelistCollapseRecursive; 0102 QAction *m_filelistCloseOtherDocument; 0103 QAction *m_filelistReloadDocument; 0104 QAction *m_filelistOpenContainingFolder; 0105 QAction *m_filelistCopyFilename; 0106 QAction *m_filelistRenameFile; 0107 QAction *m_filelistPrintDocument; 0108 QAction *m_filelistPrintDocumentPreview; 0109 QAction *m_filelistDeleteDocument; 0110 0111 QAction *m_treeModeAction; 0112 QAction *m_listModeAction; 0113 0114 QAction *m_sortByFile; 0115 QAction *m_sortByPath; 0116 QAction *m_sortByOpeningOrder; 0117 QAction *m_customSorting; 0118 QAction *m_resetHistory; 0119 0120 KateFileTreeProxyModel *m_proxyModel = nullptr; 0121 KateFileTreeModel *m_sourceModel = nullptr; 0122 QPersistentModelIndex m_previouslySelected; 0123 QPersistentModelIndex m_indexContextMenu; 0124 0125 bool m_hasCloseButton = false; 0126 bool m_middleClickToClose = false; 0127 0128 KTextEditor::MainWindow *m_mainWindow; 0129 };