foldernavigationwidget.h 3.83 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
namespace Core { class IEditor; }
35

36 37 38 39
namespace Utils {
class NavigationTreeView;
}

40
QT_BEGIN_NAMESPACE
41
class QAction;
42 43 44
class QComboBox;
class QFileSystemModel;
class QModelIndex;
45 46
QT_END_NAMESPACE

con's avatar
con committed
47 48 49
namespace ProjectExplorer {
namespace Internal {

50 51 52 53 54 55 56
class FolderNavigationWidgetFactory : public Core::INavigationWidgetFactory
{
    Q_OBJECT

public:
    struct RootDirectory {
        QString id;
57
        int sortValue;
58 59
        QString displayName;
        Utils::FileName path;
60
        QIcon icon;
61 62 63 64 65 66 67 68
    };

    FolderNavigationWidgetFactory();

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

69
    static void insertRootDirectory(const RootDirectory &directory);
70 71 72 73 74 75 76
    static void removeRootDirectory(const QString &id);

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

private:
77 78
    static int rootIndex(const QString &id);
    void updateProjectsDirectoryRoot();
79 80 81
    static QVector<RootDirectory> m_rootDirectories;
};

hjk's avatar
hjk committed
82 83
class FolderNavigationWidget : public QWidget
{
con's avatar
con committed
84
    Q_OBJECT
85
    Q_PROPERTY(bool autoSynchronization READ autoSynchronization WRITE setAutoSynchronization)
con's avatar
con committed
86
public:
87
    explicit FolderNavigationWidget(QWidget *parent = nullptr);
con's avatar
con committed
88

89 90
    static QStringList projectFilesInDirectory(const QString &path);

con's avatar
con committed
91
    bool autoSynchronization() const;
92 93
    bool hiddenFilesFilter() const;

94
    void setAutoSynchronization(bool sync);
con's avatar
con committed
95 96
    void toggleAutoSynchronization();

97
    void insertRootDirectory(const FolderNavigationWidgetFactory::RootDirectory &directory);
98
    void removeRootDirectory(const QString &id);
con's avatar
con committed
99

100
protected:
Tobias Hunger's avatar
Tobias Hunger committed
101
    void contextMenuEvent(QContextMenuEvent *ev) override;
con's avatar
con committed
102

103
private:
104 105 106 107 108 109 110 111 112 113
    void setHiddenFilesFilter(bool filter);
    void setCurrentEditor(Core::IEditor *editor);
    void selectFile(const Utils::FileName &filePath);
    void setRootDirectory(const Utils::FileName &directory);
    int bestRootForFile(const Utils::FileName &filePath);
    void openItem(const QModelIndex &index);

    Utils::NavigationTreeView *m_listView = nullptr;
    QFileSystemModel *m_fileSystemModel = nullptr;
    QAction *m_filterHiddenFilesAction = nullptr;
114
    bool m_autoSync = false;
115 116
    QToolButton *m_toggleSync = nullptr;
    QComboBox *m_rootSelector = nullptr;
117

118 119
    // FolderNavigationWidgetFactory needs private members to build a menu
    friend class FolderNavigationWidgetFactory;
con's avatar
con committed
120 121 122 123
};

} // namespace Internal
} // namespace ProjectExplorer