forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -52,7 +52,9 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace { const char EXTERNAL_FILE_WARNING[] = "ExternalFile"; }
|
namespace {
|
||||||
|
const char EXTERNAL_OR_GENERATED_FILE_WARNING[] = "ExternalOrGeneratedFile";
|
||||||
|
}
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -214,14 +216,20 @@ void ProjectTree::setCurrent(Node *node, Project *project)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Core::IDocument *document = Core::EditorManager::currentDocument()) {
|
if (Core::IDocument *document = Core::EditorManager::currentDocument()) {
|
||||||
if (node) {
|
if (!node) {
|
||||||
disconnect(document, &Core::IDocument::changed,
|
|
||||||
this, &ProjectTree::updateExternalFileWarning);
|
|
||||||
document->infoBar()->removeInfo(EXTERNAL_FILE_WARNING);
|
|
||||||
} else {
|
|
||||||
connect(document, &Core::IDocument::changed,
|
connect(document, &Core::IDocument::changed,
|
||||||
this, &ProjectTree::updateExternalFileWarning,
|
this, &ProjectTree::updateExternalFileWarning,
|
||||||
Qt::UniqueConnection);
|
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();
|
m_currentProject->changeRootProjectDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTree::updateExternalFileWarning()
|
void ProjectTree::updateFileWarning(const QString &text)
|
||||||
{
|
{
|
||||||
auto document = qobject_cast<Core::IDocument *>(sender());
|
auto document = qobject_cast<Core::IDocument *>(sender());
|
||||||
if (!document || document->filePath().isEmpty())
|
if (!document || document->filePath().isEmpty())
|
||||||
return;
|
return;
|
||||||
Utils::InfoBar *infoBar = document->infoBar();
|
Utils::InfoBar *infoBar = document->infoBar();
|
||||||
Utils::Id externalFileId(EXTERNAL_FILE_WARNING);
|
Utils::Id infoId(EXTERNAL_OR_GENERATED_FILE_WARNING);
|
||||||
if (!document->isModified()) {
|
if (!document->isModified()) {
|
||||||
infoBar->removeInfo(externalFileId);
|
infoBar->removeInfo(infoId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!infoBar->canInfoBeAdded(externalFileId))
|
if (!infoBar->canInfoBeAdded(infoId))
|
||||||
return;
|
return;
|
||||||
const FilePath fileName = document->filePath();
|
const FilePath fileName = document->filePath();
|
||||||
const QList<Project *> projects = SessionManager::projects();
|
const QList<Project *> projects = SessionManager::projects();
|
||||||
@@ -335,9 +343,17 @@ void ProjectTree::updateExternalFileWarning()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
infoBar->addInfo(
|
infoBar->addInfo(
|
||||||
Utils::InfoBarEntry(externalFileId,
|
Utils::InfoBarEntry(infoId, text, Utils::InfoBarEntry::GlobalSuppression::Enabled));
|
||||||
tr("<b>Warning:</b> This file is outside the project directory."),
|
}
|
||||||
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)
|
bool ProjectTree::hasFocus(ProjectTreeWidget *widget)
|
||||||
|
@@ -132,7 +132,9 @@ private:
|
|||||||
|
|
||||||
void updateFromFocus();
|
void updateFromFocus();
|
||||||
|
|
||||||
|
void updateFileWarning(const QString &text);
|
||||||
void updateExternalFileWarning();
|
void updateExternalFileWarning();
|
||||||
|
void updateGeneratedFileWarning();
|
||||||
static bool hasFocus(Internal::ProjectTreeWidget *widget);
|
static bool hasFocus(Internal::ProjectTreeWidget *widget);
|
||||||
Internal::ProjectTreeWidget *currentWidget() const;
|
Internal::ProjectTreeWidget *currentWidget() const;
|
||||||
void hideContextMenu();
|
void hideContextMenu();
|
||||||
|
Reference in New Issue
Block a user