Commit 4eeb9dc0 authored by Friedemann Kleint's avatar Friedemann Kleint

ProjectExplorer: Enable the document factory to handle directories.

Register the mime type inode/directory and use it to open
project files in that directory.

It is then possible to drop directories on the main window
which will cause the contained projects to be opened.

Also allows for simplifying the code in the command line handling.

Change-Id: I92138915216b1346a36b5ca7654cf2b7d6f405c4
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9c7146a8
......@@ -290,12 +290,9 @@ void FolderNavigationWidget::openItem(const QModelIndex &srcIndex, bool openDire
return;
// Try to find project files in directory and open those.
if (openDirectoryAsProject) {
QDir dir(path);
QStringList proFiles;
foreach (const QFileInfo &i, dir.entryInfoList(ProjectExplorerPlugin::projectFileGlobs(), QDir::Files))
proFiles.append(i.absoluteFilePath());
if (!proFiles.isEmpty())
Core::ICore::instance()->openFiles(proFiles);
const QStringList projectFiles = FolderNavigationWidget::projectFilesInDirectory(path);
if (!projectFiles.isEmpty())
Core::ICore::instance()->openFiles(projectFiles);
return;
}
// Change to directory
......@@ -428,6 +425,15 @@ void FolderNavigationWidget::ensureCurrentIndex()
m_listView->scrollTo(index);
}
QStringList FolderNavigationWidget::projectFilesInDirectory(const QString &path)
{
QDir dir(path);
QStringList projectFiles;
foreach (const QFileInfo &i, dir.entryInfoList(ProjectExplorerPlugin::projectFileGlobs(), QDir::Files))
projectFiles.append(i.absoluteFilePath());
return projectFiles;
}
// --------------------FolderNavigationWidgetFactory
FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
{
......
......@@ -50,6 +50,8 @@ class FolderNavigationWidget : public QWidget
public:
explicit FolderNavigationWidget(QWidget *parent = 0);
static QStringList projectFilesInDirectory(const QString &path);
bool autoSynchronization() const;
bool hiddenFilesFilter() const;
......
......@@ -1472,7 +1472,10 @@ void ProjectExplorerPlugin::extensionsInitialized()
QStringList filterStrings;
auto factory = new IDocumentFactory;
factory->setOpener([this](const QString &fileName) -> IDocument* {
factory->setOpener([this](QString fileName) -> IDocument* {
const QFileInfo fi(fileName);
if (fi.isDir())
fileName = FolderNavigationWidget::projectFilesInDirectory(fi.absoluteFilePath()).value(0, fileName);
OpenProjectResult result = ProjectExplorerPlugin::openProject(fileName);
if (!result)
......@@ -1481,6 +1484,7 @@ void ProjectExplorerPlugin::extensionsInitialized()
});
Utils::MimeDatabase mdb;
factory->addMimeType(QStringLiteral("inode/directory"));
foreach (IProjectManager *manager, projectManagers) {
const QString mimeType = manager->mimeType();
factory->addMimeType(mimeType);
......@@ -1848,7 +1852,6 @@ void ProjectExplorerPluginPrivate::restoreSession()
// "filename+45" and "filename:23".
if (!arguments.isEmpty()) {
const QStringList sessions = SessionManager::sessions();
QStringList projectGlobs = ProjectExplorerPlugin::projectFileGlobs();
for (int a = 0; a < arguments.size(); ) {
const QString &arg = arguments.at(a);
const QFileInfo fi(arg);
......@@ -1860,21 +1863,7 @@ void ProjectExplorerPluginPrivate::restoreSession()
dd->m_sessionToRestoreAtStartup = dir.dirName();
arguments.removeAt(a);
continue;
} else {
// Are there project files in that directory?
const QFileInfoList proFiles
= dir.entryInfoList(projectGlobs, QDir::Files);
if (!proFiles.isEmpty()) {
arguments[a] = proFiles.front().absoluteFilePath();
++a;
continue;
}
}
// Cannot handle: Avoid mime type warning for directory.
qWarning("Skipping directory '%s' passed on to command line.",
qPrintable(QDir::toNativeSeparators(arg)));
arguments.removeAt(a);
continue;
} // Done directories.
// Converts "filename" "+45" or "filename" ":23" into "filename+45" and "filename:23"
if (a && (arg.startsWith(QLatin1Char('+')) || arg.startsWith(QLatin1Char(':')))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment