diff options
author | hjk <hjk@qt.io> | 2021-07-23 10:33:02 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2021-07-29 11:14:46 +0000 |
commit | 906cfb060bc717ccd1ea81bf0384068c342f3b48 (patch) | |
tree | 278ccdba034c08eb337ff70bf1fb06394a5afacb | |
parent | dbdea46f6677f68b3438773972e292c759afad06 (diff) | |
download | qt-creator-906cfb060bc717ccd1ea81bf0384068c342f3b48.tar.gz |
Core: Use FilePath in some functions related to opening files
Change-Id: I9610855a914d315d7934996c755fb69ad399320f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/coreplugin/coreplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/documentmanager.cpp | 19 | ||||
-rw-r--r-- | src/plugins/coreplugin/documentmanager.h | 6 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 6 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.cpp | 6 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.cpp | 20 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.h | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/foldernavigationwidget.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 11 | ||||
-rw-r--r-- | src/plugins/qtsupport/gettingstartedwelcomepage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/welcome/welcomeplugin.cpp | 2 |
13 files changed, 46 insertions, 40 deletions
diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 647636b8f1..75c18dfeb7 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -279,8 +279,10 @@ QObject *CorePlugin::remoteCommand(const QStringList & /* options */, }); return nullptr; } + const FilePaths filePaths = Utils::transform(args, FilePath::fromString); IDocument *res = MainWindow::openFiles( - args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible), + filePaths, + ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible), workingDirectory); m_mainWindow->raiseWindow(); return res; diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 037f54b4ef..b636ce02d4 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -44,7 +44,6 @@ #include <coreplugin/editormanager/ieditorfactory.h> #include <coreplugin/editormanager/iexternaleditor.h> - #include <extensionsystem/pluginmanager.h> #include <utils/algorithm.h> @@ -1034,17 +1033,17 @@ void DocumentManager::showFilePropertiesDialog(const FilePath &filePath) dialog in if that is not overridden by the user's policy. */ -QStringList DocumentManager::getOpenFileNames(const QString &filters, - const QString &pathIn, - QString *selectedFilter) +FilePaths DocumentManager::getOpenFileNames(const QString &filters, + const FilePath &pathIn, + QString *selectedFilter) { - const QString &path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn; - const QStringList files = QFileDialog::getOpenFileNames(ICore::dialogParent(), - tr("Open File"), - path, filters, - selectedFilter); + const FilePath path = pathIn.isEmpty() ? FilePath::fromString(fileDialogInitialDirectory()) + : pathIn; + const FilePaths files = FileUtils::getOpenFilePaths(tr("Open File"), + path, filters, + selectedFilter); if (!files.isEmpty()) - setFileDialogLastVisitedDirectory(QFileInfo(files.front()).absolutePath()); + setFileDialogLastVisitedDirectory(files.front().absolutePath().toString()); return files; } diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index d96efd088d..b3cc073697 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -84,9 +84,9 @@ public: static QString allDocumentFactoryFiltersString(QString *allFilesFilter); - static QStringList getOpenFileNames(const QString &filters, - const QString &path = QString(), - QString *selectedFilter = nullptr); + static Utils::FilePaths getOpenFileNames(const QString &filters, + const Utils::FilePath &path = {}, + QString *selectedFilter = nullptr); static QString getSaveFileName(const QString &title, const QString &pathIn, const QString &filter = QString(), diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index ce178bb2fb..444504999e 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -3190,13 +3190,13 @@ void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)> /*! Asks the user for a list of files to open and returns the choice. - \sa DocumentManager::getOpenFileNames() + \sa DocumentManager::getOpenFilePaths() */ -QStringList EditorManager::getOpenFileNames() +FilePaths EditorManager::getOpenFilePaths() { QString selectedFilter; const QString &fileFilters = DocumentManager::allDocumentFactoryFiltersString(&selectedFilter); - return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter); + return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter); } static QString makeTitleUnique(QString *titlePattern) diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 84f7842b65..0c56805947 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -118,7 +118,7 @@ public: static bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId); static void addCloseEditorListener(const std::function<bool(IEditor *)> &listener); - static QStringList getOpenFileNames(); + static Utils::FilePaths getOpenFilePaths(); static IDocument *currentDocument(); static IEditor *currentEditor(); diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index 73bcc5e793..25d89899ea 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -804,14 +804,14 @@ void ICore::registerWindow(QWidget *window, const Context &context) } /*! - Opens files using \a arguments and \a flags like it would be + Opens files using \a filePaths and \a flags like it would be done if they were given to \QC on the command line, or they were opened via \uicontrol File > \uicontrol Open. */ -void ICore::openFiles(const QStringList &arguments, ICore::OpenFilesFlags flags) +void ICore::openFiles(const FilePaths &filePaths, ICore::OpenFilesFlags flags) { - MainWindow::openFiles(arguments, flags); + MainWindow::openFiles(filePaths, flags); } /*! diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h index 2e02fb43f8..5aa7314d95 100644 --- a/src/plugins/coreplugin/icore.h +++ b/src/plugins/coreplugin/icore.h @@ -133,7 +133,7 @@ public: StopOnLoadFail = 4, SwitchSplitIfAlreadyVisible = 8 }; - static void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None); + static void openFiles(const Utils::FilePaths &filePaths, OpenFilesFlags flags = None); static void addPreCloseListener(const std::function<bool()> &listener); diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 6bcb343ca5..b8d1263b42 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -390,7 +390,7 @@ void MainWindow::openDroppedFiles(const QList<DropSupport::FileSpec> &files) { raiseWindow(); QStringList filePaths = Utils::transform(files, &DropSupport::FileSpec::filePath); - openFiles(filePaths, ICore::SwitchMode); + openFiles(Utils::transform(filePaths, &FilePath::fromString), ICore::SwitchMode); } IContext *MainWindow::currentContextObject() const @@ -852,7 +852,7 @@ void MainWindow::registerModeSelectorStyleActions() void MainWindow::openFile() { - openFiles(EditorManager::getOpenFileNames(), ICore::SwitchMode); + openFiles(EditorManager::getOpenFilePaths(), ICore::SwitchMode); } static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories, @@ -866,7 +866,7 @@ static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fil /*! * \internal - * Either opens \a fileNames with editors or loads a project. + * Either opens \a filePaths with editors or loads a project. * * \a flags can be used to stop on first failure, indicate that a file name * might include line numbers and/or switch mode to edit mode. @@ -879,14 +879,15 @@ static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fil * * \sa IPlugin::remoteArguments() */ -IDocument *MainWindow::openFiles(const QStringList &fileNames, +IDocument *MainWindow::openFiles(const FilePaths &filePaths, ICore::OpenFilesFlags flags, const QString &workingDirectory) { const QList<IDocumentFactory*> documentFactories = IDocumentFactory::allDocumentFactories(); IDocument *res = nullptr; - for (const QString &fileName : fileNames) { + for (const FilePath &filePath : filePaths) { + const QString fileName = filePath.toString(); const QDir workingDir(workingDirectory.isEmpty() ? QDir::currentPath() : workingDirectory); const QFileInfo fi(workingDir, fileName); const QString absoluteFilePath = fi.absoluteFilePath(); @@ -947,15 +948,16 @@ void MainWindow::exit() void MainWindow::openFileWith() { - foreach (const QString &fileName, EditorManager::getOpenFileNames()) { + const FilePaths filePaths = EditorManager::getOpenFilePaths(); + for (const FilePath &filePath : filePaths) { bool isExternal; - const Id editorId = EditorManagerPrivate::getOpenWithEditorId(fileName, &isExternal); + const Id editorId = EditorManagerPrivate::getOpenWithEditorId(filePath.toString(), &isExternal); if (!editorId.isValid()) continue; if (isExternal) - EditorManager::openExternalEditor(FilePath::fromString(fileName), editorId); + EditorManager::openExternalEditor(filePath, editorId); else - EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId); + EditorManagerPrivate::openEditorWith(filePath, editorId); } } diff --git a/src/plugins/coreplugin/mainwindow.h b/src/plugins/coreplugin/mainwindow.h index 746dd93fc4..4631986c58 100644 --- a/src/plugins/coreplugin/mainwindow.h +++ b/src/plugins/coreplugin/mainwindow.h @@ -89,7 +89,7 @@ public: void addContextObject(IContext *context); void removeContextObject(IContext *context); - static IDocument *openFiles(const QStringList &fileNames, + static IDocument *openFiles(const Utils::FilePaths &filePaths, ICore::OpenFilesFlags flags, const QString &workingDirectory = QString()); diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index b445741332..9670292be0 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -75,6 +75,8 @@ #include <QToolButton> #include <QVBoxLayout> +using namespace Utils; + const int PATH_ROLE = Qt::UserRole; const int ID_ROLE = Qt::UserRole + 1; const int SORT_ROLE = Qt::UserRole + 2; @@ -679,7 +681,7 @@ void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index) { const QStringList projectFiles = projectsInDirectory(index); if (!projectFiles.isEmpty()) - Core::ICore::openFiles(projectFiles); + Core::ICore::openFiles(Utils::transform(projectFiles, &FilePath::fromString)); } void FolderNavigationWidget::createNewFolder(const QModelIndex &parent) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 1ee8fc23ac..10a96bd0f5 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2566,7 +2566,8 @@ void ProjectExplorerPluginPrivate::restoreSession() dd->m_arguments = arguments; // delay opening projects from the command line even more QTimer::singleShot(0, m_instance, []() { - ICore::openFiles(dd->m_arguments, ICore::OpenFilesFlags(ICore::CanContainLineAndColumnNumbers | ICore::SwitchMode)); + ICore::openFiles(Utils::transform(dd->m_arguments, &FilePath::fromString), + ICore::OpenFilesFlags(ICore::CanContainLineAndColumnNumbers | ICore::SwitchMode)); emit m_instance->finishedInitialization(); }); updateActions(); @@ -4075,10 +4076,10 @@ bool ProjectExplorerPlugin::isProjectFile(const FilePath &filePath) void ProjectExplorerPlugin::openOpenProjectDialog() { - const QString path = DocumentManager::useProjectsDirectory() - ? DocumentManager::projectsDirectory().toString() - : QString(); - const QStringList files = DocumentManager::getOpenFileNames(dd->m_projectFilterString, path); + const FilePath path = DocumentManager::useProjectsDirectory() + ? DocumentManager::projectsDirectory() + : FilePath(); + const FilePaths files = DocumentManager::getOpenFileNames(dd->m_projectFilterString, path); if (!files.isEmpty()) ICore::openFiles(files, ICore::SwitchMode); } diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp index 18197bd4c2..f8ea269bd2 100644 --- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp +++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp @@ -207,7 +207,7 @@ void ExamplesWelcomePage::openProject(const ExampleItem *item) ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(FilePath::fromString(proFile)); if (result) { - ICore::openFiles(filesToOpen); + ICore::openFiles(Utils::transform(filesToOpen, &FilePath::fromString)); ModeManager::activateMode(Core::Constants::MODE_EDIT); QUrl docUrl = QUrl::fromUserInput(item->docUrl); if (docUrl.isValid()) diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index 3561ea621d..cf0bd101b5 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -399,7 +399,7 @@ bool WelcomeMode::openDroppedFiles(const QList<QUrl> &urls) const QList<QUrl> localUrls = Utils::filtered(urls, &QUrl::isLocalFile); if (!localUrls.isEmpty()) { QTimer::singleShot(0, [localUrls]() { - ICore::openFiles(Utils::transform(localUrls, &QUrl::toLocalFile), ICore::SwitchMode); + ICore::openFiles(Utils::transform(localUrls, &FilePath::fromUrl), ICore::SwitchMode); }); return true; } |