Skip to content
Snippets Groups Projects
Commit 0a509409 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Welcome: Do not open main.cpp when project loading was canceled

When choosing an example from the welcome screen and the user
cancels loading the project:
 * Do not switch to edit mode
 * Do not load main.cpp
 * Do not pop up help

Task-number: QTCREATORBUG-2774
Reviewed-by: Daniel Molkentin
parent a6cfa0ca
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,13 @@ public:
virtual void addContextObject(IContext *context) = 0;
virtual void removeContextObject(IContext *context) = 0;
enum OpenFilesFlags { None = 0, SwitchMode = 1, CanContainLineNumbers = 2};
enum OpenFilesFlags {
None = 0,
SwitchMode = 1,
CanContainLineNumbers = 2,
/// Stop loading once the first file fails to load
StopOnLoadFail = 4
};
virtual void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None) = 0;
signals:
......
......@@ -829,16 +829,20 @@ void MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags f
const QFileInfo fi(fileName);
const QString absoluteFilePath = fi.absoluteFilePath();
if (IFileFactory *fileFactory = findFileFactory(nonEditorFileFactories, mimeDatabase(), fi)) {
fileFactory->open(absoluteFilePath);
if (flags && ICore::SwitchMode)
Core::IFile *file = fileFactory->open(absoluteFilePath);
if (!file && (flags & ICore::StopOnLoadFail))
return;
if (file && (flags & ICore::SwitchMode))
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
} else {
QFlags<EditorManager::OpenEditorFlag> emFlags;
if (flags && ICore::SwitchMode)
if (flags & ICore::SwitchMode)
emFlags = EditorManager::ModeSwitch;
if (flags && ICore::CanContainLineNumbers)
if (flags & ICore::CanContainLineNumbers)
emFlags |= EditorManager::CanContainLineNumber;
editorManager()->openEditor(absoluteFilePath, QString(), emFlags);
Core::IEditor *editor = editorManager()->openEditor(absoluteFilePath, QString(), emFlags);
if (!editor && (flags & ICore::StopOnLoadFail))
return;
}
}
}
......
......@@ -33,6 +33,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/mainwindow.h>
#include <coreplugin/rssfetcher.h>
#include <projectexplorer/projectexplorer.h>
......@@ -329,8 +330,8 @@ void GettingStartedWelcomePageWidget::slotOpenExample()
tryFile = proFileInfo.path() + '/' + proFileInfo.baseName() + ".qml";
if(QFile::exists(tryFile))
files << tryFile;
Core::ICore::instance()->openFiles(files, Core::ICore::SwitchMode);
if (!helpFile.isEmpty())
Core::ICore::instance()->openFiles(files, static_cast<Core::ICore::OpenFilesFlags>(Core::ICore::SwitchMode | Core::ICore::StopOnLoadFail));
if (!tryFile.isEmpty() && Core::EditorManager::instance()->hasEditor(tryFile) && !helpFile.isEmpty())
slotOpenContextHelpPage(helpFile);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment