forked from qt-creator/qt-creator
Core: Use FilePath in some functions related to opening files
Change-Id: I9610855a914d315d7934996c755fb69ad399320f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -279,8 +279,10 @@ QObject *CorePlugin::remoteCommand(const QStringList & /* options */,
|
|||||||
});
|
});
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const FilePaths filePaths = Utils::transform(args, FilePath::fromString);
|
||||||
IDocument *res = MainWindow::openFiles(
|
IDocument *res = MainWindow::openFiles(
|
||||||
args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible),
|
filePaths,
|
||||||
|
ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible),
|
||||||
workingDirectory);
|
workingDirectory);
|
||||||
m_mainWindow->raiseWindow();
|
m_mainWindow->raiseWindow();
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
#include <coreplugin/editormanager/iexternaleditor.h>
|
#include <coreplugin/editormanager/iexternaleditor.h>
|
||||||
|
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.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.
|
dialog in if that is not overridden by the user's policy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QStringList DocumentManager::getOpenFileNames(const QString &filters,
|
FilePaths DocumentManager::getOpenFileNames(const QString &filters,
|
||||||
const QString &pathIn,
|
const FilePath &pathIn,
|
||||||
QString *selectedFilter)
|
QString *selectedFilter)
|
||||||
{
|
{
|
||||||
const QString &path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
|
const FilePath path = pathIn.isEmpty() ? FilePath::fromString(fileDialogInitialDirectory())
|
||||||
const QStringList files = QFileDialog::getOpenFileNames(ICore::dialogParent(),
|
: pathIn;
|
||||||
tr("Open File"),
|
const FilePaths files = FileUtils::getOpenFilePaths(tr("Open File"),
|
||||||
path, filters,
|
path, filters,
|
||||||
selectedFilter);
|
selectedFilter);
|
||||||
if (!files.isEmpty())
|
if (!files.isEmpty())
|
||||||
setFileDialogLastVisitedDirectory(QFileInfo(files.front()).absolutePath());
|
setFileDialogLastVisitedDirectory(files.front().absolutePath().toString());
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,9 @@ public:
|
|||||||
|
|
||||||
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
|
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
|
||||||
|
|
||||||
static QStringList getOpenFileNames(const QString &filters,
|
static Utils::FilePaths getOpenFileNames(const QString &filters,
|
||||||
const QString &path = QString(),
|
const Utils::FilePath &path = {},
|
||||||
QString *selectedFilter = nullptr);
|
QString *selectedFilter = nullptr);
|
||||||
static QString getSaveFileName(const QString &title,
|
static QString getSaveFileName(const QString &title,
|
||||||
const QString &pathIn,
|
const QString &pathIn,
|
||||||
const QString &filter = QString(),
|
const QString &filter = QString(),
|
||||||
|
|||||||
@@ -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.
|
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;
|
QString selectedFilter;
|
||||||
const QString &fileFilters = DocumentManager::allDocumentFactoryFiltersString(&selectedFilter);
|
const QString &fileFilters = DocumentManager::allDocumentFactoryFiltersString(&selectedFilter);
|
||||||
return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
|
return DocumentManager::getOpenFileNames(fileFilters, {}, &selectedFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString makeTitleUnique(QString *titlePattern)
|
static QString makeTitleUnique(QString *titlePattern)
|
||||||
|
|||||||
@@ -118,7 +118,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 QStringList getOpenFileNames();
|
static Utils::FilePaths getOpenFilePaths();
|
||||||
|
|
||||||
static IDocument *currentDocument();
|
static IDocument *currentDocument();
|
||||||
static IEditor *currentEditor();
|
static IEditor *currentEditor();
|
||||||
|
|||||||
@@ -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
|
done if they were given to \QC on the command line, or
|
||||||
they were opened via \uicontrol File > \uicontrol Open.
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public:
|
|||||||
StopOnLoadFail = 4,
|
StopOnLoadFail = 4,
|
||||||
SwitchSplitIfAlreadyVisible = 8
|
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);
|
static void addPreCloseListener(const std::function<bool()> &listener);
|
||||||
|
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ void MainWindow::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
|
|||||||
{
|
{
|
||||||
raiseWindow();
|
raiseWindow();
|
||||||
QStringList filePaths = Utils::transform(files, &DropSupport::FileSpec::filePath);
|
QStringList filePaths = Utils::transform(files, &DropSupport::FileSpec::filePath);
|
||||||
openFiles(filePaths, ICore::SwitchMode);
|
openFiles(Utils::transform(filePaths, &FilePath::fromString), ICore::SwitchMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
IContext *MainWindow::currentContextObject() const
|
IContext *MainWindow::currentContextObject() const
|
||||||
@@ -852,7 +852,7 @@ void MainWindow::registerModeSelectorStyleActions()
|
|||||||
|
|
||||||
void MainWindow::openFile()
|
void MainWindow::openFile()
|
||||||
{
|
{
|
||||||
openFiles(EditorManager::getOpenFileNames(), ICore::SwitchMode);
|
openFiles(EditorManager::getOpenFilePaths(), ICore::SwitchMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories,
|
static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories,
|
||||||
@@ -866,7 +866,7 @@ static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fil
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \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
|
* \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.
|
* 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()
|
* \sa IPlugin::remoteArguments()
|
||||||
*/
|
*/
|
||||||
IDocument *MainWindow::openFiles(const QStringList &fileNames,
|
IDocument *MainWindow::openFiles(const FilePaths &filePaths,
|
||||||
ICore::OpenFilesFlags flags,
|
ICore::OpenFilesFlags flags,
|
||||||
const QString &workingDirectory)
|
const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
const QList<IDocumentFactory*> documentFactories = IDocumentFactory::allDocumentFactories();
|
const QList<IDocumentFactory*> documentFactories = IDocumentFactory::allDocumentFactories();
|
||||||
IDocument *res = nullptr;
|
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 QDir workingDir(workingDirectory.isEmpty() ? QDir::currentPath() : workingDirectory);
|
||||||
const QFileInfo fi(workingDir, fileName);
|
const QFileInfo fi(workingDir, fileName);
|
||||||
const QString absoluteFilePath = fi.absoluteFilePath();
|
const QString absoluteFilePath = fi.absoluteFilePath();
|
||||||
@@ -947,15 +948,16 @@ void MainWindow::exit()
|
|||||||
|
|
||||||
void MainWindow::openFileWith()
|
void MainWindow::openFileWith()
|
||||||
{
|
{
|
||||||
foreach (const QString &fileName, EditorManager::getOpenFileNames()) {
|
const FilePaths filePaths = EditorManager::getOpenFilePaths();
|
||||||
|
for (const FilePath &filePath : filePaths) {
|
||||||
bool isExternal;
|
bool isExternal;
|
||||||
const Id editorId = EditorManagerPrivate::getOpenWithEditorId(fileName, &isExternal);
|
const Id editorId = EditorManagerPrivate::getOpenWithEditorId(filePath.toString(), &isExternal);
|
||||||
if (!editorId.isValid())
|
if (!editorId.isValid())
|
||||||
continue;
|
continue;
|
||||||
if (isExternal)
|
if (isExternal)
|
||||||
EditorManager::openExternalEditor(FilePath::fromString(fileName), editorId);
|
EditorManager::openExternalEditor(filePath, editorId);
|
||||||
else
|
else
|
||||||
EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
|
EditorManagerPrivate::openEditorWith(filePath, editorId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public:
|
|||||||
void addContextObject(IContext *context);
|
void addContextObject(IContext *context);
|
||||||
void removeContextObject(IContext *context);
|
void removeContextObject(IContext *context);
|
||||||
|
|
||||||
static IDocument *openFiles(const QStringList &fileNames,
|
static IDocument *openFiles(const Utils::FilePaths &filePaths,
|
||||||
ICore::OpenFilesFlags flags,
|
ICore::OpenFilesFlags flags,
|
||||||
const QString &workingDirectory = QString());
|
const QString &workingDirectory = QString());
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,8 @@
|
|||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
const int PATH_ROLE = Qt::UserRole;
|
const int PATH_ROLE = Qt::UserRole;
|
||||||
const int ID_ROLE = Qt::UserRole + 1;
|
const int ID_ROLE = Qt::UserRole + 1;
|
||||||
const int SORT_ROLE = Qt::UserRole + 2;
|
const int SORT_ROLE = Qt::UserRole + 2;
|
||||||
@@ -679,7 +681,7 @@ void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
const QStringList projectFiles = projectsInDirectory(index);
|
const QStringList projectFiles = projectsInDirectory(index);
|
||||||
if (!projectFiles.isEmpty())
|
if (!projectFiles.isEmpty())
|
||||||
Core::ICore::openFiles(projectFiles);
|
Core::ICore::openFiles(Utils::transform(projectFiles, &FilePath::fromString));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderNavigationWidget::createNewFolder(const QModelIndex &parent)
|
void FolderNavigationWidget::createNewFolder(const QModelIndex &parent)
|
||||||
|
|||||||
@@ -2566,7 +2566,8 @@ void ProjectExplorerPluginPrivate::restoreSession()
|
|||||||
dd->m_arguments = arguments;
|
dd->m_arguments = arguments;
|
||||||
// delay opening projects from the command line even more
|
// delay opening projects from the command line even more
|
||||||
QTimer::singleShot(0, m_instance, []() {
|
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();
|
emit m_instance->finishedInitialization();
|
||||||
});
|
});
|
||||||
updateActions();
|
updateActions();
|
||||||
@@ -4075,10 +4076,10 @@ bool ProjectExplorerPlugin::isProjectFile(const FilePath &filePath)
|
|||||||
|
|
||||||
void ProjectExplorerPlugin::openOpenProjectDialog()
|
void ProjectExplorerPlugin::openOpenProjectDialog()
|
||||||
{
|
{
|
||||||
const QString path = DocumentManager::useProjectsDirectory()
|
const FilePath path = DocumentManager::useProjectsDirectory()
|
||||||
? DocumentManager::projectsDirectory().toString()
|
? DocumentManager::projectsDirectory()
|
||||||
: QString();
|
: FilePath();
|
||||||
const QStringList files = DocumentManager::getOpenFileNames(dd->m_projectFilterString, path);
|
const FilePaths files = DocumentManager::getOpenFileNames(dd->m_projectFilterString, path);
|
||||||
if (!files.isEmpty())
|
if (!files.isEmpty())
|
||||||
ICore::openFiles(files, ICore::SwitchMode);
|
ICore::openFiles(files, ICore::SwitchMode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ void ExamplesWelcomePage::openProject(const ExampleItem *item)
|
|||||||
ProjectExplorerPlugin::OpenProjectResult result =
|
ProjectExplorerPlugin::OpenProjectResult result =
|
||||||
ProjectExplorerPlugin::openProject(FilePath::fromString(proFile));
|
ProjectExplorerPlugin::openProject(FilePath::fromString(proFile));
|
||||||
if (result) {
|
if (result) {
|
||||||
ICore::openFiles(filesToOpen);
|
ICore::openFiles(Utils::transform(filesToOpen, &FilePath::fromString));
|
||||||
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
||||||
QUrl docUrl = QUrl::fromUserInput(item->docUrl);
|
QUrl docUrl = QUrl::fromUserInput(item->docUrl);
|
||||||
if (docUrl.isValid())
|
if (docUrl.isValid())
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ bool WelcomeMode::openDroppedFiles(const QList<QUrl> &urls)
|
|||||||
const QList<QUrl> localUrls = Utils::filtered(urls, &QUrl::isLocalFile);
|
const QList<QUrl> localUrls = Utils::filtered(urls, &QUrl::isLocalFile);
|
||||||
if (!localUrls.isEmpty()) {
|
if (!localUrls.isEmpty()) {
|
||||||
QTimer::singleShot(0, [localUrls]() {
|
QTimer::singleShot(0, [localUrls]() {
|
||||||
ICore::openFiles(Utils::transform(localUrls, &QUrl::toLocalFile), ICore::SwitchMode);
|
ICore::openFiles(Utils::transform(localUrls, &FilePath::fromUrl), ICore::SwitchMode);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user