forked from qt-creator/qt-creator
ProjectManager: Centralize "File not found handling"
That's the only error that was ever checked for, in all nine project manager. In the hypothetical case that we'll need something else than the name of a file to identify a "project file", we'd probably need to touch the signature anyway. Until then, remove the duplication. Change-Id: Iba00b8f71309a908e2d29c0a58c50b685eca0cae Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -29,27 +29,13 @@
|
|||||||
#include "autotoolsproject.h"
|
#include "autotoolsproject.h"
|
||||||
#include "autotoolsprojectconstants.h"
|
#include "autotoolsprojectconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/idocument.h>
|
|
||||||
#include <coreplugin/messagemanager.h>
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
|
||||||
#include <projectexplorer/session.h>
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace AutotoolsProjectManager {
|
namespace AutotoolsProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
Project *AutotoolsManager::openProject(const QString &fileName, QString *errorString)
|
Project *AutotoolsManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file")
|
|
||||||
.arg(fileName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AutotoolsProject(fileName);
|
return new AutotoolsProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ class AutotoolsManager : public ProjectExplorer::IProjectManager
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -156,17 +156,9 @@ void CMakeManager::rescanProject(Project *project)
|
|||||||
cmakeProject->runCMake(); // by my experience: every rescan run requires cmake run too
|
cmakeProject->runCMake(); // by my experience: every rescan run requires cmake run too
|
||||||
}
|
}
|
||||||
|
|
||||||
Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
|
Project *CMakeManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
Utils::FileName file = Utils::FileName::fromString(fileName);
|
return new CMakeProject(Utils::FileName::fromString(fileName));
|
||||||
if (!file.toFileInfo().isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file")
|
|
||||||
.arg(file.toUserOutput());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CMakeProject(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CMakeManager::mimeType() const
|
QString CMakeManager::mimeType() const
|
||||||
|
@@ -42,7 +42,7 @@ class CMakeManager : public ProjectExplorer::IProjectManager
|
|||||||
public:
|
public:
|
||||||
CMakeManager();
|
CMakeManager();
|
||||||
|
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -27,13 +27,6 @@
|
|||||||
#include "genericprojectconstants.h"
|
#include "genericprojectconstants.h"
|
||||||
#include "genericproject.h"
|
#include "genericproject.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
#include <projectexplorer/session.h>
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace GenericProjectManager {
|
namespace GenericProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -42,15 +35,8 @@ QString Manager::mimeType() const
|
|||||||
return QLatin1String(Constants::GENERICMIMETYPE);
|
return QLatin1String(Constants::GENERICMIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
|
ProjectExplorer::Project *Manager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
|
|
||||||
.arg(fileName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GenericProject(fileName);
|
return new GenericProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ class Manager : public ProjectExplorer::IProjectManager
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual QString mimeType() const override;
|
virtual QString mimeType() const override;
|
||||||
virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
virtual ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
|
|
||||||
void registerProject(GenericProject *project);
|
void registerProject(GenericProject *project);
|
||||||
void unregisterProject(GenericProject *project);
|
void unregisterProject(GenericProject *project);
|
||||||
|
@@ -37,13 +37,8 @@ QString NimProjectManager::mimeType() const
|
|||||||
return QLatin1String(Constants::C_NIM_PROJECT_MIMETYPE);
|
return QLatin1String(Constants::C_NIM_PROJECT_MIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Project *NimProjectManager::openProject(const QString &fileName, QString *errorString)
|
Project *NimProjectManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file.").arg(fileName);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new NimProject(fileName);
|
return new NimProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ class NimProjectManager : public ProjectExplorer::IProjectManager
|
|||||||
public:
|
public:
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
|
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -39,8 +39,8 @@ class PROJECTEXPLORER_EXPORT IProjectManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual QString mimeType() const = 0;
|
virtual QString mimeType() const = 0;
|
||||||
// fileName is a canonical path!
|
// FileName is a canonical path of a checked-to-exist file.
|
||||||
virtual Project *openProject(const QString &fileName, QString *errorString) = 0;
|
virtual Project *openProject(const QString &fileName) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -109,7 +109,6 @@ void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
|
|||||||
|
|
||||||
foreach (const JsonWizard::GeneratorFile &f, files) {
|
foreach (const JsonWizard::GeneratorFile &f, files) {
|
||||||
if (f.file.attributes() & GeneratedFile::OpenProjectAttribute) {
|
if (f.file.attributes() & GeneratedFile::OpenProjectAttribute) {
|
||||||
QString errorMessage;
|
|
||||||
const QFileInfo fi(f.file.path());
|
const QFileInfo fi(f.file.path());
|
||||||
const QString path = fi.absoluteFilePath();
|
const QString path = fi.absoluteFilePath();
|
||||||
|
|
||||||
@@ -119,7 +118,7 @@ void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto manager = Utils::findOrDefault(managerList, Utils::equal(&IProjectManager::mimeType, mt.name()));
|
auto manager = Utils::findOrDefault(managerList, Utils::equal(&IProjectManager::mimeType, mt.name()));
|
||||||
project = manager ? manager->openProject(path, &errorMessage) : nullptr;
|
project = manager ? manager->openProject(path) : nullptr;
|
||||||
if (project) {
|
if (project) {
|
||||||
if (setupProject(project))
|
if (setupProject(project))
|
||||||
project->saveSettings();
|
project->saveSettings();
|
||||||
|
@@ -1707,8 +1707,10 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
|
|||||||
foreach (IProjectManager *manager, projectManagers) {
|
foreach (IProjectManager *manager, projectManagers) {
|
||||||
if (mt.matchesName(manager->mimeType())) {
|
if (mt.matchesName(manager->mimeType())) {
|
||||||
foundProjectManager = true;
|
foundProjectManager = true;
|
||||||
QString tmp;
|
if (!QFileInfo(filePath).isFile()) {
|
||||||
if (Project *pro = manager->openProject(filePath, &tmp)) {
|
appendError(errorString,
|
||||||
|
tr("Failed opening project \"%1\": Project is not a file").arg(fileName));
|
||||||
|
} else if (Project *pro = manager->openProject(filePath)) {
|
||||||
pro->setProjectManager(manager);
|
pro->setProjectManager(manager);
|
||||||
QObject::connect(pro, &Project::parsingFinished, [pro]() {
|
QObject::connect(pro, &Project::parsingFinished, [pro]() {
|
||||||
emit SessionManager::instance()->projectFinishedParsing(pro);
|
emit SessionManager::instance()->projectFinishedParsing(pro);
|
||||||
@@ -1726,8 +1728,6 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
|
|||||||
delete pro;
|
delete pro;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tmp.isEmpty())
|
|
||||||
appendError(errorString, tmp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -94,7 +94,7 @@ class PythonProjectManager : public IProjectManager
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QString mimeType() const override { return QLatin1String(PythonMimeType); }
|
QString mimeType() const override { return QLatin1String(PythonMimeType); }
|
||||||
Project *openProject(const QString &fileName, QString *errorString) override;
|
Project *openProject(const QString &fileName) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PythonProject : public Project
|
class PythonProject : public Project
|
||||||
@@ -361,15 +361,8 @@ PythonRunConfigurationWidget::PythonRunConfigurationWidget(PythonRunConfiguratio
|
|||||||
setEnabled(runConfiguration->isEnabled());
|
setEnabled(runConfiguration->isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
Project *PythonProjectManager::openProject(const QString &fileName, QString *errorString)
|
Project *PythonProjectManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
|
|
||||||
.arg(fileName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PythonProject(fileName);
|
return new PythonProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -105,15 +105,8 @@ QString QbsManager::mimeType() const
|
|||||||
return QLatin1String(QmlJSTools::Constants::QBS_MIMETYPE);
|
return QLatin1String(QmlJSTools::Constants::QBS_MIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::Project *QbsManager::openProject(const QString &fileName, QString *errorString)
|
ProjectExplorer::Project *QbsManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
|
|
||||||
.arg(fileName);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new QbsProject(fileName);
|
return new QbsProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ public:
|
|||||||
~QbsManager();
|
~QbsManager();
|
||||||
|
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
|
|
||||||
// QBS profiles management:
|
// QBS profiles management:
|
||||||
QString profileForKit(const ProjectExplorer::Kit *k);
|
QString profileForKit(const ProjectExplorer::Kit *k);
|
||||||
|
@@ -74,15 +74,8 @@ QString QmakeManager::mimeType() const
|
|||||||
return QLatin1String(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
|
return QLatin1String(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName, QString *errorString)
|
ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file")
|
|
||||||
.arg(fileName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new QmakeProject(this, fileName);
|
return new QmakeProject(this, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ public:
|
|||||||
void notifyChanged(const Utils::FileName &name);
|
void notifyChanged(const Utils::FileName &name);
|
||||||
|
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
|
|
||||||
// Context information used in the slot implementations
|
// Context information used in the slot implementations
|
||||||
static ProjectExplorer::Node *contextNode();
|
static ProjectExplorer::Node *contextNode();
|
||||||
|
@@ -43,15 +43,8 @@ Manager::Manager()
|
|||||||
QString Manager::mimeType() const
|
QString Manager::mimeType() const
|
||||||
{ return QLatin1String(Constants::QMLPROJECT_MIMETYPE); }
|
{ return QLatin1String(Constants::QMLPROJECT_MIMETYPE); }
|
||||||
|
|
||||||
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
|
ProjectExplorer::Project *Manager::openProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!QFileInfo(fileName).isFile()) {
|
|
||||||
if (errorString)
|
|
||||||
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
|
|
||||||
.arg(fileName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new QmlProject(this, Utils::FileName::fromString(fileName));
|
return new QmlProject(this, Utils::FileName::fromString(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ public:
|
|||||||
Manager();
|
Manager();
|
||||||
|
|
||||||
QString mimeType() const override;
|
QString mimeType() const override;
|
||||||
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
|
ProjectExplorer::Project *openProject(const QString &fileName) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user