diff options
| author | Eike Ziller <eike.ziller@qt.io> | 2022-05-09 14:55:18 +0200 |
|---|---|---|
| committer | Eike Ziller <eike.ziller@qt.io> | 2022-05-10 10:16:14 +0000 |
| commit | 08359cafde68103aa5f99e259633d30374e97f5a (patch) | |
| tree | 71faada32e5721ec14e418dd98b9132503007342 | |
| parent | e657bc8781113984e38d3fc6b72a555249f508c2 (diff) | |
| download | qt-creator-08359cafde68103aa5f99e259633d30374e97f5a.tar.gz | |
Warn when editing generated files
We already warn when editing a file that is not corresponding to a node
in the project and not under some project directory and not under some
project's version control.
Generated files are part of the project tree (not shown by default, if
"Hide Generated Files" is not turned off in the filter settings). So,
add another warning that the file is generated when editing a file that
is part of the project tree, but has the isGenerated flag set.
Task-number: QTCREATORBUG-27173
Change-Id: Id554d0e97bd5e033e957e7b3a863897845b7b654
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
| -rw-r--r-- | src/plugins/projectexplorer/projecttree.cpp | 42 | ||||
| -rw-r--r-- | src/plugins/projectexplorer/projecttree.h | 2 |
2 files changed, 31 insertions, 13 deletions
diff --git a/src/plugins/projectexplorer/projecttree.cpp b/src/plugins/projectexplorer/projecttree.cpp index ee040d5a37..7941ab5660 100644 --- a/src/plugins/projectexplorer/projecttree.cpp +++ b/src/plugins/projectexplorer/projecttree.cpp @@ -52,7 +52,9 @@ #include <QMenu> #include <QTimer> -namespace { const char EXTERNAL_FILE_WARNING[] = "ExternalFile"; } +namespace { +const char EXTERNAL_OR_GENERATED_FILE_WARNING[] = "ExternalOrGeneratedFile"; +} using namespace Utils; @@ -214,14 +216,20 @@ void ProjectTree::setCurrent(Node *node, Project *project) } if (Core::IDocument *document = Core::EditorManager::currentDocument()) { - if (node) { - disconnect(document, &Core::IDocument::changed, - this, &ProjectTree::updateExternalFileWarning); - document->infoBar()->removeInfo(EXTERNAL_FILE_WARNING); - } else { + if (!node) { connect(document, &Core::IDocument::changed, this, &ProjectTree::updateExternalFileWarning, Qt::UniqueConnection); + } else if (node->isGenerated()) { + connect(document, &Core::IDocument::changed, + this, &ProjectTree::updateGeneratedFileWarning, + Qt::UniqueConnection); + } else { + disconnect(document, &Core::IDocument::changed, + this, &ProjectTree::updateExternalFileWarning); + disconnect(document, &Core::IDocument::changed, + this, &ProjectTree::updateGeneratedFileWarning); + document->infoBar()->removeInfo(EXTERNAL_OR_GENERATED_FILE_WARNING); } } @@ -304,18 +312,18 @@ void ProjectTree::changeProjectRootDirectory() m_currentProject->changeRootProjectDirectory(); } -void ProjectTree::updateExternalFileWarning() +void ProjectTree::updateFileWarning(const QString &text) { auto document = qobject_cast<Core::IDocument *>(sender()); if (!document || document->filePath().isEmpty()) return; Utils::InfoBar *infoBar = document->infoBar(); - Utils::Id externalFileId(EXTERNAL_FILE_WARNING); + Utils::Id infoId(EXTERNAL_OR_GENERATED_FILE_WARNING); if (!document->isModified()) { - infoBar->removeInfo(externalFileId); + infoBar->removeInfo(infoId); return; } - if (!infoBar->canInfoBeAdded(externalFileId)) + if (!infoBar->canInfoBeAdded(infoId)) return; const FilePath fileName = document->filePath(); const QList<Project *> projects = SessionManager::projects(); @@ -335,9 +343,17 @@ void ProjectTree::updateExternalFileWarning() } } infoBar->addInfo( - Utils::InfoBarEntry(externalFileId, - tr("<b>Warning:</b> This file is outside the project directory."), - Utils::InfoBarEntry::GlobalSuppression::Enabled)); + Utils::InfoBarEntry(infoId, text, Utils::InfoBarEntry::GlobalSuppression::Enabled)); +} + +void ProjectTree::updateExternalFileWarning() +{ + updateFileWarning(tr("<b>Warning:</b> This file is outside the project directory.")); +} + +void ProjectTree::updateGeneratedFileWarning() +{ + updateFileWarning(tr("<b>Warning:</b> This file is generated.")); } bool ProjectTree::hasFocus(ProjectTreeWidget *widget) diff --git a/src/plugins/projectexplorer/projecttree.h b/src/plugins/projectexplorer/projecttree.h index 3947666d3a..c09d359156 100644 --- a/src/plugins/projectexplorer/projecttree.h +++ b/src/plugins/projectexplorer/projecttree.h @@ -132,7 +132,9 @@ private: void updateFromFocus(); + void updateFileWarning(const QString &text); void updateExternalFileWarning(); + void updateGeneratedFileWarning(); static bool hasFocus(Internal::ProjectTreeWidget *widget); Internal::ProjectTreeWidget *currentWidget() const; void hideContextMenu(); |
