diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index 51cfbfc382f..70edbbabb4e 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -135,6 +135,7 @@ const char ABOUT_QTCREATOR[] = "QtCreator.AboutQtCreator"; const char ABOUT_PLUGINS[] = "QtCreator.AboutPlugins"; const char S_RETURNTOEDITOR[] = "QtCreator.ReturnToEditor"; const char SHOWINGRAPHICALSHELL[] = "QtCreator.ShowInGraphicalShell"; +const char SHOWINFILESYSTEMVIEW[] = "QtCreator.ShowInFileSystemView"; const char OUTPUTPANE_CLEAR[] = "Coreplugin.OutputPane.clear"; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 7944c882853..df222e0fe8e 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -25,6 +25,8 @@ #include "editormanager.h" #include "editormanager_p.h" + +#include "../coreconstants.h" #include "editorwindow.h" #include "editorview.h" @@ -421,6 +423,8 @@ EditorManagerPrivate::EditorManagerPrivate(QObject *parent) : m_closeAllEditorsExceptVisibleContextAction(new QAction(EditorManager::tr("Close All Except Visible"), this)), m_openGraphicalShellAction(new QAction(FileUtils::msgGraphicalShellAction(), this)), m_openGraphicalShellContextAction(new QAction(FileUtils::msgGraphicalShellAction(), this)), + m_showInFileSystemViewAction(new QAction(FileUtils::msgFileSystemAction(), this)), + m_showInFileSystemViewContextAction(new QAction(FileUtils::msgFileSystemAction(), this)), m_openTerminalAction(new QAction(FileUtils::msgTerminalHereAction(), this)), m_findInDirectoryAction(new QAction(FileUtils::msgFindInDirectory(), this)), m_filePropertiesAction(new QAction(tr("Properties..."), this)), @@ -538,6 +542,17 @@ void EditorManagerPrivate::init() FileUtils::showInGraphicalShell(ICore::dialogParent(), fp); }); + cmd = ActionManager::registerAction(m_showInFileSystemViewAction, + Constants::SHOWINFILESYSTEMVIEW, + editManagerContext); + connect(m_showInFileSystemViewAction, &QAction::triggered, this, [] { + if (!EditorManager::currentDocument()) + return; + const FilePath fp = EditorManager::currentDocument()->filePath(); + if (!fp.isEmpty()) + FileUtils::showInFileSystemView(fp); + }); + //Save XXX Context Actions connect(m_copyFilePathContextAction, &QAction::triggered, this, &EditorManagerPrivate::copyFilePathFromContextMenu); @@ -567,6 +582,11 @@ void EditorManagerPrivate::init() return; FileUtils::showInGraphicalShell(ICore::dialogParent(), m_contextMenuEntry->fileName()); }); + connect(m_showInFileSystemViewContextAction, &QAction::triggered, this, [this] { + if (!m_contextMenuEntry || m_contextMenuEntry->fileName().isEmpty()) + return; + FileUtils::showInFileSystemView(m_contextMenuEntry->fileName()); + }); connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal); connect(m_findInDirectoryAction, &QAction::triggered, this, &EditorManagerPrivate::findInDirectory); @@ -2876,10 +2896,12 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM d->m_contextMenuEntry = entry; bool enabled = entry && !entry->fileName().isEmpty(); d->m_openGraphicalShellContextAction->setEnabled(enabled); + d->m_showInFileSystemViewContextAction->setEnabled(enabled); d->m_openTerminalAction->setEnabled(enabled); d->m_findInDirectoryAction->setEnabled(enabled); d->m_filePropertiesAction->setEnabled(enabled); contextMenu->addAction(d->m_openGraphicalShellContextAction); + contextMenu->addAction(d->m_showInFileSystemViewContextAction); contextMenu->addAction(d->m_openTerminalAction); contextMenu->addAction(d->m_findInDirectoryAction); contextMenu->addAction(d->m_filePropertiesAction); diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h index a8cc29f2040..76f7f5c379a 100644 --- a/src/plugins/coreplugin/editormanager/editormanager_p.h +++ b/src/plugins/coreplugin/editormanager/editormanager_p.h @@ -258,6 +258,8 @@ private: QAction *m_closeAllEditorsExceptVisibleContextAction; QAction *m_openGraphicalShellAction; QAction *m_openGraphicalShellContextAction; + QAction *m_showInFileSystemViewAction; + QAction *m_showInFileSystemViewContextAction; QAction *m_openTerminalAction; QAction *m_findInDirectoryAction; QAction *m_filePropertiesAction = nullptr; diff --git a/src/plugins/coreplugin/fileutils.cpp b/src/plugins/coreplugin/fileutils.cpp index c77f9836cba..64cf96613e3 100644 --- a/src/plugins/coreplugin/fileutils.cpp +++ b/src/plugins/coreplugin/fileutils.cpp @@ -27,17 +27,19 @@ #include #include +#include #include #include #include +#include #include +#include #include #include #include -#include +#include #include #include -#include #include #include @@ -128,6 +130,15 @@ void FileUtils::showInGraphicalShell(QWidget *parent, const FilePath &pathIn) } } +void FileUtils::showInFileSystemView(const FilePath &path) +{ + QWidget *widget + = NavigationWidget::activateSubWidget(FolderNavigationWidgetFactory::instance()->id(), + Side::Left); + if (auto *navWidget = qobject_cast(widget)) + navWidget->syncWithFilePath(path); +} + void FileUtils::openTerminal(const FilePath &path) { openTerminal(path, Environment::systemEnvironment()); diff --git a/src/plugins/coreplugin/fileutils.h b/src/plugins/coreplugin/fileutils.h index 56c640981e2..74f14f9e748 100644 --- a/src/plugins/coreplugin/fileutils.h +++ b/src/plugins/coreplugin/fileutils.h @@ -43,6 +43,7 @@ struct CORE_EXPORT FileUtils { // Helpers for common directory browser options. static void showInGraphicalShell(QWidget *parent, const Utils::FilePath &path); + static void showInFileSystemView(const Utils::FilePath &path); static void openTerminal(const Utils::FilePath &path); static void openTerminal(const Utils::FilePath &path, const Utils::Environment &env); static QString msgFindInDirectory(); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 934a7b87b5d..d30891a7260 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3846,11 +3846,7 @@ void ProjectExplorerPluginPrivate::showInFileSystemPane() { Node *currentNode = ProjectTree::currentNode(); QTC_ASSERT(currentNode, return ); - QWidget *widget - = NavigationWidget::activateSubWidget(FolderNavigationWidgetFactory::instance()->id(), - Side::Left); - if (auto *navWidget = qobject_cast(widget)) - navWidget->syncWithFilePath(currentNode->filePath()); + Core::FileUtils::showInFileSystemView(currentNode->filePath()); } void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env)