From 5dc74a98e27ac7cf80f77cdc5b59fe213e63d280 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Tue, 17 Mar 2009 16:45:29 +0100
Subject: [PATCH] Add 'Show in Finder' context menu.

Task:     248454
---
 .../projectexplorer/projectexplorer.cpp       | 26 +++++++++++++++++++
 src/plugins/projectexplorer/projectexplorer.h |  6 +++++
 .../projectexplorerconstants.h                |  1 +
 3 files changed, 33 insertions(+)

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index ff9e5d74bc8..b4481b7773d 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -414,6 +414,14 @@ 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,
+                       globalcontext);
+    mfilec->addAction(cmd, Constants::G_FILE_OPEN);
+#endif
+
     // Open With menu
     mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);
 
@@ -625,6 +633,9 @@ 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_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
     connect(m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile()));
 
@@ -1625,6 +1636,21 @@ void ProjectExplorerPlugin::openFile()
     em->ensureEditorManagerVisible();
 }
 
+#ifdef Q_OS_MAC
+void ProjectExplorerPlugin::showInFinder()
+{
+    if (!m_currentNode)
+        return;
+    QProcess::execute("/usr/bin/osascript", QStringList()
+                      << "-e"
+                      << QString("tell application \"Finder\" to reveal POSIX file \"%1\"")
+                      .arg(m_currentNode->path()));
+    QProcess::execute("/usr/bin/osascript", QStringList()
+                      << "-e"
+                      << "tell application \"Finder\" to activate");
+}
+#endif
+
 void ProjectExplorerPlugin::removeFile()
 {
     if (!m_currentNode && m_currentNode->nodeType() == FileNodeType)
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index b8f55ff3e55..83581ec1b0f 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -157,6 +157,9 @@ private slots:
     void addNewFile();
     void addExistingFiles();
     void openFile();
+#ifdef Q_OS_MAC
+    void showInFinder();
+#endif
     void removeFile();
     void renameFile();
 
@@ -225,6 +228,9 @@ private:
     QAction *m_addNewFileAction;
     QAction *m_addExistingFilesAction;
     QAction *m_openFileAction;
+#ifdef Q_OS_MAC
+    QAction *m_showInFinder;
+#endif
     QAction *m_removeFileAction;
     QAction *m_renameFileAction;
 
diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h
index 8c854349a85..77ea8d8292e 100644
--- a/src/plugins/projectexplorer/projectexplorerconstants.h
+++ b/src/plugins/projectexplorer/projectexplorerconstants.h
@@ -63,6 +63,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 REMOVEFILE           = "ProjectExplorer.RemoveFile";
 const char * const RENAMEFILE           = "ProjectExplorer.RenameFile";
 
-- 
GitLab