foldernavigationwidget.h 4.36 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

Tobias Hunger's avatar
Tobias Hunger committed
26
#pragma once
con's avatar
con committed
27 28

#include <coreplugin/inavigationwidgetfactory.h>
29
#include <utils/fileutils.h>
con's avatar
con committed
30

31
#include <QIcon>
32
#include <QWidget>
con's avatar
con committed
33

34 35 36 37
namespace Core {
class IContext;
class IEditor;
}
38

39 40
namespace Utils {
class NavigationTreeView;
41
class FileCrumbLabel;
42 43
}

44
QT_BEGIN_NAMESPACE
45
class QAction;
46 47 48
class QComboBox;
class QFileSystemModel;
class QModelIndex;
49 50
QT_END_NAMESPACE

con's avatar
con committed
51 52 53
namespace ProjectExplorer {
namespace Internal {

54 55
class DelayedFileCrumbLabel;

56 57 58 59 60 61 62
class FolderNavigationWidgetFactory : public Core::INavigationWidgetFactory
{
    Q_OBJECT

public:
    struct RootDirectory {
        QString id;
63
        int sortValue;
64 65
        QString displayName;
        Utils::FileName path;
66
        QIcon icon;
67 68 69 70 71 72 73 74
    };

    FolderNavigationWidgetFactory();

    Core::NavigationView createWidget() override;
    void saveSettings(QSettings *settings, int position, QWidget *widget) override;
    void restoreSettings(QSettings *settings, int position, QWidget *widget) override;

75
    static void insertRootDirectory(const RootDirectory &directory);
76 77 78 79 80 81 82
    static void removeRootDirectory(const QString &id);

signals:
    void rootDirectoryAdded(const RootDirectory &directory);
    void rootDirectoryRemoved(const QString &id);

private:
83 84
    static int rootIndex(const QString &id);
    void updateProjectsDirectoryRoot();
85 86
    void registerActions();

87 88 89
    static QVector<RootDirectory> m_rootDirectories;
};

hjk's avatar
hjk committed
90 91
class FolderNavigationWidget : public QWidget
{
con's avatar
con committed
92
    Q_OBJECT
93
    Q_PROPERTY(bool autoSynchronization READ autoSynchronization WRITE setAutoSynchronization)
con's avatar
con committed
94
public:
95
    explicit FolderNavigationWidget(QWidget *parent = nullptr);
96
    ~FolderNavigationWidget();
con's avatar
con committed
97

98 99
    static QStringList projectFilesInDirectory(const QString &path);

con's avatar
con committed
100
    bool autoSynchronization() const;
101 102
    bool hiddenFilesFilter() const;

103
    void setAutoSynchronization(bool sync);
con's avatar
con committed
104 105
    void toggleAutoSynchronization();

106
    void insertRootDirectory(const FolderNavigationWidgetFactory::RootDirectory &directory);
107
    void removeRootDirectory(const QString &id);
con's avatar
con committed
108

109
    void editCurrentItem();
110
    void removeCurrentItem();
111

112
protected:
Tobias Hunger's avatar
Tobias Hunger committed
113
    void contextMenuEvent(QContextMenuEvent *ev) override;
con's avatar
con committed
114

115
private:
116 117
    void setHiddenFilesFilter(bool filter);
    void setCurrentEditor(Core::IEditor *editor);
118
    void selectBestRootForFile(const Utils::FileName &filePath);
119 120 121 122
    void selectFile(const Utils::FileName &filePath);
    void setRootDirectory(const Utils::FileName &directory);
    int bestRootForFile(const Utils::FileName &filePath);
    void openItem(const QModelIndex &index);
123
    QStringList projectsInDirectory(const QModelIndex &index) const;
124
    void openProjectsInDirectory(const QModelIndex &index);
125
    void setCrumblePath(const QModelIndex &index, const QModelIndex &);
126

127
    Core::IContext *m_context = nullptr;
128 129 130
    Utils::NavigationTreeView *m_listView = nullptr;
    QFileSystemModel *m_fileSystemModel = nullptr;
    QAction *m_filterHiddenFilesAction = nullptr;
131
    bool m_autoSync = false;
132 133
    QToolButton *m_toggleSync = nullptr;
    QComboBox *m_rootSelector = nullptr;
134
    DelayedFileCrumbLabel *m_crumbLabel = nullptr;
135

136 137
    // FolderNavigationWidgetFactory needs private members to build a menu
    friend class FolderNavigationWidgetFactory;
con's avatar
con committed
138 139 140 141
};

} // namespace Internal
} // namespace ProjectExplorer