From b3b82d9abec839368f04303bf7a2482be580b23a Mon Sep 17 00:00:00 2001 From: Daniel Molkentin <daniel.molkentin@nokia.com> Date: Wed, 2 Sep 2009 11:05:33 +0200 Subject: [PATCH] Extend "Show in Finder" functionality to Windows and Unix. On Unix, we cannot select the specific file, so the entry there is called "Open containing folder". --- dist/changes-1.3.0 | 4 +- .../projectexplorer/projectexplorer.cpp | 45 ++++++++++++++----- src/plugins/projectexplorer/projectexplorer.h | 8 ++-- .../projectexplorerconstants.h | 2 +- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/dist/changes-1.3.0 b/dist/changes-1.3.0 index 8b6dd998ad9..51b48427ba0 100644 --- a/dist/changes-1.3.0 +++ b/dist/changes-1.3.0 @@ -49,9 +49,11 @@ Project support * By default projects using the Microsoft Visual Studio toolchain use jom instead of nmake, for better utilization of all processors. * Show subdirectory structure below .pro/.pri files in project tree + * Add "Show file in Finder/Explorer" (Mac/Windows) to context menu. + On Linux it opens the containing directory. Compilation - * Support distributed compilation on Windows/MSVC via jom + * Support multi-core compilation on Windows/MSVC via jom (see http://qt.gitorious.org/qt-labs/jom/) Debugging diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 7cc4087a8e4..3c9ceb5971c 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -420,14 +420,17 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er globalcontext); mfilec->addAction(cmd, Constants::G_FILE_OPEN); -#ifdef Q_OS_MAC - // Show in Finder action - m_showInFinder = new QAction(tr("Show in Finder..."), this); - cmd = am->registerAction(m_showInFinder, ProjectExplorer::Constants::SHOWINFINDER, +#if defined(Q_OS_WIN) + m_showInGraphicalShell = new QAction(tr("Show in Explorer..."), this); +#elif defined(Q_OS_MAC) + m_showInGraphicalShell = new QAction(tr("Show in Finder..."), this); +#else + m_showInGraphicalShell = new QAction(tr("Show containing folder..."), this); +#endif + cmd = am->registerAction(m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL, globalcontext); mfilec->addAction(cmd, Constants::G_FILE_OPEN); mfolder->addAction(cmd, Constants::G_FOLDER_FILES); -#endif // Open With menu mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN); @@ -681,9 +684,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(m_addNewFileAction, SIGNAL(triggered()), this, SLOT(addNewFile())); connect(m_addExistingFilesAction, SIGNAL(triggered()), this, SLOT(addExistingFiles())); connect(m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); -#ifdef Q_OS_MAC - connect(m_showInFinder, SIGNAL(triggered()), this, SLOT(showInFinder())); -#endif + connect(m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell())); connect(m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile())); connect(m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile())); @@ -1751,10 +1752,21 @@ void ProjectExplorerPlugin::openFile() em->ensureEditorManagerVisible(); } -#ifdef Q_OS_MAC -void ProjectExplorerPlugin::showInFinder() +void ProjectExplorerPlugin::showInGraphicalShell() { QTC_ASSERT(m_currentNode, return) +#if defined(Q_OS_WIN) + QString explorer = Environment::systemEnvironment().searchInPath("explorer.exe"); + if (explorer.isEmpty()) { + QMessageBox::warning(Core::ICore::instance()->mainWindow(), + tr("Launching Windows Explorer failed"), + tr("Could not find explorer.exe in path to launch Windows Explorer.")); + return; + } + QProcess::execute(explorer, + QStringList() << QString("/select,%1") + .arg(QDir::toNativeSeparators(m_currentNode->path()))); +#elif defined(Q_OS_MAC) QProcess::execute("/usr/bin/osascript", QStringList() << "-e" << QString("tell application \"Finder\" to reveal POSIX file \"%1\"") @@ -1762,8 +1774,19 @@ void ProjectExplorerPlugin::showInFinder() QProcess::execute("/usr/bin/osascript", QStringList() << "-e" << "tell application \"Finder\" to activate"); -} +#elif + // we cannot select a file here, because no file browser really supports it... + QFileInfo fileInfo(m_currentNode->path()); + QString xdgopen = Environment::systemEnvironment().searchInPath("xdg-open"); + if (xdgopen.isEmpty()) { + QMessageBox::warning(Core::ICore::instance()->mainWindow(), + tr("Launching a file explorer failed"), + tr("Could not find xdg-open to launch the native file explorer.")); + return; + } + QProcess::execute(xdgopen, QStringList() << fileInfo.path()); #endif +} void ProjectExplorerPlugin::removeFile() { diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 126849a72e8..c651e2f9532 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -184,8 +184,8 @@ private slots: void addNewFile(); void addExistingFiles(); void openFile(); -#ifdef Q_OS_MAC - void showInFinder(); +#if defined(Q_OS_MAC) || defined(Q_OS_WIN) + void showInGraphicalShell(); #endif void removeFile(); void renameFile(); @@ -257,8 +257,8 @@ private: QAction *m_addNewFileAction; QAction *m_addExistingFilesAction; QAction *m_openFileAction; -#ifdef Q_OS_MAC - QAction *m_showInFinder; +#if defined(Q_OS_MAC) || defined(Q_OS_WIN) + QAction *m_showInGraphicalShell; #endif QAction *m_removeFileAction; QAction *m_renameFileAction; diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 6c67ddbd8f4..222f8305362 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -66,7 +66,7 @@ const char * const SHOWPROPERTIES = "ProjectExplorer.ShowProperties"; const char * const ADDNEWFILE = "ProjectExplorer.AddNewFile"; const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles"; const char * const OPENFILE = "ProjectExplorer.OpenFile"; -const char * const SHOWINFINDER = "ProjectExplorer.ShowInFinder"; +const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const RENAMEFILE = "ProjectExplorer.RenameFile"; -- GitLab