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:
hjk
2024-01-17 13:46:06 +01:00
parent c2e20eafd7
commit 4d1f1f98d1
9 changed files with 52 additions and 54 deletions

View File

@@ -391,8 +391,7 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
bool configureAsExampleProject, Kit *kit)
{
ProjectExplorerPlugin::OpenProjectResult result =
ProjectExplorerPlugin::openProject(projectFile);
OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile);
if (!result) {
qWarning() << result.errorMessage() << result.alreadyOpen();
return {};

View File

@@ -529,8 +529,7 @@ bool CustomProjectWizard::postGenerateOpen(const GeneratedFiles &l, QString *err
// Post-Generate: Open the project and the editors as desired
for (const GeneratedFile &file : l) {
if (file.attributes() & GeneratedFile::OpenProjectAttribute) {
ProjectExplorerPlugin::OpenProjectResult result
= ProjectExplorerPlugin::openProject(file.filePath());
OpenProjectResult result = ProjectExplorerPlugin::openProject(file.filePath());
if (!result) {
if (errorMessage)
*errorMessage = result.errorMessage();

View File

@@ -445,8 +445,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
break;
}
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
ProjectExplorerPlugin::OpenProjectResult result
= ProjectExplorerPlugin::openProject(file.filePath());
OpenProjectResult result = ProjectExplorerPlugin::openProject(file.filePath());
if (!result) {
errorMessage = result.errorMessage();
if (errorMessage.isEmpty()) {

View File

@@ -1970,7 +1970,7 @@ void ProjectExplorerPluginPrivate::loadAction()
if (filePath.isEmpty())
return;
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
@@ -2273,7 +2273,7 @@ void ProjectExplorerPlugin::openProjectWelcomePage(const FilePath &filePath)
showOpenProjectError(result);
}
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(const FilePath &filePath)
OpenProjectResult ProjectExplorerPlugin::openProject(const FilePath &filePath)
{
OpenProjectResult result = openProjects({filePath});
Project *project = result.project();
@@ -2323,7 +2323,7 @@ static void appendError(QString &errorString, const QString &error)
errorString.append(error);
}
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths)
OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths)
{
QList<Project*> openedPro;
QList<Project *> alreadyOpen;
@@ -3198,8 +3198,7 @@ void ProjectExplorerPluginPrivate::clearRecentProjects()
void ProjectExplorerPluginPrivate::openRecentProject(const FilePath &filePath)
{
if (!filePath.isEmpty()) {
ProjectExplorerPlugin::OpenProjectResult result
= ProjectExplorerPlugin::openProject(filePath);
OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
}

View File

@@ -43,6 +43,46 @@ class MiniProjectTargetSelector;
using RecentProjectsEntry = QPair<Utils::FilePath, QString>;
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
{
Q_OBJECT
@@ -56,45 +96,6 @@ public:
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 openProjects(const Utils::FilePaths &filePaths);
static void showOpenProjectError(const OpenProjectResult &result);

View File

@@ -637,7 +637,7 @@ void ProjectManagerPrivate::restoreProjects(const FilePaths &fileList)
// Keep projects that failed to load in the session!
m_failedProjects = fileList;
if (!fileList.isEmpty()) {
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProjects(fileList);
OpenProjectResult result = ProjectExplorerPlugin::openProjects(fileList);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
const QList<Project *> projects = result.projects();

View File

@@ -114,7 +114,7 @@ bool CmakeProjectConverter::convertProject(const QmlProjectManager::QmlProject *
if (retVal) {
QMessageBox::information(Core::ICore::dialogParent(), SUCCESS_TITLE, SUCCESS_TEXT);
ProjectExplorer::ProjectExplorerPlugin::OpenProjectResult result
ProjectExplorer::OpenProjectResult result
= ProjectExplorer::ProjectExplorerPlugin::openProject(newProjectFile());
if (!result)
ProjectExplorer::ProjectExplorerPlugin::showOpenProjectError(result);

View File

@@ -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
if (proFile.isEmpty())
return;
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(proFile);
OpenProjectResult result = ProjectExplorerPlugin::openProject(proFile);
if (result) {
ICore::openFiles(filesToOpen);
ModeManager::activateMode(Core::Constants::MODE_EDIT);

View File

@@ -252,7 +252,7 @@ public:
const FilePath projectFile = FilePath::fromVariant(
data(index(row, 0), ProjectModel::FilePathRole));
if (projectFile.exists()) {
const ProjectExplorerPlugin::OpenProjectResult result
const OpenProjectResult result
= ProjectExplorer::ProjectExplorerPlugin::openProject(projectFile);
if (!result && !result.alreadyOpen().isEmpty()) {
const auto fileToOpen = getMainUiFileWithFallback();