From 1ac9f55429e7a851d72395e5e32467f24e90ad26 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Wed, 2 Sep 2009 11:05:33 +0200 Subject: 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". (cherry picked from commit 36f2edb5e29208121093883f4808fc3db3564862) --- dist/changes-1.3.0 | 5 ++- src/plugins/projectexplorer/projectexplorer.cpp | 47 ++++++++++++++++------ src/plugins/projectexplorer/projectexplorer.h | 8 ++-- .../projectexplorer/projectexplorerconstants.h | 2 +- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/dist/changes-1.3.0 b/dist/changes-1.3.0 index 648249b778..51b48427ba 100644 --- a/dist/changes-1.3.0 +++ b/dist/changes-1.3.0 @@ -48,9 +48,12 @@ Project support * The qmake step is a lot smarter and tries harder to not run * 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 2c9f24cf48..d618072420 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -420,13 +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); -#endif + mfolder->addAction(cmd, Constants::G_FOLDER_FILES); // Open With menu mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN); @@ -678,9 +682,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())); @@ -1748,11 +1750,21 @@ void ProjectExplorerPlugin::openFile() em->ensureEditorManagerVisible(); } -#ifdef Q_OS_MAC -void ProjectExplorerPlugin::showInFinder() +void ProjectExplorerPlugin::showInGraphicalShell() { - if (!m_currentNode) + 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\"") @@ -1760,8 +1772,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 126849a72e..c651e2f953 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 6c67ddbd8f..222f830536 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"; -- cgit v1.2.3