aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/projecttreewidget.h
blob: 535123da8bee915f41e2dc0608d187d3ebf8785e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#pragma once

#include <coreplugin/inavigationwidgetfactory.h>

#include <utils/filepath.h>

#include <QWidget>
#include <QModelIndex>

QT_FORWARD_DECLARE_CLASS(QTreeView)

namespace ProjectExplorer {

class Node;

namespace Internal {

class FlatModel;

class ProjectTreeWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ProjectTreeWidget(QWidget *parent = nullptr);
    ~ProjectTreeWidget() override;

    bool autoSynchronization() const;
    void setAutoSynchronization(bool sync);
    bool projectFilter();
    bool generatedFilesFilter();
    bool disabledFilesFilter();
    bool trimEmptyDirectoriesFilter();
    bool hideSourceGroups();
    Node *currentNode();
    void sync(ProjectExplorer::Node *node);
    void showMessage(ProjectExplorer::Node *node, const QString &message);

    static Node *nodeForFile(const Utils::FilePath &fileName);

    void toggleAutoSynchronization();
    void editCurrentItem();
    void expandCurrentNodeRecursively();
    void collapseAll();
    void expandAll();

    QList<QToolButton *> createToolButtons();

private:
    void setProjectFilter(bool filter);
    void setGeneratedFilesFilter(bool filter);
    void setDisabledFilesFilter(bool filter);
    void setTrimEmptyDirectories(bool filter);
    void setHideSourceGroups(bool filter);

    void handleCurrentItemChange(const QModelIndex &current);
    void showContextMenu(const QPoint &pos);
    void openItem(const QModelIndex &mainIndex);

    void setCurrentItem(ProjectExplorer::Node *node);
    static int expandedCount(Node *node);
    void rowsInserted(const QModelIndex &parent, int start, int end);
    void renamed(const Utils::FilePath &oldPath, const Utils::FilePath &newPath);

    void syncFromDocumentManager();

    void expandNodeRecursively(const QModelIndex &index);

    QTreeView *m_view = nullptr;
    FlatModel *m_model = nullptr;
    QAction *m_filterProjectsAction = nullptr;
    QAction *m_filterGeneratedFilesAction = nullptr;
    QAction *m_filterDisabledFilesAction = nullptr;
    QAction *m_trimEmptyDirectoriesAction = nullptr;
    QAction *m_toggleSync = nullptr;
    QAction *m_hideSourceGroupsAction = nullptr;

    QString m_modelId;
    bool m_autoSync = true;
    QList<Utils::FilePath> m_delayedRename;

    static QList<ProjectTreeWidget *> m_projectTreeWidgets;
    friend class ProjectTreeWidgetFactory;
};

class ProjectTreeWidgetFactory : public Core::INavigationWidgetFactory
{
    Q_OBJECT
public:
    ProjectTreeWidgetFactory();

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

} // namespace Internal
} // namespace ProjectExplorer