Use the new file dialog wrappers in some places

Change-Id: I326c883f2f76593e6fcb0f3e376d387273312982
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-07-26 17:41:28 +02:00
parent ef1653698e
commit b8f369c436
5 changed files with 34 additions and 44 deletions

View File

@@ -566,32 +566,28 @@ void DiffEditorPluginPrivate::diffOpenFiles()
void DiffEditorPluginPrivate::diffExternalFiles() void DiffEditorPluginPrivate::diffExternalFiles()
{ {
const QString fileName1 = QFileDialog::getOpenFileName(ICore::dialogParent(), const FilePath filePath1 = FileUtils::getOpenFilePath(tr("Select First File for Diff"));
tr("Select First File for Diff"), if (filePath1.isEmpty())
QString());
if (fileName1.isNull())
return; return;
if (EditorManager::skipOpeningBigTextFile(FilePath::fromString(fileName1))) if (EditorManager::skipOpeningBigTextFile(filePath1))
return; return;
const QString fileName2 = QFileDialog::getOpenFileName(ICore::dialogParent(), const FilePath filePath2 = FileUtils::getOpenFilePath(tr("Select Second File for Diff"));
tr("Select Second File for Diff"), if (filePath2.isEmpty())
QString());
if (fileName2.isNull())
return; return;
if (EditorManager::skipOpeningBigTextFile(FilePath::fromString(fileName2))) if (EditorManager::skipOpeningBigTextFile(filePath2))
return; return;
const QString documentId = Constants::DIFF_EDITOR_PLUGIN const QString documentId = QLatin1String(Constants::DIFF_EDITOR_PLUGIN)
+ QLatin1String(".DiffExternalFiles.") + fileName1 + QLatin1Char('.') + fileName2; + ".DiffExternalFiles." + filePath1.toString() + '.' + filePath2.toString();
const QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1, fileName2); const QString title = tr("Diff \"%1\", \"%2\"").arg(filePath1.toString(), filePath2.toString());
auto const document = qobject_cast<DiffEditorDocument *>( auto const document = qobject_cast<DiffEditorDocument *>(
DiffEditorController::findOrCreateDocument(documentId, title)); DiffEditorController::findOrCreateDocument(documentId, title));
if (!document) if (!document)
return; return;
if (!DiffEditorController::controller(document)) if (!DiffEditorController::controller(document))
new DiffExternalFilesController(document, fileName1, fileName2); new DiffExternalFilesController(document, filePath1.toString(), filePath2.toString());
EditorManager::activateEditorForDocument(document); EditorManager::activateEditorForDocument(document);
document->reload(); document->reload();
} }

View File

@@ -720,12 +720,10 @@ Utils::FilePath Project::projectDirectory(const Utils::FilePath &top)
void Project::changeRootProjectDirectory() void Project::changeRootProjectDirectory()
{ {
Utils::FilePath rootPath = Utils::FilePath::fromString( Utils::FilePath rootPath = Utils::FileUtils::getExistingDirectory(
QFileDialog::getExistingDirectory(Core::ICore::dialogParent(), tr("Select the Root Directory"),
tr("Select the Root Directory"), rootProjectDirectory(),
rootProjectDirectory().toString(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks));
if (rootPath != d->m_rootProjectDirectory) { if (rootPath != d->m_rootProjectDirectory) {
d->m_rootProjectDirectory = rootPath; d->m_rootProjectDirectory = rootPath;
setNamedSettings(Constants::PROJECT_ROOT_PATH_KEY, d->m_rootProjectDirectory.toString()); setNamedSettings(Constants::PROJECT_ROOT_PATH_KEY, d->m_rootProjectDirectory.toString());

View File

@@ -3577,24 +3577,24 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
projectNode = currentNode->asContainerNode()->rootProjectNode(); projectNode = currentNode->asContainerNode()->rootProjectNode();
QTC_ASSERT(projectNode, return); QTC_ASSERT(projectNode, return);
const FilePath dir = currentNode->directory(); const FilePath dir = currentNode->directory();
QStringList subProjectFilePaths = QFileDialog::getOpenFileNames( FilePaths subProjectFilePaths = Utils::FileUtils::getOpenFilePaths(
ICore::dialogParent(), tr("Choose Project File"), dir.toString(), tr("Choose Project File"), dir,
projectNode->subProjectFileNamePatterns().join(";;")); projectNode->subProjectFileNamePatterns().join(";;"));
if (!ProjectTree::hasNode(projectNode)) if (!ProjectTree::hasNode(projectNode))
return; return;
const QList<Node *> childNodes = projectNode->nodes(); const QList<Node *> childNodes = projectNode->nodes();
Utils::erase(subProjectFilePaths, [childNodes](const QString &filePath) { Utils::erase(subProjectFilePaths, [childNodes](const FilePath &filePath) {
return Utils::anyOf(childNodes, [filePath](const Node *n) { return Utils::anyOf(childNodes, [filePath](const Node *n) {
return n->filePath().toString() == filePath; return n->filePath() == filePath;
}); });
}); });
if (subProjectFilePaths.empty()) if (subProjectFilePaths.empty())
return; return;
QStringList failedProjects; FilePaths failedProjects;
QStringList addedProjects; QStringList addedProjects;
for (const QString &filePath : qAsConst(subProjectFilePaths)) { for (const FilePath &filePath : qAsConst(subProjectFilePaths)) {
if (projectNode->addSubProject(filePath)) if (projectNode->addSubProject(filePath.toString()))
addedProjects << filePath; addedProjects << filePath.toString();
else else
failedProjects << filePath; failedProjects << filePath;
} }
@@ -3602,7 +3602,7 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
const QString message = tr("The following subprojects could not be added to project " const QString message = tr("The following subprojects could not be added to project "
"\"%1\":").arg(projectNode->managingProject()->displayName()); "\"%1\":").arg(projectNode->managingProject()->displayName());
QMessageBox::warning(ICore::dialogParent(), tr("Adding Subproject Failed"), QMessageBox::warning(ICore::dialogParent(), tr("Adding Subproject Failed"),
message + "\n " + failedProjects.join("\n ")); message + "\n " + FilePath::formatFilePaths(failedProjects, "\n "));
return; return;
} }
VcsManager::promptToAdd(dir.toString(), addedProjects); VcsManager::promptToAdd(dir.toString(), addedProjects);
@@ -3615,13 +3615,12 @@ void ProjectExplorerPluginPrivate::handleAddExistingFiles()
QTC_ASSERT(folderNode, return); QTC_ASSERT(folderNode, return);
QStringList fileNames = QFileDialog::getOpenFileNames(ICore::dialogParent(), const FilePaths filePaths =
tr("Add Existing Files"), node->directory().toString()); Utils::FileUtils::getOpenFilePaths(tr("Add Existing Files"), node->directory());
if (fileNames.isEmpty()) if (filePaths.isEmpty())
return; return;
ProjectExplorerPlugin::addExistingFiles(folderNode, ProjectExplorerPlugin::addExistingFiles(folderNode, filePaths);
Utils::transform(fileNames, &FilePath::fromString));
} }
void ProjectExplorerPluginPrivate::addExistingDirectory() void ProjectExplorerPluginPrivate::addExistingDirectory()

View File

@@ -754,15 +754,13 @@ public:
ProjectImporter *projectImporter = project ? project->projectImporter() : nullptr; ProjectImporter *projectImporter = project ? project->projectImporter() : nullptr;
QTC_ASSERT(projectImporter, return); QTC_ASSERT(projectImporter, return);
QString dir = project->projectDirectory().toString(); FilePath importDir =
QString importDir = QFileDialog::getExistingDirectory(ICore::dialogParent(), Utils::FileUtils::getExistingDirectory(ProjectWindow::tr("Import Directory"),
ProjectWindow::tr("Import Directory"), project->projectDirectory());
dir);
FilePath path = FilePath::fromString(importDir);
Target *lastTarget = nullptr; Target *lastTarget = nullptr;
BuildConfiguration *lastBc = nullptr; BuildConfiguration *lastBc = nullptr;
for (const BuildInfo &info : projectImporter->import(path, false)) { for (const BuildInfo &info : projectImporter->import(importDir, false)) {
Target *target = project->target(info.kitId); Target *target = project->target(info.kitId);
if (!target) if (!target)
target = project->addTargetForKit(KitManager::kit(info.kitId)); target = project->addTargetForKit(KitManager::kit(info.kitId));

View File

@@ -239,12 +239,11 @@ QString FileExtractor::targetPath() const
void FileExtractor::browse() void FileExtractor::browse()
{ {
const QString path = QFileDialog::getExistingDirectory(Core::ICore::dialogParent(), const Utils::FilePath path =
(tr("Choose Directory")), Utils::FileUtils::getExistingDirectory(tr("Choose Directory"), m_targetPath);
m_targetPath.toString());
if (!path.isEmpty()) if (!path.isEmpty())
m_targetPath = Utils::FilePath::fromString(path); m_targetPath = path;
emit targetPathChanged(); emit targetPathChanged();
emit targetFolderExistsChanged(); emit targetFolderExistsChanged();