diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 0e6bed1c4f9634a6884c6377ae469ad4bbeb46b4..610033c378d2845035ed65f579ac5285e013ceb1 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -284,6 +284,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) actionExplorer->setEnabled(hasCurrentItem); QAction *actionTerminal = menu.addAction(msgTerminalAction()); actionTerminal->setEnabled(hasCurrentItem); + + // open with... + if (!m_fileSystemModel->isDir(current)) { + QMenu *openWith = menu.addMenu(tr("Open with")); + ProjectExplorerPlugin::populateOpenWithMenu(openWith, + m_fileSystemModel->filePath(current)); + } + // Open file dialog to choose a path starting from current QAction *actionChooseFolder = menu.addAction(tr("Choose folder...")); // Sync checkable action @@ -319,6 +327,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) showInGraphicalShell(this, m_fileSystemModel->filePath(current)); return; } + ProjectExplorerPlugin::openEditorFromAction(action, + m_fileSystemModel->filePath(current)); } QString FolderNavigationWidget::msgGraphicalShellAction() diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index de7b89d8a00015422fb4e95edbb1369e97f10248..0ccccde58676be5ecface191020fad0192c672e1 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2025,15 +2025,14 @@ void ProjectExplorerPlugin::runConfigurationMenuTriggered(QAction *action) setStartupProject(runConfiguration->project()); } -void ProjectExplorerPlugin::populateOpenWithMenu() +void ProjectExplorerPlugin::populateOpenWithMenu(QMenu *menu, const QString &fileName) { typedef QList<Core::IEditorFactory*> EditorFactoryList; typedef QList<Core::IExternalEditor*> ExternalEditorList; - d->m_openWithMenu->clear(); + menu->clear(); bool anyMatches = false; - const QString fileName = currentNode()->path(); Core::ICore *core = Core::ICore::instance(); if (const Core::MimeType mt = core->mimeDatabase()->findByFile(QFileInfo(fileName))) { @@ -2046,7 +2045,7 @@ void ProjectExplorerPlugin::populateOpenWithMenu() foreach (Core::IEditorFactory *editorFactory, factories) { // Add action to open with this very editor factory QString const actionTitle = editorFactory->displayName(); - QAction * const action = d->m_openWithMenu->addAction(actionTitle); + QAction * const action = menu->addAction(actionTitle); action->setData(qVariantFromValue(editorFactory)); // File already open in an editor -> only enable that entry since // we currently do not support opening a file in two editors at once @@ -2062,31 +2061,40 @@ void ProjectExplorerPlugin::populateOpenWithMenu() } // for editor factories // Add all suitable external editors foreach (Core::IExternalEditor *externalEditor, externalEditors) { - QAction * const action = d->m_openWithMenu->addAction(externalEditor->displayName()); + QAction * const action = menu->addAction(externalEditor->displayName()); action->setData(qVariantFromValue(externalEditor)); } } // matches } - d->m_openWithMenu->setEnabled(anyMatches); + menu->setEnabled(anyMatches); +} + +void ProjectExplorerPlugin::populateOpenWithMenu() +{ + populateOpenWithMenu(d->m_openWithMenu, currentNode()->path()); } void ProjectExplorerPlugin::openWithMenuTriggered(QAction *action) { - if (!action) { + if (!action) qWarning() << "ProjectExplorerPlugin::openWithMenuTriggered no action, can't happen."; - return; - } + else + openEditorFromAction(action, currentNode()->path()); +} + +void ProjectExplorerPlugin::openEditorFromAction(QAction *action, const QString &fileName) +{ Core::EditorManager *em = Core::EditorManager::instance(); const QVariant data = action->data(); if (qVariantCanConvert<Core::IEditorFactory *>(data)) { Core::IEditorFactory *factory = qVariantValue<Core::IEditorFactory *>(data); - em->openEditor(currentNode()->path(), factory->id()); + em->openEditor(fileName, factory->id()); em->ensureEditorManagerVisible(); return; } if (qVariantCanConvert<Core::IExternalEditor *>(data)) { Core::IExternalEditor *externalEditor = qVariantValue<Core::IExternalEditor *>(data); - em->openExternalEditor(currentNode()->path(), externalEditor->id()); + em->openExternalEditor(fileName, externalEditor->id()); } } diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index da605c76f2d8b5b9362898ccaf58224d3db61d96..517e2137d0bac1e7f5859aadd24adbf5072c3fe1 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -41,6 +41,7 @@ QT_BEGIN_NAMESPACE class QPoint; class QAction; class QComboBox; +class QMenu; QT_END_NAMESPACE namespace Core { @@ -122,6 +123,8 @@ public: bool saveModifiedFiles(); void showContextMenu(const QPoint &globalPos, Node *node); + static void populateOpenWithMenu(QMenu *menu, const QString &fileName); + static void openEditorFromAction(QAction *action, const QString &fileName); //PluginInterface bool initialize(const QStringList &arguments, QString *error_message);