forked from qt-creator/qt-creator
MainWindow: Use FileUtils::get... functions
Changes the MainWindow to use FileUtils::getFilePaths function to access files on devices instead of QFileDialog. Change-Id: I0981c960b643edd69510cfed1cce16346962d75a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -1032,11 +1032,12 @@ void DocumentManager::showFilePropertiesDialog(const FilePath &filePath)
|
||||
|
||||
FilePaths DocumentManager::getOpenFileNames(const QString &filters,
|
||||
const FilePath &pathIn,
|
||||
QString *selectedFilter)
|
||||
QString *selectedFilter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
const FilePath path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
|
||||
const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters,
|
||||
selectedFilter);
|
||||
selectedFilter, options);
|
||||
if (!files.isEmpty())
|
||||
setFileDialogLastVisitedDirectory(files.front().absolutePath());
|
||||
return files;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
|
||||
@@ -64,7 +65,8 @@ public:
|
||||
|
||||
static Utils::FilePaths getOpenFileNames(const QString &filters,
|
||||
const Utils::FilePath &path = {},
|
||||
QString *selectedFilter = nullptr);
|
||||
QString *selectedFilter = nullptr,
|
||||
QFileDialog::Options options = {});
|
||||
static Utils::FilePath getSaveFileName(const QString &title,
|
||||
const Utils::FilePath &pathIn,
|
||||
const QString &filter = {},
|
||||
|
||||
@@ -3249,11 +3249,11 @@ void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)>
|
||||
|
||||
\sa DocumentManager::getOpenFileNames()
|
||||
*/
|
||||
FilePaths EditorManager::getOpenFilePaths()
|
||||
FilePaths EditorManager::getOpenFilePaths(QFileDialog::Options options)
|
||||
{
|
||||
QString selectedFilter;
|
||||
const QString &fileFilters = DocumentManager::fileDialogFilter(&selectedFilter);
|
||||
return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter);
|
||||
return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter, options);
|
||||
}
|
||||
|
||||
static QString makeTitleUnique(QString *titlePattern)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "utils/link.h"
|
||||
#include "utils/textfileformat.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QList>
|
||||
#include <QWidget>
|
||||
|
||||
@@ -90,7 +91,7 @@ public:
|
||||
static bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId);
|
||||
static void addCloseEditorListener(const std::function<bool(IEditor *)> &listener);
|
||||
|
||||
static Utils::FilePaths getOpenFilePaths();
|
||||
static Utils::FilePaths getOpenFilePaths(QFileDialog::Options options = {});
|
||||
|
||||
static IDocument *currentDocument();
|
||||
static IEditor *currentEditor();
|
||||
|
||||
@@ -1078,37 +1078,7 @@ void MainWindow::openFileWith()
|
||||
|
||||
void MainWindow::openFileFromDevice()
|
||||
{
|
||||
QSettings *settings = PluginManager::settings();
|
||||
settings->beginGroup(QLatin1String(settingsGroup));
|
||||
QVariant dialogSettings = settings->value(QLatin1String(openFromDeviceDialogKey));
|
||||
|
||||
QFileDialog dialog;
|
||||
dialog.setOption(QFileDialog::DontUseNativeDialog);
|
||||
if (!dialogSettings.isNull()) {
|
||||
dialog.restoreState(dialogSettings.toByteArray());
|
||||
}
|
||||
QList<QUrl> sideBarUrls = Utils::transform(Utils::filtered(FSEngine::registeredDeviceRoots(),
|
||||
[](const auto &filePath) {
|
||||
return filePath.exists();
|
||||
}),
|
||||
[](const auto &filePath) {
|
||||
return QUrl::fromLocalFile(filePath.toFSPathString());
|
||||
});
|
||||
dialog.setSidebarUrls(sideBarUrls);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
dialog.setIconProvider(FileIconProvider::iconProvider());
|
||||
|
||||
if (dialog.exec()) {
|
||||
FilePaths filePaths = Utils::transform(dialog.selectedFiles(), [](const auto &path) {
|
||||
return FilePath::fromString(path);
|
||||
});
|
||||
|
||||
openFiles(filePaths, ICore::SwitchMode);
|
||||
}
|
||||
|
||||
settings->setValue(QLatin1String(openFromDeviceDialogKey), dialog.saveState());
|
||||
settings->endGroup();
|
||||
openFiles(EditorManager::getOpenFilePaths(QFileDialog::DontUseNativeDialog), ICore::SwitchMode);
|
||||
}
|
||||
|
||||
IContext *MainWindow::contextObject(QWidget *widget) const
|
||||
|
||||
Reference in New Issue
Block a user