forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/13.0'
Change-Id: I0892d8e54930bb5a65dc51117b8ca7d70ce300a3
This commit is contained in:
@@ -749,14 +749,17 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
|
||||
&& func.Arguments().size() > 1 && func.Arguments().front().Value == target_name;
|
||||
});
|
||||
|
||||
for (const auto &func : {function, targetSourcesFunc, addQmlModuleFunc}) {
|
||||
auto setSourceFilePropFunc = findFunction(*cmakeListFile, [](const auto &func) {
|
||||
return func.LowerCaseName() == "set_source_files_properties";
|
||||
});
|
||||
|
||||
for (const auto &func : {function, targetSourcesFunc, addQmlModuleFunc, setSourceFilePropFunc}) {
|
||||
if (!func.has_value())
|
||||
continue;
|
||||
auto filePathArgument = Utils::findOrDefault(func->Arguments(),
|
||||
[file_name = fileName.toStdString()](
|
||||
const auto &arg) {
|
||||
return arg.Value == file_name;
|
||||
});
|
||||
auto filePathArgument = Utils::findOrDefault(
|
||||
func->Arguments(), [file_name = fileName.toStdString()](const auto &arg) {
|
||||
return arg.Value == file_name;
|
||||
});
|
||||
|
||||
if (!filePathArgument.Value.empty()) {
|
||||
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
||||
@@ -925,48 +928,59 @@ bool CMakeBuildSystem::renameFile(Node *context,
|
||||
{
|
||||
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
||||
const FilePath projDir = n->filePath().canonicalPath();
|
||||
const QString newRelPathName
|
||||
= newFilePath.canonicalPath().relativePathFrom(projDir).cleanPath().toString();
|
||||
const FilePath newRelPath = newFilePath.canonicalPath().relativePathFrom(projDir).cleanPath();
|
||||
const QString newRelPathName = newRelPath.toString();
|
||||
|
||||
// FilePath needs the file to exist on disk, the old file has already been renamed
|
||||
const QString oldRelPathName
|
||||
= newRelPath.parentDir().pathAppended(oldFilePath.fileName()).cleanPath().toString();
|
||||
|
||||
const QString targetName = n->buildKey();
|
||||
const QString key
|
||||
= QStringList{projDir.path(), targetName, oldFilePath.path(), newFilePath.path()}.join(
|
||||
";");
|
||||
|
||||
auto fileToRename = m_filesToBeRenamed.take(key);
|
||||
if (!fileToRename.cmakeFile.exists()) {
|
||||
std::optional<CMakeBuildSystem::ProjectFileArgumentPosition> fileToRename
|
||||
= m_filesToBeRenamed.take(key);
|
||||
if (!fileToRename->cmakeFile.exists()) {
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "File" << fileToRename.cmakeFile.path() << "does not exist.";
|
||||
<< "File" << fileToRename->cmakeFile.path() << "does not exist.";
|
||||
return false;
|
||||
}
|
||||
|
||||
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
||||
Core::EditorManager::openEditorAt({fileToRename.cmakeFile,
|
||||
static_cast<int>(fileToRename.argumentPosition.Line),
|
||||
static_cast<int>(fileToRename.argumentPosition.Column
|
||||
- 1)},
|
||||
Constants::CMAKE_EDITOR_ID,
|
||||
Core::EditorManager::DoNotMakeVisible));
|
||||
if (!editor) {
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "BaseTextEditor cannot be obtained for" << fileToRename.cmakeFile.path()
|
||||
<< fileToRename.argumentPosition.Line << int(fileToRename.argumentPosition.Column);
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
||||
Core::EditorManager::openEditorAt(
|
||||
{fileToRename->cmakeFile,
|
||||
static_cast<int>(fileToRename->argumentPosition.Line),
|
||||
static_cast<int>(fileToRename->argumentPosition.Column - 1)},
|
||||
Constants::CMAKE_EDITOR_ID,
|
||||
Core::EditorManager::DoNotMakeVisible));
|
||||
if (!editor) {
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "BaseTextEditor cannot be obtained for" << fileToRename->cmakeFile.path()
|
||||
<< fileToRename->argumentPosition.Line
|
||||
<< int(fileToRename->argumentPosition.Column);
|
||||
return false;
|
||||
}
|
||||
|
||||
// If quotes were used for the source file, skip the starting quote
|
||||
if (fileToRename.argumentPosition.Delim == cmListFileArgument::Quoted)
|
||||
editor->setCursorPosition(editor->position() + 1);
|
||||
// If quotes were used for the source file, skip the starting quote
|
||||
if (fileToRename->argumentPosition.Delim == cmListFileArgument::Quoted)
|
||||
editor->setCursorPosition(editor->position() + 1);
|
||||
|
||||
if (!fileToRename.fromGlobbing)
|
||||
editor->replace(fileToRename.relativeFileName.length(), newRelPathName);
|
||||
if (!fileToRename->fromGlobbing)
|
||||
editor->replace(fileToRename->relativeFileName.length(), newRelPathName);
|
||||
|
||||
editor->editorWidget()->autoIndent();
|
||||
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "Changes to" << fileToRename.cmakeFile.path() << "could not be saved.";
|
||||
return false;
|
||||
}
|
||||
editor->editorWidget()->autoIndent();
|
||||
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "Changes to" << fileToRename->cmakeFile.path() << "could not be saved.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try the next occurrence. This can happen if set_source_file_properties is used
|
||||
fileToRename = projectFileArgumentPosition(targetName, oldRelPathName);
|
||||
} while (fileToRename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ static FolderNode *createSourceGroupNode(const QString &sourceGroupName,
|
||||
FolderNode *existingNode = currentNode->findChildFolderNode(
|
||||
[&p](const FolderNode *fn) { return fn->displayName() == p; });
|
||||
if (!existingNode) {
|
||||
auto node = createCMakeVFolder(sourceDirectory, Node::DefaultFolderPriority + 5, p, true);
|
||||
auto node = createCMakeVFolder(sourceDirectory, Node::DefaultFolderPriority + 5, p);
|
||||
node->setListInProject(false);
|
||||
node->setIcon([] { return Icon::fromTheme("edit-copy"); });
|
||||
|
||||
@@ -654,7 +654,6 @@ static void addCompileGroups(ProjectNode *targetRoot,
|
||||
const FilePath &buildDirectory,
|
||||
const TargetDetails &td)
|
||||
{
|
||||
const bool showSourceFolders = settings().showSourceSubFolders();
|
||||
const bool inSourceBuild = (sourceDirectory == buildDirectory);
|
||||
|
||||
QSet<FilePath> alreadyListed;
|
||||
@@ -685,6 +684,9 @@ static void addCompileGroups(ProjectNode *targetRoot,
|
||||
if (isPchFile(buildDirectory, sourcePath) || isUnityFile(buildDirectory, sourcePath))
|
||||
node->setIsGenerated(true);
|
||||
|
||||
const bool showSourceFolders = settings().showSourceSubFolders()
|
||||
&& sourcesOrHeadersFolder(td.sourceGroups[si.sourceGroup]);
|
||||
|
||||
// Where does the file node need to go?
|
||||
if (showSourceFolders && sourcePath.isChildOf(buildDirectory) && !inSourceBuild) {
|
||||
buildFileNodes.emplace_back(std::move(node));
|
||||
@@ -696,6 +698,9 @@ static void addCompileGroups(ProjectNode *targetRoot,
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sourceGroupFileNodes.size(); ++i) {
|
||||
const bool showSourceFolders = settings().showSourceSubFolders()
|
||||
&& sourcesOrHeadersFolder(td.sourceGroups[i]);
|
||||
|
||||
std::vector<std::unique_ptr<FileNode>> ¤t = sourceGroupFileNodes[i];
|
||||
FolderNode *insertNode = td.sourceGroups[i] == "TREE"
|
||||
? targetRoot
|
||||
|
||||
@@ -18,15 +18,19 @@ using namespace ProjectExplorer;
|
||||
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
bool sourcesOrHeadersFolder(const QString &displayName)
|
||||
{
|
||||
return displayName == "Source Files" || displayName == "Header Files";
|
||||
}
|
||||
|
||||
std::unique_ptr<FolderNode> createCMakeVFolder(const Utils::FilePath &basePath,
|
||||
int priority,
|
||||
const QString &displayName,
|
||||
bool sourcesOrHeaders)
|
||||
const QString &displayName)
|
||||
{
|
||||
auto newFolder = std::make_unique<VirtualFolderNode>(basePath);
|
||||
newFolder->setPriority(priority);
|
||||
newFolder->setDisplayName(displayName);
|
||||
newFolder->setIsSourcesOrHeaders(sourcesOrHeaders);
|
||||
newFolder->setIsSourcesOrHeaders(sourcesOrHeadersFolder(displayName));
|
||||
return newFolder;
|
||||
}
|
||||
|
||||
@@ -35,14 +39,13 @@ void addCMakeVFolder(FolderNode *base,
|
||||
int priority,
|
||||
const QString &displayName,
|
||||
std::vector<std::unique_ptr<FileNode>> &&files,
|
||||
bool sourcesOrHeaders,
|
||||
bool listInProject)
|
||||
{
|
||||
if (files.size() == 0)
|
||||
return;
|
||||
FolderNode *folder = base;
|
||||
if (!displayName.isEmpty()) {
|
||||
auto newFolder = createCMakeVFolder(basePath, priority, displayName, sourcesOrHeaders);
|
||||
auto newFolder = createCMakeVFolder(basePath, priority, displayName);
|
||||
folder = newFolder.get();
|
||||
base->addNode(std::move(newFolder));
|
||||
}
|
||||
@@ -90,7 +93,6 @@ void addCMakeInputs(FolderNode *root,
|
||||
10,
|
||||
Tr::tr("<Other Locations>"),
|
||||
removeKnownNodes(knownFiles, std::move(rootInputs)),
|
||||
/*sourcesOrHeaders=*/false,
|
||||
/*listInProject=*/false);
|
||||
|
||||
root->addNode(std::move(cmakeVFolder));
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
bool sourcesOrHeadersFolder(const QString &displayName);
|
||||
|
||||
std::unique_ptr<ProjectExplorer::FolderNode> createCMakeVFolder(const Utils::FilePath &basePath,
|
||||
int priority,
|
||||
const QString &displayName,
|
||||
bool sourcesOrHeaders);
|
||||
const QString &displayName);
|
||||
|
||||
void addCMakeVFolder(ProjectExplorer::FolderNode *base,
|
||||
const Utils::FilePath &basePath,
|
||||
int priority,
|
||||
const QString &displayName,
|
||||
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&files,
|
||||
bool sourcesOrHeaders = false,
|
||||
bool listInProject = true);
|
||||
|
||||
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&removeKnownNodes(
|
||||
|
||||
Reference in New Issue
Block a user