RevealFileInFinder for mac "show file in browser"

on mac, use QProcess to call "/usr/bin/open -R file", which highlights the file
when you context-menu click "show file in browser", instead of merely opening
the directory

Fixes issue #3634
This commit is contained in:
graehl 2013-04-20 14:08:45 -07:00 committed by John Maguire
parent cccfe814d0
commit 6fa77b8749
1 changed files with 12 additions and 2 deletions

View File

@ -62,6 +62,7 @@
# include "CoreServices/CoreServices.h"
# include "IOKit/ps/IOPowerSources.h"
# include "IOKit/ps/IOPSKeys.h"
# include <QProcess>
#endif
namespace Utilities {
@ -342,6 +343,11 @@ qint32 GetMacVersion() {
Gestalt(gestaltSystemVersionMinor, &minor_version);
return minor_version;
}
// Better than openUrl(dirname(path)) - also highlights file at path
void RevealFileInFinder(QString const& path) {
QProcess::execute("/usr/bin/open", QStringList() << "-R" << path);
}
#endif // Q_OS_DARWIN
void OpenInFileBrowser(const QList<QUrl>& urls) {
@ -357,12 +363,16 @@ void OpenInFileBrowser(const QList<QUrl>& urls) {
continue;
const QString directory = QFileInfo(path).dir().path();
if (dirs.contains(directory))
continue;
dirs.insert(directory);
#ifdef Q_OS_DARWIN
// revealing multiple files in the finder only opens one window,
// so it also makes sense to reveal at most one per directory
RevealFileInFinder(path);
#else
QDesktopServices::openUrl(QUrl::fromLocalFile(directory));
#endif
}
}