forked from qt-creator/qt-creator
Projects: Improve opening of projects
Move logic to detect already open projects into ProjectExplorer itself, along with some check for the canonicalFilePath. Remove the same logic from the individual projectmanagers. Put check that the path is a file into project managers. So far all of them assume the project file to be a file (e.g. a xcode project manager would expect a directory though). Task-number: QTCREATORBUG-9350 Change-Id: I3901958395e3c594c8cfba9a85dc7d3ec3334afb Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -47,26 +47,14 @@ namespace Internal {
|
||||
|
||||
Project *AutotoolsManager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
|
||||
|
||||
if (canonicalFilePath.isEmpty()) {
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project file does not exist")
|
||||
.arg(QDir::toNativeSeparators(fileName));
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check whether the project is already open or not.
|
||||
ProjectExplorerPlugin *projectExplorer = ProjectExplorerPlugin::instance();
|
||||
foreach (Project *pi, projectExplorer->session()->projects()) {
|
||||
if (canonicalFilePath == pi->document()->fileName()) {
|
||||
*errorString = tr("Failed opening project '%1': Project already open")
|
||||
.arg(QDir::toNativeSeparators(canonicalFilePath));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return new AutotoolsProject(this, canonicalFilePath);
|
||||
return new AutotoolsProject(this, fileName);
|
||||
}
|
||||
|
||||
QString AutotoolsManager::mimeType() const
|
||||
|
||||
@@ -126,8 +126,13 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project)
|
||||
|
||||
ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
// TODO check whether this project is already opened
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return new CMakeProject(this, fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,21 +51,14 @@ QString Manager::mimeType() const
|
||||
|
||||
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
if (!QFileInfo(fileName).isFile())
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
|
||||
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
|
||||
if (fileName == pi->document()->fileName()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project already open")
|
||||
.arg(QDir::toNativeSeparators(fileName));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GenericProject *project = new GenericProject(this, fileName);
|
||||
return project;
|
||||
return new GenericProject(this, fileName);
|
||||
}
|
||||
|
||||
void Manager::registerProject(GenericProject *project)
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
IProjectManager() {}
|
||||
|
||||
virtual QString mimeType() const = 0;
|
||||
// fileName is a canonical path!
|
||||
virtual Project *openProject(const QString &fileName, QString *errorString) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -1334,6 +1334,16 @@ static inline QList<IProjectManager*> allProjectManagers()
|
||||
return ExtensionSystem::PluginManager::getObjects<IProjectManager>();
|
||||
}
|
||||
|
||||
static void appendError(QString *errorString, const QString &error)
|
||||
{
|
||||
if (!errorString || error.isEmpty())
|
||||
return;
|
||||
|
||||
if (!errorString->isEmpty())
|
||||
errorString->append(QLatin1Char('\n'));
|
||||
errorString->append(error);
|
||||
}
|
||||
|
||||
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames, QString *errorString)
|
||||
{
|
||||
if (debug)
|
||||
@@ -1343,11 +1353,29 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
|
||||
|
||||
QList<Project*> openedPro;
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
QTC_ASSERT(!fileName.isEmpty(), continue);
|
||||
|
||||
QFileInfo fi = QFileInfo(fileName);
|
||||
QString canonicalFilePath = fi.canonicalFilePath();
|
||||
bool found = false;
|
||||
foreach (ProjectExplorer::Project *pi, session()->projects()) {
|
||||
if (canonicalFilePath == pi->document()->fileName()) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
appendError(errorString, tr("Failed opening project '%1': Project already open")
|
||||
.arg(QDir::toNativeSeparators(fileName)));
|
||||
d->m_session->reportProjectLoadingProgress();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (const Core::MimeType mt = Core::ICore::mimeDatabase()->findByFile(QFileInfo(fileName))) {
|
||||
foreach (IProjectManager *manager, projectManagers) {
|
||||
if (manager->mimeType() == mt.type()) {
|
||||
QString tmp;
|
||||
if (Project *pro = manager->openProject(fileName, &tmp)) {
|
||||
if (Project *pro = manager->openProject(canonicalFilePath, &tmp)) {
|
||||
if (pro->restoreSettings()) {
|
||||
connect(pro, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
|
||||
d->m_session->addProject(pro);
|
||||
@@ -1359,16 +1387,13 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
|
||||
delete pro;
|
||||
}
|
||||
}
|
||||
if (errorString) {
|
||||
if (!errorString->isEmpty() && !tmp.isEmpty())
|
||||
errorString->append(QLatin1Char('\n'));
|
||||
errorString->append(tmp);
|
||||
}
|
||||
d->m_session->reportProjectLoadingProgress();
|
||||
if (!tmp.isEmpty())
|
||||
appendError(errorString, tmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
d->m_session->reportProjectLoadingProgress();
|
||||
}
|
||||
updateActions();
|
||||
|
||||
|
||||
@@ -115,9 +115,13 @@ QString QbsManager::mimeType() const
|
||||
|
||||
ProjectExplorer::Project *QbsManager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
Q_UNUSED(errorString);
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: This is way too simplistic!
|
||||
return new Internal::QbsProject(this, fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,22 +49,14 @@ QString Manager::mimeType() const
|
||||
|
||||
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
|
||||
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
|
||||
if (fileName == pi->document()->fileName()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project already open") .arg(QDir::toNativeSeparators(fileName));
|
||||
return 0;
|
||||
}
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fileInfo.isFile())
|
||||
return new QmlProject(this, fileName);
|
||||
|
||||
*errorString = tr("Failed opening project '%1': Project file is not a file").arg(QDir::toNativeSeparators(fileName));
|
||||
return 0;
|
||||
return new QmlProject(this, fileName);
|
||||
}
|
||||
|
||||
void Manager::registerProject(QmlProject *project)
|
||||
|
||||
@@ -176,28 +176,14 @@ QString Qt4Manager::mimeType() const
|
||||
|
||||
ProjectExplorer::Project *Qt4Manager::openProject(const QString &fileName, QString *errorString)
|
||||
{
|
||||
// TODO Make all file paths relative & remove this hack
|
||||
// We convert the path to an absolute one here because qt4project.cpp
|
||||
// && profileevaluator use absolute/canonical file paths all over the place
|
||||
// Correct fix would be to remove these calls ...
|
||||
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
|
||||
|
||||
if (canonicalFilePath.isEmpty()) {
|
||||
if (!QFileInfo(fileName).isFile()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project file does not exist").arg(QDir::toNativeSeparators(fileName));
|
||||
*errorString = tr("Failed opening project '%1': Project is not a file")
|
||||
.arg(fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) {
|
||||
if (canonicalFilePath == pi->document()->fileName()) {
|
||||
if (errorString)
|
||||
*errorString = tr("Failed opening project '%1': Project already open").arg(QDir::toNativeSeparators(canonicalFilePath));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Qt4Project *pro = new Qt4Project(this, canonicalFilePath);
|
||||
return pro;
|
||||
return new Qt4Project(this, fileName);
|
||||
}
|
||||
|
||||
ProjectExplorer::ProjectExplorerPlugin *Qt4Manager::projectExplorer() const
|
||||
|
||||
Reference in New Issue
Block a user