forked from qt-creator/qt-creator
ProjectTree: Add an option to hide Source and Headers file groups
A new checkbox "Show Source and Header Groups" is added to the filter menu in the project tree. It is checked by default. Unchecking it removes the extra level of virtual folders containing sources and headers. Change-Id: I25f4514e7f1f6cdfcb531a911e54cc6e7e42a3e2 Fixes: QTCREATORBUG-25313 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -43,6 +43,8 @@ std::unique_ptr<FolderNode> createCMakeVFolder(const Utils::FilePath &basePath,
|
||||
auto newFolder = std::make_unique<VirtualFolderNode>(basePath);
|
||||
newFolder->setPriority(priority);
|
||||
newFolder->setDisplayName(displayName);
|
||||
newFolder->setIsSourcesOrHeaders(displayName == "Source Files"
|
||||
|| displayName == "Header Files");
|
||||
return newFolder;
|
||||
}
|
||||
|
||||
|
@@ -399,7 +399,14 @@ void FlatModel::addFolderNode(WrapperNode *parent, FolderNode *folderNode, QSet<
|
||||
if (m_filterDisabledFiles && !node->isEnabled())
|
||||
continue;
|
||||
if (FolderNode *subFolderNode = node->asFolderNode()) {
|
||||
const bool isHidden = m_filterProjects && !subFolderNode->showInSimpleTree();
|
||||
bool isHidden = m_filterProjects && !subFolderNode->showInSimpleTree();
|
||||
if (!m_showSourceGroups) {
|
||||
if (subFolderNode->isVirtualFolderType()) {
|
||||
auto vnode = static_cast<VirtualFolderNode *>(subFolderNode);
|
||||
if (vnode->isSourcesOrHeaders())
|
||||
isHidden = true;
|
||||
}
|
||||
}
|
||||
if (!isHidden && !seen->contains(subFolderNode)) {
|
||||
seen->insert(subFolderNode);
|
||||
auto node = new WrapperNode(subFolderNode);
|
||||
@@ -800,6 +807,14 @@ void FlatModel::setTrimEmptyDirectories(bool filter)
|
||||
rebuildModel();
|
||||
}
|
||||
|
||||
void FlatModel::setShowSourceGroups(bool filter)
|
||||
{
|
||||
if (filter == m_showSourceGroups)
|
||||
return;
|
||||
m_showSourceGroups = filter;
|
||||
rebuildModel();
|
||||
}
|
||||
|
||||
bool FlatModel::projectFilterEnabled()
|
||||
{
|
||||
return m_filterProjects;
|
||||
|
@@ -82,10 +82,12 @@ public:
|
||||
bool generatedFilesFilterEnabled();
|
||||
bool disabledFilesFilterEnabled() const { return m_filterDisabledFiles; }
|
||||
bool trimEmptyDirectoriesEnabled();
|
||||
bool showSourceGroups() { return m_showSourceGroups; }
|
||||
void setProjectFilterEnabled(bool filter);
|
||||
void setGeneratedFilesFilterEnabled(bool filter);
|
||||
void setDisabledFilesFilterEnabled(bool filter);
|
||||
void setTrimEmptyDirectories(bool filter);
|
||||
void setShowSourceGroups(bool filter);
|
||||
|
||||
void onExpanded(const QModelIndex &idx);
|
||||
void onCollapsed(const QModelIndex &idx);
|
||||
@@ -98,6 +100,7 @@ private:
|
||||
bool m_filterGeneratedFiles = true;
|
||||
bool m_filterDisabledFiles = false;
|
||||
bool m_trimEmptyDirectories = true;
|
||||
bool m_showSourceGroups = true;
|
||||
|
||||
static const QLoggingCategory &logger();
|
||||
|
||||
|
@@ -356,6 +356,12 @@ public:
|
||||
|
||||
bool isFolderNodeType() const override { return false; }
|
||||
bool isVirtualFolderType() const override { return true; }
|
||||
|
||||
bool isSourcesOrHeaders() const { return m_isSourcesOrHeaders; }
|
||||
void setIsSourcesOrHeaders(bool on) { m_isSourcesOrHeaders = on; }
|
||||
|
||||
private:
|
||||
bool m_isSourcesOrHeaders; // "Sources" or "Headers"
|
||||
};
|
||||
|
||||
// Documentation inside.
|
||||
|
@@ -273,6 +273,12 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) : QWidget(parent)
|
||||
connect(m_trimEmptyDirectoriesAction, &QAction::toggled,
|
||||
this, &ProjectTreeWidget::setTrimEmptyDirectories);
|
||||
|
||||
m_showSourceGroupsAction = new QAction(tr("Show Source and Header Groups"), this);
|
||||
m_showSourceGroupsAction->setCheckable(true);
|
||||
m_showSourceGroupsAction->setChecked(true);
|
||||
connect(m_showSourceGroupsAction, &QAction::toggled,
|
||||
this, &ProjectTreeWidget::setShowSourceGroups);
|
||||
|
||||
// connections
|
||||
connect(m_model, &FlatModel::renamed,
|
||||
this, &ProjectTreeWidget::renamed);
|
||||
@@ -442,6 +448,7 @@ QList<QToolButton *> ProjectTreeWidget::createToolButtons()
|
||||
filterMenu->addAction(m_filterGeneratedFilesAction);
|
||||
filterMenu->addAction(m_filterDisabledFilesAction);
|
||||
filterMenu->addAction(m_trimEmptyDirectoriesAction);
|
||||
filterMenu->addAction(m_showSourceGroupsAction);
|
||||
filter->setMenu(filterMenu);
|
||||
|
||||
auto toggleSync = new QToolButton;
|
||||
@@ -586,6 +593,12 @@ void ProjectTreeWidget::setTrimEmptyDirectories(bool filter)
|
||||
m_trimEmptyDirectoriesAction->setChecked(filter);
|
||||
}
|
||||
|
||||
void ProjectTreeWidget::setShowSourceGroups(bool filter)
|
||||
{
|
||||
m_model->setShowSourceGroups(filter);
|
||||
m_showSourceGroupsAction->setChecked(filter);
|
||||
}
|
||||
|
||||
bool ProjectTreeWidget::generatedFilesFilter()
|
||||
{
|
||||
return m_model->generatedFilesFilterEnabled();
|
||||
@@ -601,6 +614,11 @@ bool ProjectTreeWidget::trimEmptyDirectoriesFilter()
|
||||
return m_model->trimEmptyDirectoriesEnabled();
|
||||
}
|
||||
|
||||
bool ProjectTreeWidget::showSourceGroups()
|
||||
{
|
||||
return m_model->showSourceGroups();
|
||||
}
|
||||
|
||||
bool ProjectTreeWidget::projectFilter()
|
||||
{
|
||||
return m_model->projectFilterEnabled();
|
||||
@@ -625,6 +643,7 @@ const bool kProjectFilterDefault = false;
|
||||
const bool kHideGeneratedFilesDefault = true;
|
||||
const bool kHideDisabledFilesDefault = false;
|
||||
const bool kTrimEmptyDirsDefault = true;
|
||||
const bool kShowSourceGroupsDefault = true;
|
||||
const bool kSyncDefault = true;
|
||||
const char kBaseKey[] = "ProjectTreeWidget.";
|
||||
const char kProjectFilterKey[] = ".ProjectFilter";
|
||||
@@ -632,6 +651,7 @@ const char kHideGeneratedFilesKey[] = ".GeneratedFilter";
|
||||
const char kHideDisabledFilesKey[] = ".DisabledFilesFilter";
|
||||
const char kTrimEmptyDirsKey[] = ".TrimEmptyDirsFilter";
|
||||
const char kSyncKey[] = ".SyncWithEditor";
|
||||
const char kShowSourceGroupsKey[] = ".ShowSourceGroups";
|
||||
|
||||
void ProjectTreeWidgetFactory::saveSettings(QtcSettings *settings, int position, QWidget *widget)
|
||||
{
|
||||
@@ -650,6 +670,9 @@ void ProjectTreeWidgetFactory::saveSettings(QtcSettings *settings, int position,
|
||||
settings->setValueWithDefault(baseKey + kTrimEmptyDirsKey,
|
||||
ptw->trimEmptyDirectoriesFilter(),
|
||||
kTrimEmptyDirsDefault);
|
||||
settings->setValueWithDefault(baseKey + kShowSourceGroupsKey,
|
||||
ptw->showSourceGroups(),
|
||||
kShowSourceGroupsDefault);
|
||||
settings->setValueWithDefault(baseKey + kSyncKey, ptw->autoSynchronization(), kSyncDefault);
|
||||
}
|
||||
|
||||
@@ -666,5 +689,7 @@ void ProjectTreeWidgetFactory::restoreSettings(QSettings *settings, int position
|
||||
settings->value(baseKey + kHideDisabledFilesKey, kHideDisabledFilesDefault).toBool());
|
||||
ptw->setTrimEmptyDirectories(
|
||||
settings->value(baseKey + kTrimEmptyDirsKey, kTrimEmptyDirsDefault).toBool());
|
||||
ptw->setShowSourceGroups(
|
||||
settings->value(baseKey + kShowSourceGroupsKey, kShowSourceGroupsDefault).toBool());
|
||||
ptw->setAutoSynchronization(settings->value(baseKey + kSyncKey, kSyncDefault).toBool());
|
||||
}
|
||||
|
@@ -58,6 +58,7 @@ public:
|
||||
bool generatedFilesFilter();
|
||||
bool disabledFilesFilter();
|
||||
bool trimEmptyDirectoriesFilter();
|
||||
bool showSourceGroups();
|
||||
Node *currentNode();
|
||||
void sync(ProjectExplorer::Node *node);
|
||||
void showMessage(ProjectExplorer::Node *node, const QString &message);
|
||||
@@ -77,6 +78,7 @@ private:
|
||||
void setGeneratedFilesFilter(bool filter);
|
||||
void setDisabledFilesFilter(bool filter);
|
||||
void setTrimEmptyDirectories(bool filter);
|
||||
void setShowSourceGroups(bool filter);
|
||||
|
||||
void handleCurrentItemChange(const QModelIndex ¤t);
|
||||
void showContextMenu(const QPoint &pos);
|
||||
@@ -98,6 +100,7 @@ private:
|
||||
QAction *m_filterDisabledFilesAction = nullptr;
|
||||
QAction *m_trimEmptyDirectoriesAction = nullptr;
|
||||
QAction *m_toggleSync = nullptr;
|
||||
QAction *m_showSourceGroupsAction = nullptr;
|
||||
|
||||
QString m_modelId;
|
||||
bool m_autoSync = true;
|
||||
|
@@ -179,6 +179,7 @@ static void createTree(QmakeBuildSystem *buildSystem,
|
||||
vfolder->setIcon(fileTypes.at(i).icon);
|
||||
vfolder->setDisplayName(fileTypes.at(i).typeName);
|
||||
vfolder->setAddFileFilter(fileTypes.at(i).addFileFilter);
|
||||
vfolder->setIsSourcesOrHeaders(type == FileType::Source || type == FileType::Header);
|
||||
|
||||
if (type == FileType::Resource) {
|
||||
for (const auto &file : newFilePaths) {
|
||||
|
Reference in New Issue
Block a user