aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2021-07-16 17:31:41 +0200
committerhjk <hjk@qt.io>2021-07-27 11:35:47 +0000
commit9b250ea2c0b1a4a6960d6d311082caf1c52e7c86 (patch)
tree23f13024eda06d96466df432182571ce4ce5fc73 /src/plugins
parent2b4f5749ab041e22ac09ca44df374fefc5dad574 (diff)
ProjectExplorer: Use FilePath in ProjectExplorer::openProject{,s}()
Change-Id: Ibfb7ab5ef7226b85452bd37b840408708935453b Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp2
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp4
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp4
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp4
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizard.cpp2
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.cpp2
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp8
-rw-r--r--src/plugins/projectexplorer/project.cpp3
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp38
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h4
-rw-r--r--src/plugins/projectexplorer/session.cpp38
-rw-r--r--src/plugins/qtsupport/gettingstartedwelcomepage.cpp3
12 files changed, 58 insertions, 54 deletions
diff --git a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp
index bb45147eb87..fb9f303f31b 100644
--- a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp
+++ b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp
@@ -232,7 +232,7 @@ bool OpenProjectCommand::run()
qCDebug(debug) << "line" << context().lineNumber << "OpenProjectCommand" << m_projectFilePath;
const ProjectExplorerPlugin::OpenProjectResult openProjectSucceeded
- = ProjectExplorerPlugin::openProject(m_projectFilePath);
+ = ProjectExplorerPlugin::openProject(Utils::FilePath::fromString(m_projectFilePath));
QTC_ASSERT(openProjectSucceeded, return false);
Project *project = openProjectSucceeded.project();
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index 1e3b55d0c36..8d50f5b6abd 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -41,7 +41,9 @@
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <qtsupport/qtkitinformation.h>
+
#include <utils/algorithm.h>
+#include <utils/filepath.h>
#include <utils/textutils.h>
#include <QEventLoop>
@@ -108,7 +110,7 @@ void ClangdTest::initTestCase()
.baseName().toLocal8Bit()));
QVERIFY(m_projectDir->isValid());
const auto openProjectResult = ProjectExplorerPlugin::openProject(
- m_projectDir->absolutePath(m_projectFileName.toUtf8()));
+ Utils::FilePath::fromString(m_projectDir->absolutePath(m_projectFileName.toUtf8())));
QVERIFY2(openProjectResult, qPrintable(openProjectResult.errorMessage()));
m_project = openProjectResult.project();
m_project->configureAsExampleProject(m_kit);
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 9af92352c38..dd8c521a92d 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -329,7 +329,9 @@ F2TestCase::F2TestCase(CppEditorAction action,
TestDocument projectFile(projectFileContent.toUtf8(), "project.qbs");
projectFile.setBaseDirectory(temporaryDir.path());
QVERIFY(projectFile.writeToDisk());
- const auto openProjectResult = ProjectExplorerPlugin::openProject(projectFile.filePath());
+ const auto openProjectResult =
+ ProjectExplorerPlugin::openProject(
+ Utils::FilePath::fromString(projectFile.filePath()));
QVERIFY2(openProjectResult && openProjectResult.project(),
qPrintable(openProjectResult.errorMessage()));
projectCloser.setProject(openProjectResult.project());
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index e9a6e85d0d5..887f7afd42d 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -50,6 +50,7 @@
#include <QtTest>
using namespace ProjectExplorer;
+using namespace Utils;
static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors)
{
@@ -282,7 +283,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject,
Kit *kit)
{
- ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile);
+ ProjectExplorerPlugin::OpenProjectResult result =
+ ProjectExplorerPlugin::openProject(FilePath::fromString(projectFile));
if (!result) {
qWarning() << result.errorMessage() << result.alreadyOpen();
return ProjectInfo();
diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp
index 5b8a3f697f0..0a3d2a118cd 100644
--- a/src/plugins/projectexplorer/customwizard/customwizard.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp
@@ -560,7 +560,7 @@ bool CustomProjectWizard::postGenerateOpen(const Core::GeneratedFiles &l, QStrin
foreach (const Core::GeneratedFile &file, l) {
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
ProjectExplorerPlugin::OpenProjectResult result
- = ProjectExplorerPlugin::openProject(file.path());
+ = ProjectExplorerPlugin::openProject(file.filePath());
if (!result) {
if (errorMessage)
*errorMessage = result.errorMessage();
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp
index 0b33b88309e..b445741332f 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.cpp
+++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp
@@ -792,7 +792,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
if (action == actionOpenFile) {
openItem(current);
} else if (action == actionOpenAsProject) {
- ProjectExplorerPlugin::openProject(filePath.toString());
+ ProjectExplorerPlugin::openProject(filePath);
} else if (action == actionOpenProjects)
openProjectsInDirectory(current);
else if (action == newFolder) {
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
index 5ea23a05222..b9c6a661dd3 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
@@ -447,18 +447,18 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
if (!QFileInfo::exists(file.path())) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"\"%1\" does not exist in the file system.")
- .arg(QDir::toNativeSeparators(file.path()));
+ .arg(file.filePath().toUserOutput());
break;
}
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
ProjectExplorerPlugin::OpenProjectResult result
- = ProjectExplorerPlugin::openProject(file.path());
+ = ProjectExplorerPlugin::openProject(file.filePath());
if (!result) {
errorMessage = result.errorMessage();
if (errorMessage.isEmpty()) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"Failed to open \"%1\" as a project.")
- .arg(QDir::toNativeSeparators(file.path()));
+ .arg(file.filePath().toUserOutput());
}
break;
}
@@ -470,7 +470,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
if (!editor) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"Failed to open an editor for \"%1\".")
- .arg(QDir::toNativeSeparators(file.path()));
+ .arg(file.filePath().toUserOutput());
break;
} else if (file.attributes() & Core::GeneratedFile::TemporaryFile) {
editor->document()->setTemporary(true);
diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp
index 25fe115afd3..89a61abb38d 100644
--- a/src/plugins/projectexplorer/project.cpp
+++ b/src/plugins/projectexplorer/project.cpp
@@ -1312,8 +1312,7 @@ void ProjectExplorerPlugin::testProject_multipleBuildConfigs()
const QFileInfoList files = QDir(projectDir.toString()).entryInfoList(QDir::Files | QDir::Dirs);
for (const QFileInfo &f : files)
QFile(f.absoluteFilePath()).setPermissions(f.permissions() | QFile::WriteUser);
- const auto theProject = openProject(projectDir.pathAppended("generic-project.creator")
- .toString());
+ const auto theProject = openProject(projectDir.pathAppended("generic-project.creator"));
QVERIFY2(theProject, qPrintable(theProject.errorMessage()));
theProject.project()->configureAsExampleProject(kit);
QCOMPARE(theProject.project()->targets().size(), 1);
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index a14a0405109..66506d08930 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1998,13 +1998,12 @@ void ProjectExplorerPluginPrivate::loadAction()
dir = isProject ? fn : QFileInfo(fn).absolutePath();
}
- QString filename = QFileDialog::getOpenFileName(ICore::dialogParent(),
- tr("Load Project"), dir,
- dd->m_projectFilterString);
- if (filename.isEmpty())
+ FilePath filePath = Utils::FileUtils::getOpenFilePath(tr("Load Project"), FilePath::fromString(dir),
+ dd->m_projectFilterString);
+ if (filePath.isEmpty())
return;
- ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(filename);
+ ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
@@ -2088,7 +2087,7 @@ void ProjectExplorerPlugin::extensionsInitialized()
if (fi.isDir())
fileName = FolderNavigationWidget::projectFilesInDirectory(fi.absoluteFilePath()).value(0, fileName);
- OpenProjectResult result = ProjectExplorerPlugin::openProject(fileName);
+ OpenProjectResult result = ProjectExplorerPlugin::openProject(FilePath::fromString(fileName));
if (!result)
showOpenProjectError(result);
return nullptr;
@@ -2329,18 +2328,18 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
{
- OpenProjectResult result = openProject(fileName);
+ OpenProjectResult result = openProject(FilePath::fromString(fileName));
if (!result)
showOpenProjectError(result);
}
-ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(const QString &fileName)
+ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(const FilePath &filePath)
{
- OpenProjectResult result = openProjects(QStringList(fileName));
+ OpenProjectResult result = openProjects({filePath});
Project *project = result.project();
if (!project)
return result;
- dd->addToRecentProjects(fileName, project->displayName());
+ dd->addToRecentProjects(filePath.toString(), project->displayName());
SessionManager::setStartupProject(project);
return result;
}
@@ -2384,16 +2383,15 @@ static void appendError(QString &errorString, const QString &error)
errorString.append(error);
}
-ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
+ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths)
{
QList<Project*> openedPro;
QList<Project *> alreadyOpen;
QString errorString;
- foreach (const QString &fileName, fileNames) {
+ for (const FilePath &fileName : filePaths) {
QTC_ASSERT(!fileName.isEmpty(), continue);
+ const FilePath filePath = fileName.absoluteFilePath();
- const QFileInfo fi(fileName);
- const auto filePath = Utils::FilePath::fromString(fi.absoluteFilePath());
Project *found = Utils::findOrDefault(SessionManager::projects(),
Utils::equal(&Project::projectFilePath, filePath));
if (found) {
@@ -2402,11 +2400,11 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
continue;
}
- Utils::MimeType mt = Utils::mimeTypeForFile(fileName);
+ MimeType mt = Utils::mimeTypeForFile(filePath);
if (ProjectManager::canOpenProjectForMimeType(mt)) {
- if (!filePath.toFileInfo().isFile()) {
+ if (!filePath.isFile()) {
appendError(errorString,
- tr("Failed opening project \"%1\": Project is not a file.").arg(fileName));
+ tr("Failed opening project \"%1\": Project is not a file.").arg(filePath.toUserOutput()));
} else if (Project *pro = ProjectManager::openProject(mt, filePath)) {
QString restoreError;
Project::RestoreResult restoreResult = pro->restoreSettings(&restoreError);
@@ -2423,10 +2421,10 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
}
} else {
appendError(errorString, tr("Failed opening project \"%1\": No plugin can open project type \"%2\".")
- .arg(QDir::toNativeSeparators(fileName))
+ .arg(filePath.toUserOutput())
.arg(mt.name()));
}
- if (fileNames.size() > 1)
+ if (filePaths.size() > 1)
SessionManager::reportProjectLoadingProgress();
}
dd->updateActions();
@@ -3286,7 +3284,7 @@ void ProjectExplorerPluginPrivate::openRecentProject(const QString &fileName)
{
if (!fileName.isEmpty()) {
ProjectExplorerPlugin::OpenProjectResult result
- = ProjectExplorerPlugin::openProject(fileName);
+ = ProjectExplorerPlugin::openProject(FilePath::fromString(fileName));
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
}
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index aad380c85b7..9333367d592 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -116,8 +116,8 @@ public:
QString m_errorMessage;
};
- static OpenProjectResult openProject(const QString &fileName);
- static OpenProjectResult openProjects(const QStringList &fileNames);
+ static OpenProjectResult openProject(const Utils::FilePath &filePath);
+ static OpenProjectResult openProjects(const Utils::FilePaths &filePaths);
static void showOpenProjectError(const OpenProjectResult &result);
static void openProjectWelcomePage(const QString &fileName);
static void unloadProject(Project *project);
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index ce9a28546c6..7f3fd32723c 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -85,7 +85,7 @@ public:
void restoreDependencies(const PersistentSettingsReader &reader);
void restoreStartupProject(const PersistentSettingsReader &reader);
void restoreEditors(const PersistentSettingsReader &reader);
- void restoreProjects(const QStringList &fileList);
+ void restoreProjects(const Utils::FilePaths &fileList);
void askUserAboutFailedProjects();
void sessionLoadingProgress();
@@ -109,7 +109,7 @@ public:
Project *m_startupProject = nullptr;
QList<Project *> m_projects;
- QStringList m_failedProjects;
+ FilePaths m_failedProjects;
QMap<QString, QStringList> m_depMap;
QMap<QString, QVariant> m_values;
QFutureInterface<void> m_future;
@@ -501,18 +501,17 @@ bool SessionManager::save()
data.insert(QLatin1String("Color"), tmp);
}
- QStringList projectFiles = Utils::transform(projects(), [](Project *p) {
- return p->projectFilePath().toString();
- });
+ FilePaths projectFiles = Utils::transform(projects(), &Project::projectFilePath);
// Restore information on projects that failed to load:
// don't read projects to the list, which the user loaded
- foreach (const QString &failed, d->m_failedProjects) {
+ for (const FilePath &failed : qAsConst(d->m_failedProjects)) {
if (!projectFiles.contains(failed))
projectFiles << failed;
}
- data.insert(QLatin1String("ProjectList"), projectFiles);
- data.insert(QLatin1String("CascadeSetActive"), d->m_casadeSetActive);
+ data.insert("ProjectList", Utils::transform<QStringList>(projectFiles,
+ &FilePath::toString));
+ data.insert("CascadeSetActive", d->m_casadeSetActive);
QVariantMap depMap;
auto i = d->m_depMap.constBegin();
@@ -903,10 +902,9 @@ void SessionManagerPrivate::restoreDependencies(const PersistentSettingsReader &
void SessionManagerPrivate::askUserAboutFailedProjects()
{
- QStringList failedProjects = m_failedProjects;
+ FilePaths failedProjects = m_failedProjects;
if (!failedProjects.isEmpty()) {
- QString fileList =
- QDir::toNativeSeparators(failedProjects.join(QLatin1String("<br>")));
+ QString fileList = FilePath::formatFilePaths(failedProjects, "<br>");
QMessageBox box(QMessageBox::Warning,
SessionManager::tr("Failed to restore project files"),
SessionManager::tr("Could not restore the following project files:<br><b>%1</b>").
@@ -954,7 +952,7 @@ void SessionManagerPrivate::restoreEditors(const PersistentSettingsReader &reade
/*!
Loads a session, takes a session name (not filename).
*/
-void SessionManagerPrivate::restoreProjects(const QStringList &fileList)
+void SessionManagerPrivate::restoreProjects(const FilePaths &fileList)
{
// indirectly adds projects to session
// Keep projects that failed to load in the session!
@@ -964,7 +962,7 @@ void SessionManagerPrivate::restoreProjects(const QStringList &fileList)
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
foreach (Project *p, result.projects())
- m_failedProjects.removeAll(p->projectFilePath().toString());
+ m_failedProjects.removeAll(p->projectFilePath());
}
}
@@ -1008,7 +1006,7 @@ bool SessionManager::loadSession(const QString &session, bool initial)
if (!loadImplicitDefault && !sessions().contains(session))
return false;
- QStringList fileList;
+ FilePaths fileList;
// Try loading the file
FilePath fileName = sessionNameToFileName(loadImplicitDefault ? "default" : session);
PersistentSettingsReader reader;
@@ -1026,7 +1024,8 @@ bool SessionManager::loadSession(const QString &session, bool initial)
return true;
}
- fileList = reader.restoreValue(QLatin1String("ProjectList")).toStringList();
+ fileList = Utils::transform(reader.restoreValue("ProjectList").toStringList(),
+ &FilePath::fromString);
} else if (loadImplicitDefault) {
return true;
}
@@ -1049,12 +1048,12 @@ bool SessionManager::loadSession(const QString &session, bool initial)
// find a list of projects to close later
const QList<Project *> projectsToRemove = Utils::filtered(projects(), [&fileList](Project *p) {
- return !fileList.contains(p->projectFilePath().toString());
+ return !fileList.contains(p->projectFilePath());
});
const QList<Project *> openProjects = projects();
- const QStringList projectPathsToLoad = Utils::filtered(fileList, [&openProjects](const QString &path) {
+ const FilePaths projectPathsToLoad = Utils::filtered(fileList, [&openProjects](const FilePath &path) {
return !Utils::contains(openProjects, [&path](Project *p) {
- return p->projectFilePath().toString() == path;
+ return p->projectFilePath() == path;
});
});
d->m_failedProjects.clear();
@@ -1202,7 +1201,8 @@ void ProjectExplorerPlugin::testSessionSwitch()
sessionSpec.projectFile.close();
QVERIFY(SessionManager::loadSession(sessionSpec.name));
const OpenProjectResult openResult
- = ProjectExplorerPlugin::openProject(sessionSpec.projectFile.fileName());
+ = ProjectExplorerPlugin::openProject(
+ FilePath::fromString(sessionSpec.projectFile.fileName()));
if (openResult.errorMessage().contains("text/plain"))
QSKIP("This test requires the presence of QmakeProjectManager to be fully functional");
QVERIFY(openResult);
diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
index bd93f8407f1..18197bd4c23 100644
--- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
+++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
@@ -204,7 +204,8 @@ void ExamplesWelcomePage::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);
+ ProjectExplorerPlugin::OpenProjectResult result =
+ ProjectExplorerPlugin::openProject(FilePath::fromString(proFile));
if (result) {
ICore::openFiles(filesToOpen);
ModeManager::activateMode(Core::Constants::MODE_EDIT);