Commit eaa5cfaa authored by Eike Ziller's avatar Eike Ziller

File System view: Do not open projects on double clicking directory

That functionality is available through the context menu.

Task-number: QTCREATORBUG-19035
Change-Id: If08fe798f06c013ca5149fad7934d38e357b2342
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
parent 1932912e
...@@ -294,21 +294,26 @@ int FolderNavigationWidget::bestRootForFile(const Utils::FileName &filePath) ...@@ -294,21 +294,26 @@ int FolderNavigationWidget::bestRootForFile(const Utils::FileName &filePath)
void FolderNavigationWidget::openItem(const QModelIndex &index) void FolderNavigationWidget::openItem(const QModelIndex &index)
{ {
if (!index.isValid()) QTC_ASSERT(index.isValid(), return);
// signal "activate" is also sent when double-clicking folders
// but we don't want to do anything in that case
if (m_fileSystemModel->isDir(index))
return; return;
const QString path = m_fileSystemModel->filePath(index); const QString path = m_fileSystemModel->filePath(index);
if (m_fileSystemModel->isDir(index)) { Core::EditorManager::openEditor(path);
const QFileInfo fi = m_fileSystemModel->fileInfo(index); }
if (!fi.isReadable() || !fi.isExecutable())
return; void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
// Try to find project files in directory and open those. {
const QStringList projectFiles = FolderNavigationWidget::projectFilesInDirectory(path); QTC_ASSERT(index.isValid() && m_fileSystemModel->isDir(index), return);
if (!projectFiles.isEmpty()) const QFileInfo fi = m_fileSystemModel->fileInfo(index);
Core::ICore::instance()->openFiles(projectFiles); if (!fi.isReadable() || !fi.isExecutable())
} else { return;
// Open editor const QString path = m_fileSystemModel->filePath(index);
Core::EditorManager::openEditor(path); // Try to find project files in directory and open those.
} const QStringList projectFiles = FolderNavigationWidget::projectFilesInDirectory(path);
if (!projectFiles.isEmpty())
Core::ICore::instance()->openFiles(projectFiles);
} }
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
...@@ -317,13 +322,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) ...@@ -317,13 +322,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
// Open current item // Open current item
const QModelIndex current = m_listView->currentIndex(); const QModelIndex current = m_listView->currentIndex();
const bool hasCurrentItem = current.isValid(); const bool hasCurrentItem = current.isValid();
QAction *actionOpen = nullptr; QAction *actionOpenFile = nullptr;
QAction *actionOpenProjects = nullptr;
if (hasCurrentItem) { if (hasCurrentItem) {
const QString fileName = m_fileSystemModel->fileName(current); const QString fileName = m_fileSystemModel->fileName(current);
if (m_fileSystemModel->isDir(current)) if (m_fileSystemModel->isDir(current))
actionOpen = menu.addAction(tr("Open Project in \"%1\"").arg(fileName)); actionOpenProjects = menu.addAction(tr("Open Project in \"%1\"").arg(fileName));
else else
actionOpen = menu.addAction(tr("Open \"%1\"").arg(fileName)); actionOpenFile = menu.addAction(tr("Open \"%1\"").arg(fileName));
} }
// we need dummy DocumentModel::Entry with absolute file path in it // we need dummy DocumentModel::Entry with absolute file path in it
...@@ -339,9 +345,10 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) ...@@ -339,9 +345,10 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
return; return;
ev->accept(); ev->accept();
if (action == actionOpen) { // Handle open file. if (action == actionOpenFile)
openItem(current); openItem(current);
} else if (action == actionOpenProjects)
openProjectsInDirectory(current);
} }
void FolderNavigationWidget::setHiddenFilesFilter(bool filter) void FolderNavigationWidget::setHiddenFilesFilter(bool filter)
......
...@@ -107,6 +107,7 @@ private: ...@@ -107,6 +107,7 @@ private:
void setRootDirectory(const Utils::FileName &directory); void setRootDirectory(const Utils::FileName &directory);
int bestRootForFile(const Utils::FileName &filePath); int bestRootForFile(const Utils::FileName &filePath);
void openItem(const QModelIndex &index); void openItem(const QModelIndex &index);
void openProjectsInDirectory(const QModelIndex &index);
Utils::NavigationTreeView *m_listView = nullptr; Utils::NavigationTreeView *m_listView = nullptr;
QFileSystemModel *m_fileSystemModel = nullptr; QFileSystemModel *m_fileSystemModel = 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