1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include <coreplugin/inavigationwidgetfactory.h> 29 #include <coreplugin/opendocumentstreeview.h> 30 31 #include <QAbstractProxyModel> 32 #include <QCoreApplication> 33 34 namespace Core { 35 class IEditor; 36 37 namespace Internal { 38 39 class ProxyModel : public QAbstractProxyModel 40 { 41 public: 42 explicit ProxyModel(QObject *parent = nullptr); 43 QModelIndex mapFromSource(const QModelIndex & sourceIndex) const override; 44 QModelIndex mapToSource(const QModelIndex & proxyIndex) const override; 45 46 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 47 QModelIndex parent(const QModelIndex &child) const override; 48 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 49 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 50 51 void setSourceModel(QAbstractItemModel *sourceModel) override; 52 53 // QAbstractProxyModel::sibling is broken in Qt 5 54 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override; 55 // QAbstractProxyModel::supportedDragActions delegation is missing in Qt 5 56 Qt::DropActions supportedDragActions() const override; 57 58 private: 59 void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 60 void sourceRowsRemoved(const QModelIndex &parent, int start, int end); 61 void sourceRowsInserted(const QModelIndex &parent, int start, int end); 62 void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); 63 void sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end); 64 }; 65 66 class OpenEditorsWidget : public OpenDocumentsTreeView 67 { 68 Q_DECLARE_TR_FUNCTIONS(OpenEditorsWidget) 69 public: 70 OpenEditorsWidget(); 71 ~OpenEditorsWidget() override; 72 73 private: 74 void handleActivated(const QModelIndex &); 75 void updateCurrentItem(IEditor*); 76 void contextMenuRequested(QPoint pos); 77 void activateEditor(const QModelIndex &index); 78 void closeDocument(const QModelIndex &index); 79 80 ProxyModel *m_model; 81 }; 82 83 class OpenEditorsViewFactory : public INavigationWidgetFactory 84 { 85 public: 86 OpenEditorsViewFactory(); 87 88 NavigationView createWidget() override; 89 }; 90 91 } // namespace Internal 92 } // namespace Core 93