ProjectExplorer: Always give feedback on failed project loading

Task-Nr: QTCREATORBUG-3435
This commit is contained in:
dt
2011-01-11 19:30:25 +01:00
parent 49655d622d
commit 81b37f0215
3 changed files with 27 additions and 33 deletions

View File

@@ -71,17 +71,9 @@ QString ProjectFileFactory::displayName() const
Core::IFile *ProjectFileFactory::open(const QString &fileName) Core::IFile *ProjectFileFactory::open(const QString &fileName)
{ {
Core::IFile *fIFace = 0;
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
if (!pe->openProject(fileName)) { pe->openProject(fileName);
Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not open the following project: '%1'").arg(fileName)); return 0;
} else if (pe->session()) {
SessionManager *session = pe->session();
if (session->projects().count() == 1)
fIFace = session->projects().first()->file();
}
return fIFace;
} }
QList<ProjectFileFactory *> ProjectFileFactory::createFactories(QString *filterString) QList<ProjectFileFactory *> ProjectFileFactory::createFactories(QString *filterString)

View File

@@ -887,19 +887,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
return true; return true;
} }
ProjectFileFactory *ProjectExplorerPlugin::findProjectFileFactory(const QString &filename) const
{
// Find factory
if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(filename))) {
const QString mimeType = mt.type();
foreach (ProjectFileFactory *f, d->m_fileFactories)
if (f->mimeTypes().contains(mimeType))
return f;
}
qWarning("Unable to find project file factory for '%s'", filename.toUtf8().constData());
return 0;
}
void ProjectExplorerPlugin::loadAction() void ProjectExplorerPlugin::loadAction()
{ {
if (debug) if (debug)
@@ -923,8 +910,7 @@ void ProjectExplorerPlugin::loadAction()
d->m_projectFilterString); d->m_projectFilterString);
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
if (ProjectFileFactory *pf = findProjectFileFactory(filename)) loadProject(filename);
pf->open(filename);
updateActions(); updateActions();
} }
@@ -1110,6 +1096,18 @@ void ProjectExplorerPlugin::savePersistentSettings()
} }
} }
void ProjectExplorerPlugin::loadProject(const QString &project)
{
if (!openProject(project)) {
QMessageBox box(QMessageBox::Warning,
tr("Failed to open project"),
tr("Failed to open project:\n%1").arg(project),
QMessageBox::Ok,
Core::ICore::instance()->mainWindow());
box.exec();
}
}
bool ProjectExplorerPlugin::openProject(const QString &fileName) bool ProjectExplorerPlugin::openProject(const QString &fileName)
{ {
if (debug) if (debug)
@@ -1161,11 +1159,8 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
} }
updateActions(); updateActions();
if (openedPro.isEmpty()) { if (!openedPro.isEmpty())
qDebug() << "ProjectExplorerPlugin - Could not open any projects!";
} else {
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT); Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
}
return openedPro; return openedPro;
} }
@@ -1984,8 +1979,16 @@ void ProjectExplorerPlugin::openRecentProject()
if (!a) if (!a)
return; return;
QString fileName = a->data().toString(); QString fileName = a->data().toString();
if (!fileName.isEmpty()) if (!fileName.isEmpty()) {
openProject(fileName); if (!openProject(fileName)) {
QMessageBox box(QMessageBox::Warning,
tr("Failed to open project"),
tr("Failed to open project:\n%1").arg(fileName),
QMessageBox::Ok,
Core::ICore::instance()->mainWindow());
box.exec();
}
}
} }
void ProjectExplorerPlugin::invalidateProject(Project *project) void ProjectExplorerPlugin::invalidateProject(Project *project)

View File

@@ -205,7 +205,7 @@ private slots:
void updateDeployActions(); void updateDeployActions();
void slotUpdateRunActions(); void slotUpdateRunActions();
void loadProject(const QString &project) { openProject(project); } void loadProject(const QString &project);
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode); void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void updateActions(); void updateActions();
void loadCustomWizards(); void loadCustomWizards();
@@ -245,7 +245,6 @@ private:
void addToRecentProjects(const QString &fileName, const QString &displayName); void addToRecentProjects(const QString &fileName, const QString &displayName);
void updateWelcomePage(); void updateWelcomePage();
Internal::ProjectFileFactory *findProjectFileFactory(const QString &filename) const;
static ProjectExplorerPlugin *m_instance; static ProjectExplorerPlugin *m_instance;
ProjectExplorerPluginPrivate *d; ProjectExplorerPluginPrivate *d;