diff --git a/src/gui/macutilities.h b/src/gui/macutilities.h index b9eda325f..02c4a1be6 100644 --- a/src/gui/macutilities.h +++ b/src/gui/macutilities.h @@ -36,5 +36,6 @@ QPixmap pixmapForExtension(const QString &ext, const QSize &size); void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)); void displayNotification(const QString &title, const QString &message); +void openFiles(const QSet &pathsList); #endif // MACUTILITIES_H diff --git a/src/gui/macutilities.mm b/src/gui/macutilities.mm index 2a6b0c6f6..d950e21c6 100644 --- a/src/gui/macutilities.mm +++ b/src/gui/macutilities.mm @@ -28,6 +28,7 @@ #include "macutilities.h" +#include #include #include #import @@ -81,3 +82,15 @@ void displayNotification(const QString &title, const QString &message) [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; } } + +void openFiles(const QSet &pathsList) +{ + @autoreleasepool { + NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; + + for (const auto &path : pathsList) + [pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]]; + + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; + } +} diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 756588b23..4a1a730a7 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -62,6 +62,10 @@ #include "transferlistsortmodel.h" #include "updownratiodlg.h" +#ifdef Q_OS_MAC +#include "macutilities.h" +#endif + namespace { using ToggleFn = std::function; @@ -548,6 +552,15 @@ void TransferListWidget::hidePriorityColumn(bool hide) void TransferListWidget::openSelectedTorrentsFolder() const { QSet pathsList; +#ifdef Q_OS_MAC + // On macOS you expect both the files and folders to be opened in their parent + // folders prehilighted for opening, so we use a custom method. + foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { + QString path = torrent->contentPath(true); + pathsList.insert(path); + } + openFiles(pathsList); +#else foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { QString path = torrent->contentPath(true); if (!pathsList.contains(path)) { @@ -558,6 +571,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const } pathsList.insert(path); } +#endif } void TransferListWidget::previewSelectedTorrents()