Commit ae34bde4 authored by Eike Ziller's avatar Eike Ziller Committed by Florian Apolloner

File System View: Disable "Open Projects" if directory has no projects

Change-Id: I4172b9aaee296fc0656f348aae20883f849d7556
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarFlorian Apolloner <florian@apolloner.eu>
parent e180244e
......@@ -303,15 +303,20 @@ void FolderNavigationWidget::openItem(const QModelIndex &index)
Core::EditorManager::openEditor(path);
}
void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
QStringList FolderNavigationWidget::projectsInDirectory(const QModelIndex &index) const
{
QTC_ASSERT(index.isValid() && m_fileSystemModel->isDir(index), return);
QTC_ASSERT(index.isValid() && m_fileSystemModel->isDir(index), return {});
const QFileInfo fi = m_fileSystemModel->fileInfo(index);
if (!fi.isReadable() || !fi.isExecutable())
return;
return {};
const QString path = m_fileSystemModel->filePath(index);
// Try to find project files in directory and open those.
const QStringList projectFiles = FolderNavigationWidget::projectFilesInDirectory(path);
return FolderNavigationWidget::projectFilesInDirectory(path);
}
void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
{
const QStringList projectFiles = projectsInDirectory(index);
if (!projectFiles.isEmpty())
Core::ICore::instance()->openFiles(projectFiles);
}
......@@ -332,6 +337,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
const QString fileName = m_fileSystemModel->fileName(current);
if (m_fileSystemModel->isDir(current)) {
actionOpenProjects = menu.addAction(tr("Open Project in \"%1\"").arg(fileName));
if (projectsInDirectory(current).isEmpty())
actionOpenProjects->setEnabled(false);
} else {
actionOpenFile = menu.addAction(tr("Open \"%1\"").arg(fileName));
if (ProjectExplorerPlugin::isProjectFile(Utils::FileName::fromString(fileName)))
......
......@@ -107,6 +107,7 @@ private:
void setRootDirectory(const Utils::FileName &directory);
int bestRootForFile(const Utils::FileName &filePath);
void openItem(const QModelIndex &index);
QStringList projectsInDirectory(const QModelIndex &index) const;
void openProjectsInDirectory(const QModelIndex &index);
Utils::NavigationTreeView *m_listView = nullptr;
......
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