aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-10-09 11:11:22 +0200
committerEike Ziller <eike.ziller@qt.io>2017-10-11 08:31:11 +0000
commiteaa5cfaa983569282605631148e13dadd3a5f142 (patch)
tree63c01dab3d8483ed3ce6003e724852691c3f72a1
parent1932912e7c07484fa3523f451a9317630b9aac20 (diff)
File System view: Do not open projects on double clicking directoryv4.5.0-beta1
That functionality is available through the context menu. Task-number: QTCREATORBUG-19035 Change-Id: If08fe798f06c013ca5149fad7934d38e357b2342 Reviewed-by: André Hartmann <aha_1980@gmx.de>
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.cpp43
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.h1
2 files changed, 26 insertions, 18 deletions
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp
index 3ba8fecce1..4a003ba028 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.cpp
+++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp
@@ -294,21 +294,26 @@ int FolderNavigationWidget::bestRootForFile(const Utils::FileName &filePath)
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;
const QString path = m_fileSystemModel->filePath(index);
- if (m_fileSystemModel->isDir(index)) {
- const QFileInfo fi = m_fileSystemModel->fileInfo(index);
- if (!fi.isReadable() || !fi.isExecutable())
- return;
- // Try to find project files in directory and open those.
- const QStringList projectFiles = FolderNavigationWidget::projectFilesInDirectory(path);
- if (!projectFiles.isEmpty())
- Core::ICore::instance()->openFiles(projectFiles);
- } else {
- // Open editor
- Core::EditorManager::openEditor(path);
- }
+ Core::EditorManager::openEditor(path);
+}
+
+void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
+{
+ QTC_ASSERT(index.isValid() && m_fileSystemModel->isDir(index), return);
+ const QFileInfo fi = m_fileSystemModel->fileInfo(index);
+ if (!fi.isReadable() || !fi.isExecutable())
+ return;
+ const QString path = m_fileSystemModel->filePath(index);
+ // 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)
@@ -317,13 +322,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
// Open current item
const QModelIndex current = m_listView->currentIndex();
const bool hasCurrentItem = current.isValid();
- QAction *actionOpen = nullptr;
+ QAction *actionOpenFile = nullptr;
+ QAction *actionOpenProjects = nullptr;
if (hasCurrentItem) {
const QString fileName = m_fileSystemModel->fileName(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
- 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
@@ -339,9 +345,10 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
return;
ev->accept();
- if (action == actionOpen) { // Handle open file.
+ if (action == actionOpenFile)
openItem(current);
- }
+ else if (action == actionOpenProjects)
+ openProjectsInDirectory(current);
}
void FolderNavigationWidget::setHiddenFilesFilter(bool filter)
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.h b/src/plugins/projectexplorer/foldernavigationwidget.h
index 55bbf44a27..efb72828c3 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.h
+++ b/src/plugins/projectexplorer/foldernavigationwidget.h
@@ -107,6 +107,7 @@ private:
void setRootDirectory(const Utils::FileName &directory);
int bestRootForFile(const Utils::FileName &filePath);
void openItem(const QModelIndex &index);
+ void openProjectsInDirectory(const QModelIndex &index);
Utils::NavigationTreeView *m_listView = nullptr;
QFileSystemModel *m_fileSystemModel = nullptr;