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 <utils/fileutils.h> 30 31 #include <QIcon> 32 #include <QWidget> 33 34 namespace Core { 35 class IContext; 36 class IEditor; 37 } 38 39 namespace Utils { 40 class NavigationTreeView; 41 class FileCrumbLabel; 42 class QtcSettings; 43 } 44 45 QT_BEGIN_NAMESPACE 46 class QAction; 47 class QComboBox; 48 class QFileSystemModel; 49 class QModelIndex; 50 class QSortFilterProxyModel; 51 QT_END_NAMESPACE 52 53 namespace ProjectExplorer { 54 namespace Internal { 55 56 class DelayedFileCrumbLabel; 57 58 class FolderNavigationWidgetFactory : public Core::INavigationWidgetFactory 59 { 60 Q_OBJECT 61 62 public: 63 struct RootDirectory { 64 QString id; 65 int sortValue; 66 QString displayName; 67 Utils::FilePath path; 68 QIcon icon; 69 }; 70 71 FolderNavigationWidgetFactory(); 72 73 Core::NavigationView createWidget() override; 74 void saveSettings(Utils::QtcSettings *settings, int position, QWidget *widget) override; 75 void restoreSettings(QSettings *settings, int position, QWidget *widget) override; 76 77 static void insertRootDirectory(const RootDirectory &directory); 78 static void removeRootDirectory(const QString &id); 79 80 signals: 81 void rootDirectoryAdded(const RootDirectory &directory); 82 void rootDirectoryRemoved(const QString &id); 83 84 private: 85 static int rootIndex(const QString &id); 86 void updateProjectsDirectoryRoot(); 87 void registerActions(); 88 89 static QVector<RootDirectory> m_rootDirectories; 90 }; 91 92 class FolderNavigationWidget : public QWidget 93 { 94 Q_OBJECT 95 Q_PROPERTY(bool autoSynchronization READ autoSynchronization WRITE setAutoSynchronization) 96 public: 97 explicit FolderNavigationWidget(QWidget *parent = nullptr); 98 99 static QStringList projectFilesInDirectory(const QString &path); 100 101 bool autoSynchronization() const; 102 bool hiddenFilesFilter() const; 103 bool isShowingBreadCrumbs() const; 104 bool isShowingFoldersOnTop() const; 105 106 void setAutoSynchronization(bool sync); 107 void toggleAutoSynchronization(); 108 void setShowBreadCrumbs(bool show); 109 void setShowFoldersOnTop(bool onTop); 110 111 void insertRootDirectory(const FolderNavigationWidgetFactory::RootDirectory &directory); 112 void removeRootDirectory(const QString &id); 113 114 void addNewItem(); 115 void editCurrentItem(); 116 void removeCurrentItem(); 117 118 protected: 119 void contextMenuEvent(QContextMenuEvent *ev) override; 120 121 private slots: 122 void setCrumblePath(const Utils::FilePath &filePath); 123 124 private: 125 bool rootAutoSynchronization() const; 126 void setRootAutoSynchronization(bool sync); 127 void setHiddenFilesFilter(bool filter); 128 void selectBestRootForFile(const Utils::FilePath &filePath); 129 void handleCurrentEditorChanged(Core::IEditor *editor); 130 void selectFile(const Utils::FilePath &filePath); 131 void setRootDirectory(const Utils::FilePath &directory); 132 int bestRootForFile(const Utils::FilePath &filePath); 133 void openItem(const QModelIndex &index); 134 QStringList projectsInDirectory(const QModelIndex &index) const; 135 void openProjectsInDirectory(const QModelIndex &index); 136 void createNewFolder(const QModelIndex &parent); 137 138 Utils::NavigationTreeView *m_listView = nullptr; 139 QFileSystemModel *m_fileSystemModel = nullptr; 140 QSortFilterProxyModel *m_sortProxyModel = nullptr; 141 QAction *m_filterHiddenFilesAction = nullptr; 142 QAction *m_showBreadCrumbsAction = nullptr; 143 QAction *m_showFoldersOnTopAction = nullptr; 144 bool m_autoSync = false; 145 bool m_rootAutoSync = true; 146 QToolButton *m_toggleSync = nullptr; 147 QToolButton *m_toggleRootSync = nullptr; 148 QComboBox *m_rootSelector = nullptr; 149 QWidget *m_crumbContainer = nullptr; 150 DelayedFileCrumbLabel *m_crumbLabel = nullptr; 151 152 // FolderNavigationWidgetFactory needs private members to build a menu 153 friend class FolderNavigationWidgetFactory; 154 }; 155 156 } // namespace Internal 157 } // namespace ProjectExplorer 158