forked from qt-creator/qt-creator
Project: Remove Project::document() method
The document is used to do file watching, which may or may not be ideal. So make sure we do not leak the information how we watch files into the API and its users. The method is not used sensibly anywhere in creator, so it seems safe to remove it entirely. Change-Id: Ieed755bd5c852875378e4e96665dc906499975b0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -285,9 +285,7 @@ ParserTreeItem::ConstPtr Parser::parse()
|
|||||||
for (const Project *prj : SessionManager::projects()) {
|
for (const Project *prj : SessionManager::projects()) {
|
||||||
ParserTreeItem::Ptr item;
|
ParserTreeItem::Ptr item;
|
||||||
QString prjName(prj->displayName());
|
QString prjName(prj->displayName());
|
||||||
QString prjType(prjName);
|
QString prjType = prj->projectFilePath().toString();
|
||||||
if (prj->document())
|
|
||||||
prjType = prj->projectFilePath().toString();
|
|
||||||
SymbolInformation inf(prjName, prjType);
|
SymbolInformation inf(prjName, prjType);
|
||||||
item = ParserTreeItem::Ptr(new ParserTreeItem());
|
item = ParserTreeItem::Ptr(new ParserTreeItem());
|
||||||
|
|
||||||
|
@@ -72,7 +72,7 @@ bool CurrentProjectFind::isEnabled() const
|
|||||||
QVariant CurrentProjectFind::additionalParameters() const
|
QVariant CurrentProjectFind::additionalParameters() const
|
||||||
{
|
{
|
||||||
Project *project = ProjectTree::currentProject();
|
Project *project = ProjectTree::currentProject();
|
||||||
if (project && project->document())
|
if (project)
|
||||||
return QVariant::fromValue(project->projectFilePath().toString());
|
return QVariant::fromValue(project->projectFilePath().toString());
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ Utils::FileIterator *CurrentProjectFind::files(const QStringList &nameFilters,
|
|||||||
return new Utils::FileListIterator(QStringList(), QList<QTextCodec *>()));
|
return new Utils::FileListIterator(QStringList(), QList<QTextCodec *>()));
|
||||||
QString projectFile = additionalParameters.toString();
|
QString projectFile = additionalParameters.toString();
|
||||||
for (Project *project : SessionManager::projects()) {
|
for (Project *project : SessionManager::projects()) {
|
||||||
if (project->document() && projectFile == project->projectFilePath().toString())
|
if (project && projectFile == project->projectFilePath().toString())
|
||||||
return filesForProjects(nameFilters, exclusionFilters, {project});
|
return filesForProjects(nameFilters, exclusionFilters, {project});
|
||||||
}
|
}
|
||||||
return new Utils::FileListIterator(QStringList(), QList<QTextCodec *>());
|
return new Utils::FileListIterator(QStringList(), QList<QTextCodec *>());
|
||||||
|
@@ -243,7 +243,7 @@ Core::Id Project::id() const
|
|||||||
|
|
||||||
QString Project::mimeType() const
|
QString Project::mimeType() const
|
||||||
{
|
{
|
||||||
return document()->mimeType();
|
return d->m_document->mimeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::canBuildProducts() const
|
bool Project::canBuildProducts() const
|
||||||
@@ -251,16 +251,10 @@ bool Project::canBuildProducts() const
|
|||||||
return d->m_canBuildProducts;
|
return d->m_canBuildProducts;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument *Project::document() const
|
|
||||||
{
|
|
||||||
QTC_CHECK(d->m_document);
|
|
||||||
return d->m_document.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils::FilePath Project::projectFilePath() const
|
Utils::FilePath Project::projectFilePath() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(document(), return Utils::FilePath());
|
QTC_ASSERT(d->m_document, return Utils::FilePath());
|
||||||
return document()->filePath();
|
return d->m_document->filePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::addTarget(std::unique_ptr<Target> &&t)
|
void Project::addTarget(std::unique_ptr<Target> &&t)
|
||||||
@@ -1074,10 +1068,6 @@ void ProjectExplorerPlugin::testProject_setup()
|
|||||||
|
|
||||||
QVERIFY(project.macroExpander());
|
QVERIFY(project.macroExpander());
|
||||||
|
|
||||||
QVERIFY(project.document());
|
|
||||||
QCOMPARE(project.document()->filePath(), TEST_PROJECT_PATH);
|
|
||||||
QCOMPARE(project.document()->mimeType(), TEST_PROJECT_MIMETYPE);
|
|
||||||
|
|
||||||
QCOMPARE(project.mimeType(), TEST_PROJECT_MIMETYPE);
|
QCOMPARE(project.mimeType(), TEST_PROJECT_MIMETYPE);
|
||||||
QCOMPARE(project.projectFilePath(), TEST_PROJECT_PATH);
|
QCOMPARE(project.projectFilePath(), TEST_PROJECT_PATH);
|
||||||
QCOMPARE(project.projectDirectory(), TEST_PROJECT_PATH.parentDir());
|
QCOMPARE(project.projectDirectory(), TEST_PROJECT_PATH.parentDir());
|
||||||
|
@@ -85,7 +85,6 @@ public:
|
|||||||
QString mimeType() const;
|
QString mimeType() const;
|
||||||
bool canBuildProducts() const;
|
bool canBuildProducts() const;
|
||||||
|
|
||||||
Core::IDocument *document() const;
|
|
||||||
Utils::FilePath projectFilePath() const;
|
Utils::FilePath projectFilePath() const;
|
||||||
Utils::FilePath projectDirectory() const;
|
Utils::FilePath projectDirectory() const;
|
||||||
static Utils::FilePath projectDirectory(const Utils::FilePath &top);
|
static Utils::FilePath projectDirectory(const Utils::FilePath &top);
|
||||||
|
@@ -1773,18 +1773,10 @@ void ProjectExplorerPlugin::unloadProject(Project *project)
|
|||||||
BuildManager::cancel();
|
BuildManager::cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
IDocument *document = project->document();
|
|
||||||
|
|
||||||
if (!document || document->filePath().isEmpty()) //nothing to save?
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!DocumentManager::saveModifiedDocumentSilently(document))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (projectExplorerSettings().closeSourceFilesWithProject && !dd->closeAllFilesInProject(project))
|
if (projectExplorerSettings().closeSourceFilesWithProject && !dd->closeAllFilesInProject(project))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dd->addToRecentProjects(document->filePath().toString(), project->displayName());
|
dd->addToRecentProjects(project->projectFilePath().toString(), project->displayName());
|
||||||
|
|
||||||
SessionManager::removeProject(project);
|
SessionManager::removeProject(project);
|
||||||
dd->updateActions();
|
dd->updateActions();
|
||||||
|
@@ -84,7 +84,7 @@ bool QmlProjectNode::renameFile(const QString & filePath, const QString & newFil
|
|||||||
m_project->setMainFile(newFilePath);
|
m_project->setMainFile(newFilePath);
|
||||||
|
|
||||||
// make sure to change it also in the qmlproject file
|
// make sure to change it also in the qmlproject file
|
||||||
const QString qmlProjectFilePath = m_project->document()->filePath().toString();
|
const QString qmlProjectFilePath = m_project->projectFilePath().toString();
|
||||||
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
||||||
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath);
|
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath);
|
||||||
TextEditor::TextDocument *document = nullptr;
|
TextEditor::TextDocument *document = nullptr;
|
||||||
|
@@ -1246,19 +1246,13 @@ static QTextCodec *findFileCodec(const QString &source)
|
|||||||
// Find the codec by checking the projects (root dir of project file)
|
// Find the codec by checking the projects (root dir of project file)
|
||||||
static QTextCodec *findProjectCodec(const QString &dir)
|
static QTextCodec *findProjectCodec(const QString &dir)
|
||||||
{
|
{
|
||||||
|
const FilePath dirPath = FilePath::fromString(dir);
|
||||||
typedef QList<ProjectExplorer::Project*> ProjectList;
|
typedef QList<ProjectExplorer::Project*> ProjectList;
|
||||||
// Try to find a project under which file tree the file is.
|
// Try to find a project under which file tree the file is.
|
||||||
const ProjectList projects = ProjectExplorer::SessionManager::projects();
|
const ProjectList projects = ProjectExplorer::SessionManager::projects();
|
||||||
if (!projects.empty()) {
|
const ProjectExplorer::Project *p
|
||||||
const ProjectList::const_iterator pcend = projects.constEnd();
|
= findOrDefault(projects, equal(&ProjectExplorer::Project::projectDirectory, dirPath));
|
||||||
for (ProjectList::const_iterator it = projects.constBegin(); it != pcend; ++it)
|
return p ? p->editorConfiguration()->textCodec() : nullptr;
|
||||||
if (const Core::IDocument *document = (*it)->document())
|
|
||||||
if (document->filePath().toString().startsWith(dir)) {
|
|
||||||
QTextCodec *codec = (*it)->editorConfiguration()->textCodec();
|
|
||||||
return codec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCodec *VcsBaseEditor::getCodec(const QString &source)
|
QTextCodec *VcsBaseEditor::getCodec(const QString &source)
|
||||||
|
Reference in New Issue
Block a user