forked from qt-creator/qt-creator
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:
committed by
Eike Ziller
parent
8cdbb31aaf
commit
ef545260cd
@@ -147,6 +147,11 @@ QString FileUtils::msgFindInDirectory()
|
||||
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()
|
||||
{
|
||||
if (HostOsInfo::isWindowsHost())
|
||||
|
@@ -46,6 +46,7 @@ struct CORE_EXPORT FileUtils
|
||||
static void openTerminal(const Utils::FilePath &path);
|
||||
static void openTerminal(const Utils::FilePath &path, const Utils::Environment &env);
|
||||
static QString msgFindInDirectory();
|
||||
static QString msgFileSystemAction();
|
||||
// Platform-dependent action descriptions
|
||||
static QString msgGraphicalShellAction();
|
||||
static QString msgTerminalHereAction();
|
||||
|
@@ -238,8 +238,7 @@ QWidget *NavigationWidget::activateSubWidget(Id factoryId, Side fallbackSide)
|
||||
preferredPosition = info.position;
|
||||
}
|
||||
|
||||
navigationWidget->activateSubWidget(factoryId, preferredPosition);
|
||||
return navigationWidget;
|
||||
return navigationWidget->activateSubWidget(factoryId, preferredPosition);
|
||||
}
|
||||
|
||||
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &factories)
|
||||
|
@@ -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
|
||||
{
|
||||
return m_autoSync;
|
||||
@@ -598,10 +607,7 @@ void FolderNavigationWidget::handleCurrentEditorChanged(Core::IEditor *editor)
|
||||
if (!m_autoSync || !editor || editor->document()->filePath().isEmpty()
|
||||
|| editor->document()->isTemporary())
|
||||
return;
|
||||
const Utils::FilePath filePath = editor->document()->filePath();
|
||||
if (m_rootAutoSync)
|
||||
selectBestRootForFile(filePath);
|
||||
selectFile(filePath);
|
||||
syncWithFilePath(editor->document()->filePath());
|
||||
}
|
||||
|
||||
void FolderNavigationWidget::selectBestRootForFile(const Utils::FilePath &filePath)
|
||||
|
@@ -115,6 +115,8 @@ public:
|
||||
void editCurrentItem();
|
||||
void removeCurrentItem();
|
||||
|
||||
void syncWithFilePath(const Utils::FilePath &filePath);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *ev) override;
|
||||
|
||||
|
@@ -125,6 +125,7 @@
|
||||
#include <coreplugin/locator/directoryfilter.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/navigationwidget.h>
|
||||
#include <coreplugin/outputpane.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
@@ -236,6 +237,7 @@ const char REMOVEPROJECT[] = "ProjectExplorer.RemoveProject";
|
||||
const char OPENFILE[] = "ProjectExplorer.OpenFile";
|
||||
const char SEARCHONFILESYSTEM[] = "ProjectExplorer.SearchOnFileSystem";
|
||||
const char OPENTERMINALHERE[] = "ProjectExplorer.OpenTerminalHere";
|
||||
const char SHOWINFILESYSTEMVIEW[] = "ProjectExplorer.OpenFileSystemView";
|
||||
const char DUPLICATEFILE[] = "ProjectExplorer.DuplicateFile";
|
||||
const char DELETEFILE[] = "ProjectExplorer.DeleteFile";
|
||||
const char DIFFFILE[] = "ProjectExplorer.DiffFile";
|
||||
@@ -454,6 +456,7 @@ public:
|
||||
void openFile();
|
||||
void searchOnFileSystem();
|
||||
void showInGraphicalShell();
|
||||
void showInFileSystemPane();
|
||||
void removeFile();
|
||||
void duplicateFile();
|
||||
void deleteFile();
|
||||
@@ -552,6 +555,7 @@ public:
|
||||
ParameterAction *m_closeProjectFilesActionContextMenu;
|
||||
QAction *m_searchOnFileSystem;
|
||||
QAction *m_showInGraphicalShell;
|
||||
QAction *m_showFileSystemPane;
|
||||
QAction *m_openTerminalHere;
|
||||
QAction *m_openTerminalHereBuildEnv;
|
||||
QAction *m_openTerminalHereRunEnv;
|
||||
@@ -1045,6 +1049,16 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
|
||||
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
|
||||
dd->m_openTerminalHere = new QAction(Core::FileUtils::msgTerminalHereAction(), this);
|
||||
cmd = ActionManager::registerAction(dd->m_openTerminalHere, Constants::OPENTERMINALHERE,
|
||||
@@ -1772,6 +1786,13 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
dd, &ProjectExplorerPluginPrivate::searchOnFileSystem);
|
||||
connect(dd->m_showInGraphicalShell, &QAction::triggered,
|
||||
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_openTerminalHereBuildEnv, &QAction::triggered, dd, []() { dd->openTerminalHere(buildEnv); });
|
||||
@@ -3343,6 +3364,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
|
||||
m_openTerminalHereRunEnv->setVisible(false);
|
||||
|
||||
m_showInGraphicalShell->setVisible(true);
|
||||
m_showFileSystemPane->setVisible(true);
|
||||
m_searchOnFileSystem->setVisible(true);
|
||||
|
||||
ActionContainer *runMenu = ActionManager::actionContainer(Constants::RUNMENUCONTEXTMENU);
|
||||
@@ -3445,6 +3467,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
|
||||
if (supports(HidePathActions)) {
|
||||
m_openTerminalHere->setVisible(false);
|
||||
m_showInGraphicalShell->setVisible(false);
|
||||
m_showFileSystemPane->setVisible(false);
|
||||
m_searchOnFileSystem->setVisible(false);
|
||||
}
|
||||
|
||||
@@ -3700,6 +3723,16 @@ void ProjectExplorerPluginPrivate::showInGraphicalShell()
|
||||
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)
|
||||
{
|
||||
const Node *currentNode = ProjectTree::currentNode();
|
||||
|
Reference in New Issue
Block a user