Add Show in File System View to project tree context menu

That opens the selected file/path in the file system view.
Behaves the same as the navigation view shortcut + syncing with the
selected file.

It would be nice to have that at other places too, but this requires
moving the file system view to Core plugin first.

Change-Id: Icc6d1041156d97f5d2bda43a3501758f06fe80aa
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Cristian Adam
2021-09-17 17:33:47 +02:00
committed by Eike Ziller
parent 8cdbb31aaf
commit ef545260cd
6 changed files with 52 additions and 6 deletions

View File

@@ -147,6 +147,11 @@ QString FileUtils::msgFindInDirectory()
return QApplication::translate("Core::Internal", "Find in This Directory..."); return QApplication::translate("Core::Internal", "Find in This Directory...");
} }
QString FileUtils::msgFileSystemAction()
{
return QApplication::translate("Core::Internal", "Show in File System View");
}
QString FileUtils::msgGraphicalShellAction() QString FileUtils::msgGraphicalShellAction()
{ {
if (HostOsInfo::isWindowsHost()) if (HostOsInfo::isWindowsHost())

View File

@@ -46,6 +46,7 @@ struct CORE_EXPORT FileUtils
static void openTerminal(const Utils::FilePath &path); static void openTerminal(const Utils::FilePath &path);
static void openTerminal(const Utils::FilePath &path, const Utils::Environment &env); static void openTerminal(const Utils::FilePath &path, const Utils::Environment &env);
static QString msgFindInDirectory(); static QString msgFindInDirectory();
static QString msgFileSystemAction();
// Platform-dependent action descriptions // Platform-dependent action descriptions
static QString msgGraphicalShellAction(); static QString msgGraphicalShellAction();
static QString msgTerminalHereAction(); static QString msgTerminalHereAction();

View File

@@ -238,8 +238,7 @@ QWidget *NavigationWidget::activateSubWidget(Id factoryId, Side fallbackSide)
preferredPosition = info.position; preferredPosition = info.position;
} }
navigationWidget->activateSubWidget(factoryId, preferredPosition); return navigationWidget->activateSubWidget(factoryId, preferredPosition);
return navigationWidget;
} }
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &factories) void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &factories)

View File

@@ -566,6 +566,15 @@ void FolderNavigationWidget::removeCurrentItem()
} }
} }
void FolderNavigationWidget::syncWithFilePath(const Utils::FilePath &filePath)
{
if (filePath.isEmpty())
return;
if (m_rootAutoSync)
selectBestRootForFile(filePath);
selectFile(filePath);
}
bool FolderNavigationWidget::autoSynchronization() const bool FolderNavigationWidget::autoSynchronization() const
{ {
return m_autoSync; return m_autoSync;
@@ -598,10 +607,7 @@ void FolderNavigationWidget::handleCurrentEditorChanged(Core::IEditor *editor)
if (!m_autoSync || !editor || editor->document()->filePath().isEmpty() if (!m_autoSync || !editor || editor->document()->filePath().isEmpty()
|| editor->document()->isTemporary()) || editor->document()->isTemporary())
return; return;
const Utils::FilePath filePath = editor->document()->filePath(); syncWithFilePath(editor->document()->filePath());
if (m_rootAutoSync)
selectBestRootForFile(filePath);
selectFile(filePath);
} }
void FolderNavigationWidget::selectBestRootForFile(const Utils::FilePath &filePath) void FolderNavigationWidget::selectBestRootForFile(const Utils::FilePath &filePath)

View File

@@ -115,6 +115,8 @@ public:
void editCurrentItem(); void editCurrentItem();
void removeCurrentItem(); void removeCurrentItem();
void syncWithFilePath(const Utils::FilePath &filePath);
protected: protected:
void contextMenuEvent(QContextMenuEvent *ev) override; void contextMenuEvent(QContextMenuEvent *ev) override;

View File

@@ -125,6 +125,7 @@
#include <coreplugin/locator/directoryfilter.h> #include <coreplugin/locator/directoryfilter.h>
#include <coreplugin/minisplitter.h> #include <coreplugin/minisplitter.h>
#include <coreplugin/modemanager.h> #include <coreplugin/modemanager.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h> #include <coreplugin/outputpane.h>
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
@@ -236,6 +237,7 @@ const char REMOVEPROJECT[] = "ProjectExplorer.RemoveProject";
const char OPENFILE[] = "ProjectExplorer.OpenFile"; const char OPENFILE[] = "ProjectExplorer.OpenFile";
const char SEARCHONFILESYSTEM[] = "ProjectExplorer.SearchOnFileSystem"; const char SEARCHONFILESYSTEM[] = "ProjectExplorer.SearchOnFileSystem";
const char OPENTERMINALHERE[] = "ProjectExplorer.OpenTerminalHere"; const char OPENTERMINALHERE[] = "ProjectExplorer.OpenTerminalHere";
const char SHOWINFILESYSTEMVIEW[] = "ProjectExplorer.OpenFileSystemView";
const char DUPLICATEFILE[] = "ProjectExplorer.DuplicateFile"; const char DUPLICATEFILE[] = "ProjectExplorer.DuplicateFile";
const char DELETEFILE[] = "ProjectExplorer.DeleteFile"; const char DELETEFILE[] = "ProjectExplorer.DeleteFile";
const char DIFFFILE[] = "ProjectExplorer.DiffFile"; const char DIFFFILE[] = "ProjectExplorer.DiffFile";
@@ -454,6 +456,7 @@ public:
void openFile(); void openFile();
void searchOnFileSystem(); void searchOnFileSystem();
void showInGraphicalShell(); void showInGraphicalShell();
void showInFileSystemPane();
void removeFile(); void removeFile();
void duplicateFile(); void duplicateFile();
void deleteFile(); void deleteFile();
@@ -552,6 +555,7 @@ public:
ParameterAction *m_closeProjectFilesActionContextMenu; ParameterAction *m_closeProjectFilesActionContextMenu;
QAction *m_searchOnFileSystem; QAction *m_searchOnFileSystem;
QAction *m_showInGraphicalShell; QAction *m_showInGraphicalShell;
QAction *m_showFileSystemPane;
QAction *m_openTerminalHere; QAction *m_openTerminalHere;
QAction *m_openTerminalHereBuildEnv; QAction *m_openTerminalHereBuildEnv;
QAction *m_openTerminalHereRunEnv; QAction *m_openTerminalHereRunEnv;
@@ -1045,6 +1049,16 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN); mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES); mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
// Show in File System View
dd->m_showFileSystemPane = new QAction(Core::FileUtils::msgFileSystemAction(), this);
cmd = ActionManager::registerAction(dd->m_showFileSystemPane,
Constants::SHOWINFILESYSTEMVIEW,
projectTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
// Open Terminal Here menu // Open Terminal Here menu
dd->m_openTerminalHere = new QAction(Core::FileUtils::msgTerminalHereAction(), this); dd->m_openTerminalHere = new QAction(Core::FileUtils::msgTerminalHereAction(), this);
cmd = ActionManager::registerAction(dd->m_openTerminalHere, Constants::OPENTERMINALHERE, cmd = ActionManager::registerAction(dd->m_openTerminalHere, Constants::OPENTERMINALHERE,
@@ -1772,6 +1786,13 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
dd, &ProjectExplorerPluginPrivate::searchOnFileSystem); dd, &ProjectExplorerPluginPrivate::searchOnFileSystem);
connect(dd->m_showInGraphicalShell, &QAction::triggered, connect(dd->m_showInGraphicalShell, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::showInGraphicalShell); dd, &ProjectExplorerPluginPrivate::showInGraphicalShell);
// the following can delete the projects view that triggered the action, so make sure we
// are out of the context menu before actually doing it by queuing the action
connect(dd->m_showFileSystemPane,
&QAction::triggered,
dd,
&ProjectExplorerPluginPrivate::showInFileSystemPane,
Qt::QueuedConnection);
connect(dd->m_openTerminalHere, &QAction::triggered, dd, []() { dd->openTerminalHere(sysEnv); }); connect(dd->m_openTerminalHere, &QAction::triggered, dd, []() { dd->openTerminalHere(sysEnv); });
connect(dd->m_openTerminalHereBuildEnv, &QAction::triggered, dd, []() { dd->openTerminalHere(buildEnv); }); connect(dd->m_openTerminalHereBuildEnv, &QAction::triggered, dd, []() { dd->openTerminalHere(buildEnv); });
@@ -3343,6 +3364,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
m_openTerminalHereRunEnv->setVisible(false); m_openTerminalHereRunEnv->setVisible(false);
m_showInGraphicalShell->setVisible(true); m_showInGraphicalShell->setVisible(true);
m_showFileSystemPane->setVisible(true);
m_searchOnFileSystem->setVisible(true); m_searchOnFileSystem->setVisible(true);
ActionContainer *runMenu = ActionManager::actionContainer(Constants::RUNMENUCONTEXTMENU); ActionContainer *runMenu = ActionManager::actionContainer(Constants::RUNMENUCONTEXTMENU);
@@ -3445,6 +3467,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
if (supports(HidePathActions)) { if (supports(HidePathActions)) {
m_openTerminalHere->setVisible(false); m_openTerminalHere->setVisible(false);
m_showInGraphicalShell->setVisible(false); m_showInGraphicalShell->setVisible(false);
m_showFileSystemPane->setVisible(false);
m_searchOnFileSystem->setVisible(false); m_searchOnFileSystem->setVisible(false);
} }
@@ -3700,6 +3723,16 @@ void ProjectExplorerPluginPrivate::showInGraphicalShell()
Core::FileUtils::showInGraphicalShell(ICore::dialogParent(), currentNode->path()); Core::FileUtils::showInGraphicalShell(ICore::dialogParent(), currentNode->path());
} }
void ProjectExplorerPluginPrivate::showInFileSystemPane()
{
Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return );
QWidget *widget = NavigationWidget::activateSubWidget(m_folderNavigationWidgetFactory.id(),
Side::Left);
if (auto *navWidget = qobject_cast<FolderNavigationWidget *>(widget))
navWidget->syncWithFilePath(currentNode->filePath());
}
void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env) void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env)
{ {
const Node *currentNode = ProjectTree::currentNode(); const Node *currentNode = ProjectTree::currentNode();