forked from qt-creator/qt-creator
Utils: Provide FilePath based wrappers for common dialogs
Change-Id: I464a7b5775495f32648905335f2d798384867900 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -405,5 +405,76 @@ void withNtfsPermissions(const std::function<void()> &task)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace Utils
|
|
||||||
|
|
||||||
|
#ifdef QT_WIDGETS_LIB
|
||||||
|
|
||||||
|
static std::function<QWidget *()> s_dialogParentGetter;
|
||||||
|
|
||||||
|
void FileUtils::setDialogParentGetter(const std::function<QWidget *()> &getter)
|
||||||
|
{
|
||||||
|
s_dialogParentGetter = getter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QWidget *dialogParent()
|
||||||
|
{
|
||||||
|
return s_dialogParentGetter ? s_dialogParentGetter() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath FileUtils::getOpenFilePath(const QString &caption,
|
||||||
|
const FilePath &dir,
|
||||||
|
const QString &filter,
|
||||||
|
QString *selectedFilter,
|
||||||
|
QFileDialog::Options options)
|
||||||
|
{
|
||||||
|
const QString result = QFileDialog::getOpenFileName(dialogParent(),
|
||||||
|
caption,
|
||||||
|
dir.toString(),
|
||||||
|
filter,
|
||||||
|
selectedFilter,
|
||||||
|
options);
|
||||||
|
return FilePath::fromString(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath FileUtils::getSaveFilePath(const QString &caption,
|
||||||
|
const FilePath &dir,
|
||||||
|
const QString &filter,
|
||||||
|
QString *selectedFilter,
|
||||||
|
QFileDialog::Options options)
|
||||||
|
{
|
||||||
|
const QString result = QFileDialog::getSaveFileName(dialogParent(),
|
||||||
|
caption,
|
||||||
|
dir.toString(),
|
||||||
|
filter,
|
||||||
|
selectedFilter,
|
||||||
|
options);
|
||||||
|
return FilePath::fromString(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath FileUtils::getExistingDirectory(const QString &caption,
|
||||||
|
const FilePath &dir,
|
||||||
|
QFileDialog::Options options)
|
||||||
|
{
|
||||||
|
const QString result = QFileDialog::getExistingDirectory(dialogParent(),
|
||||||
|
caption,
|
||||||
|
dir.toString(),
|
||||||
|
options);
|
||||||
|
return FilePath::fromString(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePaths FileUtils::getOpenFilePaths(const QString &caption,
|
||||||
|
const FilePath &dir,
|
||||||
|
const QString &filter,
|
||||||
|
QString *selectedFilter,
|
||||||
|
QFileDialog::Options options)
|
||||||
|
{
|
||||||
|
const QStringList result = QFileDialog::getOpenFileNames(dialogParent(),
|
||||||
|
caption,
|
||||||
|
dir.toString(),
|
||||||
|
filter,
|
||||||
|
selectedFilter,
|
||||||
|
options);
|
||||||
|
return transform(result, &FilePath::fromString);
|
||||||
|
}
|
||||||
|
#endif // QT_WIDGETS_LIB
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
@@ -38,6 +38,10 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QXmlStreamWriter> // Mac.
|
#include <QXmlStreamWriter> // Mac.
|
||||||
|
|
||||||
|
#ifdef QT_WIDGETS_LIB
|
||||||
|
#include <QFileDialog>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -128,6 +132,32 @@ public:
|
|||||||
static bool renameFile(const FilePath &srcFilePath, const FilePath &tgtFilePath);
|
static bool renameFile(const FilePath &srcFilePath, const FilePath &tgtFilePath);
|
||||||
|
|
||||||
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
||||||
|
|
||||||
|
#ifdef QT_WIDGETS_LIB
|
||||||
|
static void setDialogParentGetter(const std::function<QWidget *()> &getter);
|
||||||
|
|
||||||
|
static FilePath getOpenFilePath(const QString &caption = {},
|
||||||
|
const FilePath &dir = {},
|
||||||
|
const QString &filter = {},
|
||||||
|
QString *selectedFilter = nullptr,
|
||||||
|
QFileDialog::Options options = {});
|
||||||
|
|
||||||
|
static FilePath getSaveFilePath(const QString &caption = {},
|
||||||
|
const FilePath &dir = {},
|
||||||
|
const QString &filter = {},
|
||||||
|
QString *selectedFilter = nullptr,
|
||||||
|
QFileDialog::Options options = {});
|
||||||
|
|
||||||
|
static FilePath getExistingDirectory(const QString &caption = {},
|
||||||
|
const FilePath &dir = {},
|
||||||
|
QFileDialog::Options options = QFileDialog::ShowDirsOnly);
|
||||||
|
|
||||||
|
static FilePaths getOpenFilePaths(const QString &caption = {},
|
||||||
|
const FilePath &dir = {},
|
||||||
|
const QString &filter = {},
|
||||||
|
QString *selectedFilter = nullptr,
|
||||||
|
QFileDialog::Options options = {});
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@@ -214,6 +214,8 @@ ICore::ICore(MainWindow *mainwindow)
|
|||||||
emit coreAboutToClose();
|
emit coreAboutToClose();
|
||||||
QCoreApplication::exit(exitCode);
|
QCoreApplication::exit(exitCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
FileUtils::setDialogParentGetter(&ICore::dialogParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Reference in New Issue
Block a user