diff options
author | Eike Ziller <[email protected]> | 2017-10-09 11:11:22 +0200 |
---|---|---|
committer | Eike Ziller <[email protected]> | 2017-10-11 08:31:11 +0000 |
commit | eaa5cfaa983569282605631148e13dadd3a5f142 (patch) | |
tree | 63c01dab3d8483ed3ce6003e724852691c3f72a1 | |
parent | 1932912e7c07484fa3523f451a9317630b9aac20 (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 <[email protected]>
-rw-r--r-- | src/plugins/projectexplorer/foldernavigationwidget.cpp | 43 | ||||
-rw-r--r-- | src/plugins/projectexplorer/foldernavigationwidget.h | 1 |
2 files changed, 26 insertions, 18 deletions
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 3ba8fecce18..4a003ba0283 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 55bbf44a278..efb72828c33 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; |