forked from qt-creator/qt-creator
ProjectExplorer: Move OpenProjectResult off ProjectExplorerPlugin class
It's not really related to the "Plugin-ness", and I'd generally like to get away from exported ExtensionSystem::IPlugin derived classes as "entrypoint" with the resulting fat plugin pimpl in favor of more separate isolated access points. Change-Id: I445df6109f4231e37750aa15eaa210d6669805e3 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -391,8 +391,7 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
|||||||
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
||||||
bool configureAsExampleProject, Kit *kit)
|
bool configureAsExampleProject, Kit *kit)
|
||||||
{
|
{
|
||||||
ProjectExplorerPlugin::OpenProjectResult result =
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile);
|
||||||
ProjectExplorerPlugin::openProject(projectFile);
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qWarning() << result.errorMessage() << result.alreadyOpen();
|
qWarning() << result.errorMessage() << result.alreadyOpen();
|
||||||
return {};
|
return {};
|
||||||
|
@@ -529,8 +529,7 @@ bool CustomProjectWizard::postGenerateOpen(const GeneratedFiles &l, QString *err
|
|||||||
// Post-Generate: Open the project and the editors as desired
|
// Post-Generate: Open the project and the editors as desired
|
||||||
for (const GeneratedFile &file : l) {
|
for (const GeneratedFile &file : l) {
|
||||||
if (file.attributes() & GeneratedFile::OpenProjectAttribute) {
|
if (file.attributes() & GeneratedFile::OpenProjectAttribute) {
|
||||||
ProjectExplorerPlugin::OpenProjectResult result
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(file.filePath());
|
||||||
= ProjectExplorerPlugin::openProject(file.filePath());
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = result.errorMessage();
|
*errorMessage = result.errorMessage();
|
||||||
|
@@ -445,8 +445,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
|
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
|
||||||
ProjectExplorerPlugin::OpenProjectResult result
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(file.filePath());
|
||||||
= ProjectExplorerPlugin::openProject(file.filePath());
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
errorMessage = result.errorMessage();
|
errorMessage = result.errorMessage();
|
||||||
if (errorMessage.isEmpty()) {
|
if (errorMessage.isEmpty()) {
|
||||||
|
@@ -1970,7 +1970,7 @@ void ProjectExplorerPluginPrivate::loadAction()
|
|||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
|
||||||
if (!result)
|
if (!result)
|
||||||
ProjectExplorerPlugin::showOpenProjectError(result);
|
ProjectExplorerPlugin::showOpenProjectError(result);
|
||||||
|
|
||||||
@@ -2273,7 +2273,7 @@ void ProjectExplorerPlugin::openProjectWelcomePage(const FilePath &filePath)
|
|||||||
showOpenProjectError(result);
|
showOpenProjectError(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(const FilePath &filePath)
|
OpenProjectResult ProjectExplorerPlugin::openProject(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
OpenProjectResult result = openProjects({filePath});
|
OpenProjectResult result = openProjects({filePath});
|
||||||
Project *project = result.project();
|
Project *project = result.project();
|
||||||
@@ -2323,7 +2323,7 @@ static void appendError(QString &errorString, const QString &error)
|
|||||||
errorString.append(error);
|
errorString.append(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths)
|
OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths)
|
||||||
{
|
{
|
||||||
QList<Project*> openedPro;
|
QList<Project*> openedPro;
|
||||||
QList<Project *> alreadyOpen;
|
QList<Project *> alreadyOpen;
|
||||||
@@ -3198,8 +3198,7 @@ void ProjectExplorerPluginPrivate::clearRecentProjects()
|
|||||||
void ProjectExplorerPluginPrivate::openRecentProject(const FilePath &filePath)
|
void ProjectExplorerPluginPrivate::openRecentProject(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
ProjectExplorerPlugin::OpenProjectResult result
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
|
||||||
= ProjectExplorerPlugin::openProject(filePath);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
ProjectExplorerPlugin::showOpenProjectError(result);
|
ProjectExplorerPlugin::showOpenProjectError(result);
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,46 @@ class MiniProjectTargetSelector;
|
|||||||
using RecentProjectsEntry = QPair<Utils::FilePath, QString>;
|
using RecentProjectsEntry = QPair<Utils::FilePath, QString>;
|
||||||
using RecentProjectsEntries = QList<RecentProjectsEntry>;
|
using RecentProjectsEntries = QList<RecentProjectsEntry>;
|
||||||
|
|
||||||
|
class PROJECTEXPLORER_EXPORT OpenProjectResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OpenProjectResult(const QList<Project *> &projects, const QList<Project *> &alreadyOpen,
|
||||||
|
const QString &errorMessage)
|
||||||
|
: m_projects(projects), m_alreadyOpen(alreadyOpen),
|
||||||
|
m_errorMessage(errorMessage)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
explicit operator bool() const
|
||||||
|
{
|
||||||
|
return m_errorMessage.isEmpty() && m_alreadyOpen.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Project *project() const
|
||||||
|
{
|
||||||
|
return m_projects.isEmpty() ? nullptr : m_projects.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Project *> projects() const
|
||||||
|
{
|
||||||
|
return m_projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString errorMessage() const
|
||||||
|
{
|
||||||
|
return m_errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Project *> alreadyOpen() const
|
||||||
|
{
|
||||||
|
return m_alreadyOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Project *> m_projects;
|
||||||
|
QList<Project *> m_alreadyOpen;
|
||||||
|
QString m_errorMessage;
|
||||||
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT ProjectExplorerPlugin : public ExtensionSystem::IPlugin
|
class PROJECTEXPLORER_EXPORT ProjectExplorerPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -56,45 +96,6 @@ public:
|
|||||||
|
|
||||||
static ProjectExplorerPlugin *instance();
|
static ProjectExplorerPlugin *instance();
|
||||||
|
|
||||||
class OpenProjectResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OpenProjectResult(const QList<Project *> &projects, const QList<Project *> &alreadyOpen,
|
|
||||||
const QString &errorMessage)
|
|
||||||
: m_projects(projects), m_alreadyOpen(alreadyOpen),
|
|
||||||
m_errorMessage(errorMessage)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
explicit operator bool() const
|
|
||||||
{
|
|
||||||
return m_errorMessage.isEmpty() && m_alreadyOpen.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
Project *project() const
|
|
||||||
{
|
|
||||||
return m_projects.isEmpty() ? nullptr : m_projects.first();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Project *> projects() const
|
|
||||||
{
|
|
||||||
return m_projects;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString errorMessage() const
|
|
||||||
{
|
|
||||||
return m_errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Project *> alreadyOpen() const
|
|
||||||
{
|
|
||||||
return m_alreadyOpen;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
QList<Project *> m_projects;
|
|
||||||
QList<Project *> m_alreadyOpen;
|
|
||||||
QString m_errorMessage;
|
|
||||||
};
|
|
||||||
|
|
||||||
static OpenProjectResult openProject(const Utils::FilePath &filePath);
|
static OpenProjectResult openProject(const Utils::FilePath &filePath);
|
||||||
static OpenProjectResult openProjects(const Utils::FilePaths &filePaths);
|
static OpenProjectResult openProjects(const Utils::FilePaths &filePaths);
|
||||||
static void showOpenProjectError(const OpenProjectResult &result);
|
static void showOpenProjectError(const OpenProjectResult &result);
|
||||||
|
@@ -637,7 +637,7 @@ void ProjectManagerPrivate::restoreProjects(const FilePaths &fileList)
|
|||||||
// 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()) {
|
||||||
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProjects(fileList);
|
OpenProjectResult result = ProjectExplorerPlugin::openProjects(fileList);
|
||||||
if (!result)
|
if (!result)
|
||||||
ProjectExplorerPlugin::showOpenProjectError(result);
|
ProjectExplorerPlugin::showOpenProjectError(result);
|
||||||
const QList<Project *> projects = result.projects();
|
const QList<Project *> projects = result.projects();
|
||||||
|
@@ -114,7 +114,7 @@ bool CmakeProjectConverter::convertProject(const QmlProjectManager::QmlProject *
|
|||||||
|
|
||||||
if (retVal) {
|
if (retVal) {
|
||||||
QMessageBox::information(Core::ICore::dialogParent(), SUCCESS_TITLE, SUCCESS_TEXT);
|
QMessageBox::information(Core::ICore::dialogParent(), SUCCESS_TITLE, SUCCESS_TEXT);
|
||||||
ProjectExplorer::ProjectExplorerPlugin::OpenProjectResult result
|
ProjectExplorer::OpenProjectResult result
|
||||||
= ProjectExplorer::ProjectExplorerPlugin::openProject(newProjectFile());
|
= ProjectExplorer::ProjectExplorerPlugin::openProject(newProjectFile());
|
||||||
if (!result)
|
if (!result)
|
||||||
ProjectExplorer::ProjectExplorerPlugin::showOpenProjectError(result);
|
ProjectExplorer::ProjectExplorerPlugin::showOpenProjectError(result);
|
||||||
|
@@ -203,7 +203,8 @@ static void openProject(const ExampleItem *item)
|
|||||||
// 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())
|
if (proFile.isEmpty())
|
||||||
return;
|
return;
|
||||||
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(proFile);
|
|
||||||
|
OpenProjectResult result = ProjectExplorerPlugin::openProject(proFile);
|
||||||
if (result) {
|
if (result) {
|
||||||
ICore::openFiles(filesToOpen);
|
ICore::openFiles(filesToOpen);
|
||||||
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
||||||
|
@@ -252,7 +252,7 @@ public:
|
|||||||
const FilePath projectFile = FilePath::fromVariant(
|
const FilePath projectFile = FilePath::fromVariant(
|
||||||
data(index(row, 0), ProjectModel::FilePathRole));
|
data(index(row, 0), ProjectModel::FilePathRole));
|
||||||
if (projectFile.exists()) {
|
if (projectFile.exists()) {
|
||||||
const ProjectExplorerPlugin::OpenProjectResult result
|
const OpenProjectResult result
|
||||||
= ProjectExplorer::ProjectExplorerPlugin::openProject(projectFile);
|
= ProjectExplorer::ProjectExplorerPlugin::openProject(projectFile);
|
||||||
if (!result && !result.alreadyOpen().isEmpty()) {
|
if (!result && !result.alreadyOpen().isEmpty()) {
|
||||||
const auto fileToOpen = getMainUiFileWithFallback();
|
const auto fileToOpen = getMainUiFileWithFallback();
|
||||||
|
Reference in New Issue
Block a user