forked from qt-creator/qt-creator
Core: Use FilePath in IDocumentFactory::open()
Change-Id: I369f3bba2e0d1d33fed3a29f3c1408429cc7d8f8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -46,10 +46,10 @@ const QList<IDocumentFactory *> IDocumentFactory::allDocumentFactories()
|
||||
return g_documentFactories;
|
||||
}
|
||||
|
||||
IDocument *IDocumentFactory::open(const QString &filename)
|
||||
IDocument *IDocumentFactory::open(const Utils::FilePath &filePath)
|
||||
{
|
||||
QTC_ASSERT(m_opener, return nullptr);
|
||||
return m_opener(filename);
|
||||
return m_opener(filePath);
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace Core {
|
||||
|
||||
class IDocument;
|
||||
@@ -45,8 +47,8 @@ public:
|
||||
|
||||
static const QList<IDocumentFactory *> allDocumentFactories();
|
||||
|
||||
using Opener = std::function<IDocument *(const QString &fileName)>;
|
||||
IDocument *open(const QString &filename);
|
||||
using Opener = std::function<IDocument *(const Utils::FilePath &filePath)>;
|
||||
IDocument *open(const Utils::FilePath &filePath);
|
||||
|
||||
QStringList mimeTypes() const { return m_mimeTypes; }
|
||||
|
||||
|
||||
@@ -892,7 +892,7 @@ IDocument *MainWindow::openFiles(const FilePaths &filePaths,
|
||||
const QFileInfo fi(workingDir, fileName);
|
||||
const QString absoluteFilePath = fi.absoluteFilePath();
|
||||
if (IDocumentFactory *documentFactory = findDocumentFactory(documentFactories, filePath)) {
|
||||
IDocument *document = documentFactory->open(absoluteFilePath);
|
||||
IDocument *document = documentFactory->open(FilePath::fromString(absoluteFilePath));
|
||||
if (!document) {
|
||||
if (flags & ICore::StopOnLoadFail)
|
||||
return res;
|
||||
|
||||
@@ -2081,12 +2081,15 @@ void ProjectExplorerPlugin::extensionsInitialized()
|
||||
const QString filterSeparator = QLatin1String(";;");
|
||||
QStringList filterStrings;
|
||||
|
||||
dd->m_documentFactory.setOpener([](QString fileName) {
|
||||
const QFileInfo fi(fileName);
|
||||
if (fi.isDir())
|
||||
fileName = FolderNavigationWidget::projectFilesInDirectory(fi.absoluteFilePath()).value(0, fileName);
|
||||
dd->m_documentFactory.setOpener([](FilePath filePath) {
|
||||
if (filePath.isDir()) {
|
||||
const QStringList files =
|
||||
FolderNavigationWidget::projectFilesInDirectory(filePath.absoluteFilePath().toString());
|
||||
if (!files.isEmpty())
|
||||
filePath = FilePath::fromString(files.front());
|
||||
}
|
||||
|
||||
OpenProjectResult result = ProjectExplorerPlugin::openProject(FilePath::fromString(fileName));
|
||||
OpenProjectResult result = ProjectExplorerPlugin::openProject(filePath);
|
||||
if (!result)
|
||||
showOpenProjectError(result);
|
||||
return nullptr;
|
||||
|
||||
@@ -209,8 +209,8 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
|
||||
TaskHub::addCategory(Constants::TASKLISTTASK_ID, tr("My Tasks"));
|
||||
|
||||
d->m_fileFactory.addMimeType(QLatin1String("text/x-tasklist"));
|
||||
d->m_fileFactory.setOpener([this](const QString &fileName) {
|
||||
return openTasks(FilePath::fromString(fileName));
|
||||
d->m_fileFactory.setOpener([this](const FilePath &filePath) {
|
||||
return openTasks(filePath);
|
||||
});
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
|
||||
|
||||
Reference in New Issue
Block a user