ProjectManagers: Avoid deletion of special files

Do not allow deletion or rename of files that are used
to define or manage projects.
This fixes issues of being able to remove or rename
pri and pro files of qmake based projects as well as
special files used by the GenericProjectManager.

Change-Id: Ib173abf04368f0625a9e481bb7290aa11933e62f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2019-07-18 10:43:05 +02:00
parent 4c6c3de53b
commit 53ca9752e2
2 changed files with 7 additions and 15 deletions

View File

@@ -3264,20 +3264,21 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
m_addExistingFilesAction->setEnabled(supports(AddExistingFile));
m_addExistingDirectoryAction->setEnabled(supports(AddExistingDirectory));
m_renameFileAction->setEnabled(supports(Rename));
} else if (currentNode->asFileNode()) {
} else if (auto fileNode = currentNode->asFileNode()) {
// Enable and show remove / delete in magic ways:
// If both are disabled show Remove
// If both are enabled show both (can't happen atm)
// If only removeFile is enabled only show it
// If only deleteFile is enable only show it
bool enableRemove = supports(RemoveFile);
bool isTypeProject = fileNode->fileType() == FileType::Project;
bool enableRemove = !isTypeProject && supports(RemoveFile);
m_removeFileAction->setEnabled(enableRemove);
bool enableDelete = supports(EraseFile);
bool enableDelete = !isTypeProject && supports(EraseFile);
m_deleteFileAction->setEnabled(enableDelete);
m_deleteFileAction->setVisible(enableDelete);
m_removeFileAction->setVisible(!enableDelete || enableRemove);
m_renameFileAction->setEnabled(supports(Rename));
m_renameFileAction->setEnabled(!isTypeProject && supports(Rename));
const bool currentNodeIsTextFile = isTextFile(
currentNode->filePath().toString());
m_diffFileAction->setEnabled(DiffService::instance()

View File

@@ -217,17 +217,8 @@ static bool supportsNodeAction(ProjectAction action, const Node *node)
const QbsProject * const project = parentQbsProjectNode(node)->project();
if (!project->isProjectEditable())
return false;
auto equalsNodeFilePath = [node](const QString &str)
{
return str == node->filePath().toString();
};
if (action == RemoveFile || action == Rename) {
if (node->asFileNode())
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
}
if (action == RemoveFile || action == Rename)
return node->asFileNode();
return false;
}