forked from qt-creator/qt-creator
Utils: Pass dialog parent to Utils::* file dialog
Amends 3edc5673b5
.
Turns out quite a few potential uses have other parents than
ICore::dialogParent().
Use a nullptr parent to mean ICore::dialogParent() to keep the
caller side simple.
Change-Id: Icfe1daafd710ae273d286679e0c8e2a3a27da552
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -429,18 +429,19 @@ void FileUtils::setDialogParentGetter(const std::function<QWidget *()> &getter)
|
||||
s_dialogParentGetter = getter;
|
||||
}
|
||||
|
||||
static QWidget *dialogParent()
|
||||
static QWidget *dialogParent(QWidget *parent)
|
||||
{
|
||||
return s_dialogParentGetter ? s_dialogParentGetter() : nullptr;
|
||||
return parent ? parent : s_dialogParentGetter ? s_dialogParentGetter() : nullptr;
|
||||
}
|
||||
|
||||
FilePath FileUtils::getOpenFilePath(const QString &caption,
|
||||
FilePath FileUtils::getOpenFilePath(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
const QString result = QFileDialog::getOpenFileName(dialogParent(),
|
||||
const QString result = QFileDialog::getOpenFileName(dialogParent(parent),
|
||||
caption,
|
||||
dir.toString(),
|
||||
filter,
|
||||
@@ -449,13 +450,14 @@ FilePath FileUtils::getOpenFilePath(const QString &caption,
|
||||
return FilePath::fromString(result);
|
||||
}
|
||||
|
||||
FilePath FileUtils::getSaveFilePath(const QString &caption,
|
||||
FilePath FileUtils::getSaveFilePath(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
const QString result = QFileDialog::getSaveFileName(dialogParent(),
|
||||
const QString result = QFileDialog::getSaveFileName(dialogParent(parent),
|
||||
caption,
|
||||
dir.toString(),
|
||||
filter,
|
||||
@@ -464,24 +466,26 @@ FilePath FileUtils::getSaveFilePath(const QString &caption,
|
||||
return FilePath::fromString(result);
|
||||
}
|
||||
|
||||
FilePath FileUtils::getExistingDirectory(const QString &caption,
|
||||
FilePath FileUtils::getExistingDirectory(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
const QString result = QFileDialog::getExistingDirectory(dialogParent(),
|
||||
const QString result = QFileDialog::getExistingDirectory(dialogParent(parent),
|
||||
caption,
|
||||
dir.toString(),
|
||||
options);
|
||||
return FilePath::fromString(result);
|
||||
}
|
||||
|
||||
FilePaths FileUtils::getOpenFilePaths(const QString &caption,
|
||||
FilePaths FileUtils::getOpenFilePaths(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
const QStringList result = QFileDialog::getOpenFileNames(dialogParent(),
|
||||
const QStringList result = QFileDialog::getOpenFileNames(dialogParent(parent),
|
||||
caption,
|
||||
dir.toString(),
|
||||
filter,
|
||||
|
@@ -138,23 +138,27 @@ public:
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
static void setDialogParentGetter(const std::function<QWidget *()> &getter);
|
||||
|
||||
static FilePath getOpenFilePath(const QString &caption = {},
|
||||
static FilePath getOpenFilePath(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir = {},
|
||||
const QString &filter = {},
|
||||
QString *selectedFilter = nullptr,
|
||||
QFileDialog::Options options = {});
|
||||
|
||||
static FilePath getSaveFilePath(const QString &caption = {},
|
||||
static FilePath getSaveFilePath(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir = {},
|
||||
const QString &filter = {},
|
||||
QString *selectedFilter = nullptr,
|
||||
QFileDialog::Options options = {});
|
||||
|
||||
static FilePath getExistingDirectory(const QString &caption = {},
|
||||
static FilePath getExistingDirectory(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir = {},
|
||||
QFileDialog::Options options = QFileDialog::ShowDirsOnly);
|
||||
|
||||
static FilePaths getOpenFilePaths(const QString &caption = {},
|
||||
static FilePaths getOpenFilePaths(QWidget *parent,
|
||||
const QString &caption,
|
||||
const FilePath &dir = {},
|
||||
const QString &filter = {},
|
||||
QString *selectedFilter = nullptr,
|
||||
|
@@ -1039,8 +1039,7 @@ FilePaths DocumentManager::getOpenFileNames(const QString &filters,
|
||||
{
|
||||
const FilePath path = pathIn.isEmpty() ? FilePath::fromString(fileDialogInitialDirectory())
|
||||
: pathIn;
|
||||
const FilePaths files = FileUtils::getOpenFilePaths(tr("Open File"),
|
||||
path, filters,
|
||||
const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters,
|
||||
selectedFilter);
|
||||
if (!files.isEmpty())
|
||||
setFileDialogLastVisitedDirectory(files.front().absolutePath().toString());
|
||||
|
@@ -566,13 +566,13 @@ void DiffEditorPluginPrivate::diffOpenFiles()
|
||||
|
||||
void DiffEditorPluginPrivate::diffExternalFiles()
|
||||
{
|
||||
const FilePath filePath1 = FileUtils::getOpenFilePath(tr("Select First File for Diff"));
|
||||
const FilePath filePath1 = FileUtils::getOpenFilePath(nullptr, tr("Select First File for Diff"));
|
||||
if (filePath1.isEmpty())
|
||||
return;
|
||||
if (EditorManager::skipOpeningBigTextFile(filePath1))
|
||||
return;
|
||||
|
||||
const FilePath filePath2 = FileUtils::getOpenFilePath(tr("Select Second File for Diff"));
|
||||
const FilePath filePath2 = FileUtils::getOpenFilePath(nullptr, tr("Select Second File for Diff"));
|
||||
if (filePath2.isEmpty())
|
||||
return;
|
||||
if (EditorManager::skipOpeningBigTextFile(filePath2))
|
||||
|
@@ -885,7 +885,7 @@ void PerforcePluginPrivate::filelogCurrentFile()
|
||||
|
||||
void PerforcePluginPrivate::filelogFile()
|
||||
{
|
||||
const FilePath file = FileUtils::getOpenFilePath(tr("p4 filelog"));
|
||||
const FilePath file = FileUtils::getOpenFilePath(nullptr, tr("p4 filelog"));
|
||||
if (!file.isEmpty())
|
||||
filelog(file.parentDir(), file.fileName());
|
||||
}
|
||||
|
@@ -721,6 +721,7 @@ Utils::FilePath Project::projectDirectory(const Utils::FilePath &top)
|
||||
void Project::changeRootProjectDirectory()
|
||||
{
|
||||
Utils::FilePath rootPath = Utils::FileUtils::getExistingDirectory(
|
||||
nullptr,
|
||||
tr("Select the Root Directory"),
|
||||
rootProjectDirectory(),
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
@@ -1997,7 +1997,8 @@ void ProjectExplorerPluginPrivate::loadAction()
|
||||
dir = isProject ? fn : QFileInfo(fn).absolutePath();
|
||||
}
|
||||
|
||||
FilePath filePath = Utils::FileUtils::getOpenFilePath(tr("Load Project"), FilePath::fromString(dir),
|
||||
FilePath filePath = Utils::FileUtils::getOpenFilePath(nullptr,
|
||||
tr("Load Project"), FilePath::fromString(dir),
|
||||
dd->m_projectFilterString);
|
||||
if (filePath.isEmpty())
|
||||
return;
|
||||
@@ -3578,7 +3579,7 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
|
||||
QTC_ASSERT(projectNode, return);
|
||||
const FilePath dir = currentNode->directory();
|
||||
FilePaths subProjectFilePaths = Utils::FileUtils::getOpenFilePaths(
|
||||
tr("Choose Project File"), dir,
|
||||
nullptr, tr("Choose Project File"), dir,
|
||||
projectNode->subProjectFileNamePatterns().join(";;"));
|
||||
if (!ProjectTree::hasNode(projectNode))
|
||||
return;
|
||||
@@ -3616,7 +3617,7 @@ void ProjectExplorerPluginPrivate::handleAddExistingFiles()
|
||||
QTC_ASSERT(folderNode, return);
|
||||
|
||||
const FilePaths filePaths =
|
||||
Utils::FileUtils::getOpenFilePaths(tr("Add Existing Files"), node->directory());
|
||||
Utils::FileUtils::getOpenFilePaths(nullptr, tr("Add Existing Files"), node->directory());
|
||||
if (filePaths.isEmpty())
|
||||
return;
|
||||
|
||||
|
@@ -755,7 +755,7 @@ public:
|
||||
QTC_ASSERT(projectImporter, return);
|
||||
|
||||
FilePath importDir =
|
||||
Utils::FileUtils::getExistingDirectory(ProjectWindow::tr("Import Directory"),
|
||||
FileUtils::getExistingDirectory(nullptr, ProjectWindow::tr("Import Directory"),
|
||||
project->projectDirectory());
|
||||
|
||||
Target *lastTarget = nullptr;
|
||||
|
@@ -41,6 +41,8 @@
|
||||
#include <QQuickItem>
|
||||
#include <QQuickWidget>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
ExampleCheckout::ExampleCheckout(QObject *) {}
|
||||
|
||||
void ExampleCheckout::checkoutExample(const QUrl &url)
|
||||
@@ -239,8 +241,8 @@ QString FileExtractor::targetPath() const
|
||||
|
||||
void FileExtractor::browse()
|
||||
{
|
||||
const Utils::FilePath path =
|
||||
Utils::FileUtils::getExistingDirectory(tr("Choose Directory"), m_targetPath);
|
||||
const FilePath path =
|
||||
FileUtils::getExistingDirectory(nullptr, tr("Choose Directory"), m_targetPath);
|
||||
|
||||
if (!path.isEmpty())
|
||||
m_targetPath = path;
|
||||
|
@@ -644,7 +644,7 @@ void VcsBasePluginPrivate::createRepository()
|
||||
// Prompt for a directory that is not under version control yet
|
||||
QWidget *mw = ICore::dialogParent();
|
||||
do {
|
||||
directory = FileUtils::getExistingDirectory(tr("Choose Repository Directory"), directory);
|
||||
directory = FileUtils::getExistingDirectory(nullptr, tr("Choose Repository Directory"), directory);
|
||||
if (directory.isEmpty())
|
||||
return;
|
||||
const IVersionControl *managingControl = VcsManager::findVersionControlForDirectory(directory);
|
||||
|
Reference in New Issue
Block a user