CMakePM: Refactor display of CMakeLists.txt

All CMakeLists.txt from the Project view are marked as generated, except
the root one. This means that in normal case they will be hidden.

Every CMake Target (except Utility) will get a CMakeLists.txt:<number>
entry with the definition line of the target.

The CMake Folders will get an entry with the CMakeLists.txt which can be
accessed via context menu and "Open...".

The CMake Folder that only had a CMakeLists.txt will be removed when the
filter "Hide Empty Directories" is checked. This for example makes a
reduced plugin Qt Creator only display the enabled plugins, and not all
plugins!

With this change the "Simplify Tree" view will no longer have many
CMakeLists.txt entries, which makes the view more useful.

Fixes: QTCREATORBUG-31362
Change-Id: I708171e4b114100fae6fb592044a19fc36239261
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Cristian Adam
2024-08-08 11:22:10 +02:00
parent 7c28f17481
commit 6fd9a3c807
2 changed files with 16 additions and 4 deletions

View File

@@ -44,6 +44,8 @@ CMakeListsNode::CMakeListsNode(const FilePath &cmakeListPath) :
{ {
setIcon(DirectoryIcon(Constants::Icons::FILE_OVERLAY)); setIcon(DirectoryIcon(Constants::Icons::FILE_OVERLAY));
setListInProject(false); setListInProject(false);
setLocationInfo(
{{Constants::CMAKE_LISTS_TXT, cmakeListPath.pathAppended(Constants::CMAKE_LISTS_TXT)}});
} }
bool CMakeListsNode::showInSimpleTree() const bool CMakeListsNode::showInSimpleTree() const

View File

@@ -112,10 +112,12 @@ static CMakeFileResult extractCMakeFilesData(const QFuture<void> &cancelFuture,
} }
auto node = std::make_unique<FileNode>(info.path, FileType::Project); auto node = std::make_unique<FileNode>(info.path, FileType::Project);
node->setIsGenerated(info.isGenerated node->setIsGenerated(info.isGenerated);
&& !info.isCMakeListsDotTxt); // CMakeLists.txt are never
// generated, independent // We will have the CMakeLists.txt file in the Target nodes as a child node.
// what cmake thinks:-) // Except the root CMakeLists.txt file.
if (info.isCMakeListsDotTxt && info.path.parentDir() != sourceDirectory)
node->setIsGenerated(true);
if (info.isCMakeListsDotTxt) { if (info.isCMakeListsDotTxt) {
result.cmakeListNodes.emplace_back(std::move(node)); result.cmakeListNodes.emplace_back(std::move(node));
@@ -938,6 +940,14 @@ static void setupLocationInfoForTargets(const QFuture<void> &cancelFuture,
result += dedupMulti(t.installDefinitions); result += dedupMulti(t.installDefinitions);
folderNode->setLocationInfo(result); folderNode->setLocationInfo(result);
if (!t.backtrace.isEmpty() && t.targetType != TargetType::UtilityType) {
auto cmakeDefinition = std::make_unique<FileNode>(
t.backtrace.last().path, Node::fileTypeForFileName(t.backtrace.last().path));
cmakeDefinition->setLine(t.backtrace.last().line);
cmakeDefinition->setPriority(Node::DefaultProjectFilePriority);
folderNode->addNode(std::move(cmakeDefinition));
}
} }
} }
} }