Better error feedback on Open project

Task-Nr: QTCREATORBUG-5996
Task-Nr: QTCREATORBUG-5995

Change-Id: I4184a1c652cbfc93a788a8f9b67d936401e197b9
Reviewed-on: http://codereview.qt.nokia.com/4197
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Daniel Teske
2011-09-05 13:47:29 +02:00
parent 61a887a755
commit 4e41308a0f
16 changed files with 62 additions and 42 deletions

View File

@@ -131,8 +131,9 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project)
} }
} }
ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName) ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
{ {
Q_UNUSED(errorString)
// TODO check whether this project is already opened // TODO check whether this project is already opened
return new CMakeProject(this, fileName); return new CMakeProject(this, fileName);
} }

View File

@@ -65,7 +65,7 @@ class CMakeManager : public ProjectExplorer::IProjectManager
public: public:
CMakeManager(CMakeSettingsPage *cmakeSettingsPage); CMakeManager(CMakeSettingsPage *cmakeSettingsPage);
virtual ProjectExplorer::Project *openProject(const QString &fileName); virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
virtual QString mimeType() const; virtual QString mimeType() const;
QString cmakeExecutable() const; QString cmakeExecutable() const;

View File

@@ -35,7 +35,6 @@
#include "genericproject.h" #include "genericproject.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
@@ -52,7 +51,7 @@ QString Manager::mimeType() const
return QLatin1String(Constants::GENERICMIMETYPE); return QLatin1String(Constants::GENERICMIMETYPE);
} }
ProjectExplorer::Project *Manager::openProject(const QString &fileName) ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
{ {
if (!QFileInfo(fileName).isFile()) if (!QFileInfo(fileName).isFile())
return 0; return 0;
@@ -60,9 +59,9 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance(); ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) { foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
if (fileName == pi->file()->fileName()) { if (fileName == pi->file()->fileName()) {
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager(); if (errorString)
messageManager->printToOutputPanePopup(tr("Failed opening project '%1': Project already open") *errorString = tr("Failed opening project '%1': Project already open")
.arg(QDir::toNativeSeparators(fileName))); .arg(QDir::toNativeSeparators(fileName));
return 0; return 0;
} }
} }

View File

@@ -48,7 +48,7 @@ public:
Manager(); Manager();
virtual QString mimeType() const; virtual QString mimeType() const;
virtual ProjectExplorer::Project *openProject(const QString &fileName); virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
void notifyChanged(const QString &fileName); void notifyChanged(const QString &fileName);

View File

@@ -585,10 +585,7 @@ bool CustomProjectWizard::postGenerateOpen(const Core::GeneratedFiles &l, QStrin
// Post-Generate: Open the project and the editors as desired // Post-Generate: Open the project and the editors as desired
foreach(const Core::GeneratedFile &file, l) { foreach(const Core::GeneratedFile &file, l) {
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(file.path())) { if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(file.path(), errorMessage)) {
if (errorMessage)
*errorMessage = tr("The project %1 could not be opened.").
arg(QDir::toNativeSeparators(file.path()));
return false; return false;
} }
} }

View File

@@ -53,7 +53,7 @@ public:
IProjectManager() {} IProjectManager() {}
virtual QString mimeType() const = 0; virtual QString mimeType() const = 0;
virtual Project *openProject(const QString &fileName) = 0; virtual Project *openProject(const QString &fileName, QString *errorString) = 0;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -77,7 +77,7 @@ QString ProjectFileFactory::displayName() const
Core::IFile *ProjectFileFactory::open(const QString &fileName) Core::IFile *ProjectFileFactory::open(const QString &fileName)
{ {
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
pe->openProject(fileName); pe->openProject(fileName, 0);
return 0; return 0;
} }

View File

@@ -1018,7 +1018,11 @@ void ProjectExplorerPlugin::loadAction()
d->m_projectFilterString); d->m_projectFilterString);
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
openProject(filename); QString errorMessage;
openProject(filename, &errorMessage);
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errorMessage);
updateActions(); updateActions();
} }
@@ -1229,12 +1233,20 @@ void ProjectExplorerPlugin::savePersistentSettings()
} }
} }
bool ProjectExplorerPlugin::openProject(const QString &fileName) void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
{
QString errorMessage;
openProject(fileName, &errorMessage);
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errorMessage);
}
bool ProjectExplorerPlugin::openProject(const QString &fileName, QString *errorString)
{ {
if (debug) if (debug)
qDebug() << "ProjectExplorerPlugin::openProject"; qDebug() << "ProjectExplorerPlugin::openProject";
QList<Project *> list = openProjects(QStringList() << fileName); QList<Project *> list = openProjects(QStringList() << fileName, errorString);
if (!list.isEmpty()) { if (!list.isEmpty()) {
addToRecentProjects(fileName, list.first()->displayName()); addToRecentProjects(fileName, list.first()->displayName());
d->m_session->setStartupProject(list.first()); d->m_session->setStartupProject(list.first());
@@ -1249,7 +1261,7 @@ static inline QList<IProjectManager*> allProjectManagers()
return pm->getObjects<IProjectManager>(); return pm->getObjects<IProjectManager>();
} }
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames) QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames, QString *errorString)
{ {
if (debug) if (debug)
qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames; qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames;
@@ -1261,7 +1273,8 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName))) { if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName))) {
foreach (IProjectManager *manager, projectManagers) { foreach (IProjectManager *manager, projectManagers) {
if (manager->mimeType() == mt.type()) { if (manager->mimeType() == mt.type()) {
if (Project *pro = manager->openProject(fileName)) { QString tmp;
if (Project *pro = manager->openProject(fileName, &tmp)) {
if (pro->restoreSettings()) { if (pro->restoreSettings()) {
connect(pro, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged())); connect(pro, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
d->m_session->addProject(pro); d->m_session->addProject(pro);
@@ -1273,6 +1286,11 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
delete pro; delete pro;
} }
} }
if (errorString) {
if (!errorString->isEmpty() && !tmp.isEmpty())
errorString->append('\n');
errorString->append(tmp);
}
d->m_session->reportProjectLoadingProgress(); d->m_session->reportProjectLoadingProgress();
break; break;
} }
@@ -1406,7 +1424,7 @@ void ProjectExplorerPlugin::restoreSession()
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*, Core::IMode*)), connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*, Core::IMode*)),
this, SLOT(currentModeChanged(Core::IMode*, Core::IMode*))); this, SLOT(currentModeChanged(Core::IMode*, Core::IMode*)));
connect(d->m_welcomePage, SIGNAL(requestSession(QString)), this, SLOT(loadSession(QString))); connect(d->m_welcomePage, SIGNAL(requestSession(QString)), this, SLOT(loadSession(QString)));
connect(d->m_welcomePage, SIGNAL(requestProject(QString)), this, SLOT(openProject(QString))); connect(d->m_welcomePage, SIGNAL(requestProject(QString)), this, SLOT(openProjectWelcomePage(QString)));
QStringList combinedList; QStringList combinedList;
// Converts "filename" "+45" or "filename" ":23" // Converts "filename" "+45" or "filename" ":23"
@@ -2296,7 +2314,10 @@ void ProjectExplorerPlugin::openRecentProject()
return; return;
QString fileName = a->data().toString(); QString fileName = a->data().toString();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
openProject(fileName); QString errorMessage;
openProject(fileName, &errorMessage);
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errorMessage);
} }
} }

View File

@@ -77,8 +77,9 @@ public:
static ProjectExplorerPlugin *instance(); static ProjectExplorerPlugin *instance();
Q_SLOT bool openProject(const QString &fileName); bool openProject(const QString &fileName, QString *error);
QList<Project *> openProjects(const QStringList &fileNames); QList<Project *> openProjects(const QStringList &fileNames, QString *error);
Q_SLOT void openProjectWelcomePage(const QString &fileName);
SessionManager *session() const; SessionManager *session() const;

View File

@@ -165,7 +165,10 @@ bool SessionFile::load(const QString &fileName)
// Keep projects that failed to load in the session! // Keep projects that failed to load in the session!
m_failedProjects = fileList; m_failedProjects = fileList;
if (!fileList.isEmpty()) { if (!fileList.isEmpty()) {
QList<Project *> projects = ProjectExplorerPlugin::instance()->openProjects(fileList); QString errors;
QList<Project *> projects = ProjectExplorerPlugin::instance()->openProjects(fileList, &errors);
if (!errors.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errors);
foreach (Project *p, projects) foreach (Project *p, projects)
m_failedProjects.removeAll(p->file()->fileName()); m_failedProjects.removeAll(p->file()->fileName());
} }

View File

@@ -36,7 +36,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/ifile.h> #include <coreplugin/ifile.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
@@ -53,17 +52,15 @@ Manager::Manager()
QString Manager::mimeType() const QString Manager::mimeType() const
{ return QLatin1String(Constants::QMLMIMETYPE); } { return QLatin1String(Constants::QMLMIMETYPE); }
ProjectExplorer::Project *Manager::openProject(const QString &fileName) ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
{ {
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance(); ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) { foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
if (fileName == pi->file()->fileName()) { if (fileName == pi->file()->fileName()) {
messageManager->printToOutputPanePopup(tr("Failed opening project '%1': Project already open") if (errorString)
.arg(QDir::toNativeSeparators(fileName))); *errorString = tr("Failed opening project '%1': Project already open") .arg(QDir::toNativeSeparators(fileName));
return 0; return 0;
} }
} }
@@ -71,6 +68,7 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
if (fileInfo.isFile()) if (fileInfo.isFile())
return new QmlProject(this, fileName); return new QmlProject(this, fileName);
*errorString = tr("Failed opening project '%1': Project file is not a file").arg(QDir::toNativeSeparators(fileName));
return 0; return 0;
} }

View File

@@ -50,7 +50,7 @@ public:
Manager(); Manager();
virtual QString mimeType() const; virtual QString mimeType() const;
virtual ProjectExplorer::Project *openProject(const QString &fileName); virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
void notifyChanged(const QString &fileName); void notifyChanged(const QString &fileName);

View File

@@ -46,7 +46,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/basefilewizard.h> #include <coreplugin/basefilewizard.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
@@ -232,10 +231,8 @@ static void updateBoilerPlateCodeFiles(const AbstractMobileApp *app, const QStri
} }
} }
ProjectExplorer::Project *Qt4Manager::openProject(const QString &fileName) ProjectExplorer::Project *Qt4Manager::openProject(const QString &fileName, QString *errorString)
{ {
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
// TODO Make all file paths relative & remove this hack // TODO Make all file paths relative & remove this hack
// We convert the path to an absolute one here because qt4project.cpp // We convert the path to an absolute one here because qt4project.cpp
// && profileevaluator use absolute/canonical file paths all over the place // && profileevaluator use absolute/canonical file paths all over the place
@@ -243,13 +240,15 @@ ProjectExplorer::Project *Qt4Manager::openProject(const QString &fileName)
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath(); QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
if (canonicalFilePath.isEmpty()) { if (canonicalFilePath.isEmpty()) {
messageManager->printToOutputPane(tr("Failed opening project '%1': Project file does not exist").arg(QDir::toNativeSeparators(canonicalFilePath))); if (errorString)
*errorString = tr("Failed opening project '%1': Project file does not exist").arg(QDir::toNativeSeparators(fileName));
return 0; return 0;
} }
foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) { foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) {
if (canonicalFilePath == pi->file()->fileName()) { if (canonicalFilePath == pi->file()->fileName()) {
messageManager->printToOutputPane(tr("Failed opening project '%1': Project already open").arg(QDir::toNativeSeparators(canonicalFilePath))); if (errorString)
*errorString = tr("Failed opening project '%1': Project already open").arg(QDir::toNativeSeparators(canonicalFilePath));
return 0; return 0;
} }
} }

View File

@@ -81,7 +81,7 @@ public:
ProjectExplorer::ProjectExplorerPlugin *projectExplorer() const; ProjectExplorer::ProjectExplorerPlugin *projectExplorer() const;
virtual QString mimeType() const; virtual QString mimeType() const;
ProjectExplorer::Project *openProject(const QString &fileName); ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
// Context information used in the slot implementations // Context information used in the slot implementations
ProjectExplorer::Node *contextNode() const; ProjectExplorer::Node *contextNode() const;

View File

@@ -219,10 +219,13 @@ void GettingStartedWelcomePage::openProject(const QString &projectFile, const QS
proFile = copyToAlternativeLocation(proFileInfo, filesToOpen); proFile = copyToAlternativeLocation(proFileInfo, filesToOpen);
// don't try to load help and files if loading the help request is being cancelled // don't try to load help and files if loading the help request is being cancelled
if (!proFile.isEmpty() && ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFile)) { QString errorMessage;
if (!proFile.isEmpty() && ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFile, &errorMessage)) {
Core::ICore::instance()->openFiles(filesToOpen); Core::ICore::instance()->openFiles(filesToOpen);
Core::ICore::instance()->helpManager()->handleHelpRequest(help.toString()+QLatin1String("?view=split")); Core::ICore::instance()->helpManager()->handleHelpRequest(help.toString()+QLatin1String("?view=split"));
} }
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errorMessage);
} }
void GettingStartedWelcomePage::updateTagsModel() void GettingStartedWelcomePage::updateTagsModel()

View File

@@ -189,9 +189,7 @@ QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessa
return QString(); return QString();
// Open. Do not use a busy cursor here as additional wizards might pop up // Open. Do not use a busy cursor here as additional wizards might pop up
const QString projectFile = projectFiles.front().absoluteFilePath(); const QString projectFile = projectFiles.front().absoluteFilePath();
if (!pe->openProject(projectFile)) { if (!pe->openProject(projectFile, errorMessage)) {
*errorMessage = tr("Unable to open the project '%1'.").
arg(QDir::toNativeSeparators(projectFile));
return QString(); return QString();
} }
return projectFile; return projectFile;