Commit 4e41308a authored by Daniel Teske's avatar Daniel Teske

Better error feedback on Open project

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

Change-Id: I4184a1c652cbfc93a788a8f9b67d936401e197b9
Reviewed-on: http://codereview.qt.nokia.com/4197Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 61a887a7
......@@ -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
return new CMakeProject(this, fileName);
}
......
......@@ -65,7 +65,7 @@ class CMakeManager : public ProjectExplorer::IProjectManager
public:
CMakeManager(CMakeSettingsPage *cmakeSettingsPage);
virtual ProjectExplorer::Project *openProject(const QString &fileName);
virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
virtual QString mimeType() const;
QString cmakeExecutable() const;
......
......@@ -35,7 +35,6 @@
#include "genericproject.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
......@@ -52,7 +51,7 @@ QString Manager::mimeType() const
return QLatin1String(Constants::GENERICMIMETYPE);
}
ProjectExplorer::Project *Manager::openProject(const QString &fileName)
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
{
if (!QFileInfo(fileName).isFile())
return 0;
......@@ -60,9 +59,9 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
if (fileName == pi->file()->fileName()) {
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
messageManager->printToOutputPanePopup(tr("Failed opening project '%1': Project already open")
.arg(QDir::toNativeSeparators(fileName)));
if (errorString)
*errorString = tr("Failed opening project '%1': Project already open")
.arg(QDir::toNativeSeparators(fileName));
return 0;
}
}
......
......@@ -48,7 +48,7 @@ public:
Manager();
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);
......
......@@ -585,10 +585,7 @@ bool CustomProjectWizard::postGenerateOpen(const Core::GeneratedFiles &l, QStrin
// Post-Generate: Open the project and the editors as desired
foreach(const Core::GeneratedFile &file, l) {
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(file.path())) {
if (errorMessage)
*errorMessage = tr("The project %1 could not be opened.").
arg(QDir::toNativeSeparators(file.path()));
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(file.path(), errorMessage)) {
return false;
}
}
......
......@@ -53,7 +53,7 @@ public:
IProjectManager() {}
virtual QString mimeType() const = 0;
virtual Project *openProject(const QString &fileName) = 0;
virtual Project *openProject(const QString &fileName, QString *errorString) = 0;
};
} // namespace ProjectExplorer
......
......@@ -77,7 +77,7 @@ QString ProjectFileFactory::displayName() const
Core::IFile *ProjectFileFactory::open(const QString &fileName)
{
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
pe->openProject(fileName);
pe->openProject(fileName, 0);
return 0;
}
......
......@@ -1018,7 +1018,11 @@ void ProjectExplorerPlugin::loadAction()
d->m_projectFilterString);
if (filename.isEmpty())
return;
openProject(filename);
QString errorMessage;
openProject(filename, &errorMessage);
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("Failed to open project"), errorMessage);
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)
qDebug() << "ProjectExplorerPlugin::openProject";
QList<Project *> list = openProjects(QStringList() << fileName);
QList<Project *> list = openProjects(QStringList() << fileName, errorString);
if (!list.isEmpty()) {
addToRecentProjects(fileName, list.first()->displayName());
d->m_session->setStartupProject(list.first());
......@@ -1249,7 +1261,7 @@ static inline QList<IProjectManager*> allProjectManagers()
return pm->getObjects<IProjectManager>();
}
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames, QString *errorString)
{
if (debug)
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))) {
foreach (IProjectManager *manager, projectManagers) {
if (manager->mimeType() == mt.type()) {
if (Project *pro = manager->openProject(fileName)) {
QString tmp;
if (Project *pro = manager->openProject(fileName, &tmp)) {
if (pro->restoreSettings()) {
connect(pro, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
d->m_session->addProject(pro);
......@@ -1273,6 +1286,11 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
delete pro;
}
}
if (errorString) {
if (!errorString->isEmpty() && !tmp.isEmpty())
errorString->append('\n');
errorString->append(tmp);
}
d->m_session->reportProjectLoadingProgress();
break;
}
......@@ -1406,7 +1424,7 @@ void ProjectExplorerPlugin::restoreSession()
connect(modeManager, SIGNAL(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(requestProject(QString)), this, SLOT(openProject(QString)));
connect(d->m_welcomePage, SIGNAL(requestProject(QString)), this, SLOT(openProjectWelcomePage(QString)));
QStringList combinedList;
// Converts "filename" "+45" or "filename" ":23"
......@@ -2296,7 +2314,10 @@ void ProjectExplorerPlugin::openRecentProject()
return;
QString fileName = a->data().toString();
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);
}
}
......
......@@ -77,8 +77,9 @@ public:
static ProjectExplorerPlugin *instance();
Q_SLOT bool openProject(const QString &fileName);
QList<Project *> openProjects(const QStringList &fileNames);
bool openProject(const QString &fileName, QString *error);
QList<Project *> openProjects(const QStringList &fileNames, QString *error);
Q_SLOT void openProjectWelcomePage(const QString &fileName);
SessionManager *session() const;
......
......@@ -165,7 +165,10 @@ bool SessionFile::load(const QString &fileName)
// Keep projects that failed to load in the session!
m_failedProjects = fileList;
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)
m_failedProjects.removeAll(p->file()->fileName());
}
......
......@@ -36,7 +36,6 @@
#include <coreplugin/icore.h>
#include <coreplugin/ifile.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
......@@ -53,17 +52,15 @@ Manager::Manager()
QString Manager::mimeType() const
{ 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);
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
if (fileName == pi->file()->fileName()) {
messageManager->printToOutputPanePopup(tr("Failed opening project '%1': Project already open")
.arg(QDir::toNativeSeparators(fileName)));
if (errorString)
*errorString = tr("Failed opening project '%1': Project already open") .arg(QDir::toNativeSeparators(fileName));
return 0;
}
}
......@@ -71,6 +68,7 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
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;
}
......
......@@ -50,7 +50,7 @@ public:
Manager();
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);
......
......@@ -46,7 +46,6 @@
#include <coreplugin/icore.h>
#include <coreplugin/basefilewizard.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.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
// We convert the path to an absolute one here because qt4project.cpp
// && 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();
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;
}
foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) {
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;
}
}
......
......@@ -81,7 +81,7 @@ public:
ProjectExplorer::ProjectExplorerPlugin *projectExplorer() 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
ProjectExplorer::Node *contextNode() const;
......
......@@ -219,10 +219,13 @@ void GettingStartedWelcomePage::openProject(const QString &projectFile, const QS
proFile = copyToAlternativeLocation(proFileInfo, filesToOpen);
// 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()->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()
......
......@@ -189,9 +189,7 @@ QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessa
return QString();
// Open. Do not use a busy cursor here as additional wizards might pop up
const QString projectFile = projectFiles.front().absoluteFilePath();
if (!pe->openProject(projectFile)) {
*errorMessage = tr("Unable to open the project '%1'.").
arg(QDir::toNativeSeparators(projectFile));
if (!pe->openProject(projectFile, errorMessage)) {
return QString();
}
return projectFile;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment