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

View File

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

View File

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

View File

@@ -754,15 +754,13 @@ public:
ProjectImporter *projectImporter = project ? project->projectImporter() : nullptr;
QTC_ASSERT(projectImporter, return);
QString dir = project->projectDirectory().toString();
QString importDir = QFileDialog::getExistingDirectory(ICore::dialogParent(),
ProjectWindow::tr("Import Directory"),
dir);
FilePath path = FilePath::fromString(importDir);
FilePath importDir =
Utils::FileUtils::getExistingDirectory(ProjectWindow::tr("Import Directory"),
project->projectDirectory());
Target *lastTarget = 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);
if (!target)
target = project->addTargetForKit(KitManager::kit(info.kitId));

View File

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