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,
|
FilePaths DocumentManager::getOpenFileNames(const QString &filters,
|
||||||
const FilePath &pathIn,
|
const FilePath &pathIn,
|
||||||
QString *selectedFilter)
|
QString *selectedFilter,
|
||||||
|
QFileDialog::Options options)
|
||||||
{
|
{
|
||||||
const FilePath path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
|
const FilePath path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
|
||||||
const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters,
|
const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters,
|
||||||
selectedFilter);
|
selectedFilter, options);
|
||||||
if (!files.isEmpty())
|
if (!files.isEmpty())
|
||||||
setFileDialogLastVisitedDirectory(files.front().absolutePath());
|
setFileDialogLastVisitedDirectory(files.front().absolutePath());
|
||||||
return files;
|
return files;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
|
||||||
@@ -64,7 +65,8 @@ public:
|
|||||||
|
|
||||||
static Utils::FilePaths getOpenFileNames(const QString &filters,
|
static Utils::FilePaths getOpenFileNames(const QString &filters,
|
||||||
const Utils::FilePath &path = {},
|
const Utils::FilePath &path = {},
|
||||||
QString *selectedFilter = nullptr);
|
QString *selectedFilter = nullptr,
|
||||||
|
QFileDialog::Options options = {});
|
||||||
static Utils::FilePath getSaveFileName(const QString &title,
|
static Utils::FilePath getSaveFileName(const QString &title,
|
||||||
const Utils::FilePath &pathIn,
|
const Utils::FilePath &pathIn,
|
||||||
const QString &filter = {},
|
const QString &filter = {},
|
||||||
|
|||||||
@@ -3249,11 +3249,11 @@ void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)>
|
|||||||
|
|
||||||
\sa DocumentManager::getOpenFileNames()
|
\sa DocumentManager::getOpenFileNames()
|
||||||
*/
|
*/
|
||||||
FilePaths EditorManager::getOpenFilePaths()
|
FilePaths EditorManager::getOpenFilePaths(QFileDialog::Options options)
|
||||||
{
|
{
|
||||||
QString selectedFilter;
|
QString selectedFilter;
|
||||||
const QString &fileFilters = DocumentManager::fileDialogFilter(&selectedFilter);
|
const QString &fileFilters = DocumentManager::fileDialogFilter(&selectedFilter);
|
||||||
return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter);
|
return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString makeTitleUnique(QString *titlePattern)
|
static QString makeTitleUnique(QString *titlePattern)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "utils/link.h"
|
#include "utils/link.h"
|
||||||
#include "utils/textfileformat.h"
|
#include "utils/textfileformat.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ public:
|
|||||||
static bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId);
|
static bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId);
|
||||||
static void addCloseEditorListener(const std::function<bool(IEditor *)> &listener);
|
static void addCloseEditorListener(const std::function<bool(IEditor *)> &listener);
|
||||||
|
|
||||||
static Utils::FilePaths getOpenFilePaths();
|
static Utils::FilePaths getOpenFilePaths(QFileDialog::Options options = {});
|
||||||
|
|
||||||
static IDocument *currentDocument();
|
static IDocument *currentDocument();
|
||||||
static IEditor *currentEditor();
|
static IEditor *currentEditor();
|
||||||
|
|||||||
@@ -1078,37 +1078,7 @@ void MainWindow::openFileWith()
|
|||||||
|
|
||||||
void MainWindow::openFileFromDevice()
|
void MainWindow::openFileFromDevice()
|
||||||
{
|
{
|
||||||
QSettings *settings = PluginManager::settings();
|
openFiles(EditorManager::getOpenFilePaths(QFileDialog::DontUseNativeDialog), ICore::SwitchMode);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IContext *MainWindow::contextObject(QWidget *widget) const
|
IContext *MainWindow::contextObject(QWidget *widget) const
|
||||||
|
|||||||
Reference in New Issue
Block a user