From 72c4dddf183b20fa0b88a8924ea175b5d6795c2d Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 16 Jun 2022 07:18:28 -0700 Subject: [PATCH] [Clipboard] Add textual data to clipboard on copy The copy action now includes formatted text of the selected entries when copying, in addition to the supported file and URL types. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistEntry.h | 2 ++ Playlist/PlaylistEntry.m | 9 +++++++++ Playlist/PlaylistView.m | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/Playlist/PlaylistEntry.h b/Playlist/PlaylistEntry.h index 9449e46a5..1aa8c32d0 100644 --- a/Playlist/PlaylistEntry.h +++ b/Playlist/PlaylistEntry.h @@ -20,6 +20,7 @@ + (NSSet *_Nonnull)keyPathsForValuesAffectingStatus; + (NSSet *_Nonnull)keyPathsForValuesAffectingStatusMessage; + (NSSet *_Nonnull)keyPathsForValuesAffectingSpam; ++ (NSSet *_Nonnull)keyPathsForValuesAffectingIndexedSpam; + (NSSet *_Nonnull)keyPathsForValuesAffectingAlbumArt; + (NSSet *_Nonnull)keyPathsForValuesAffectingTrackText; + (NSSet *_Nonnull)keyPathsForValuesAffectingLengthText; @@ -33,6 +34,7 @@ @property(nonatomic, readonly) NSString *_Nonnull filename; @property(nonatomic, readonly) NSString *_Nonnull spam; +@property(nonatomic, readonly) NSString *_Nonnull indexedSpam; @property(nonatomic, readonly) NSString *_Nonnull positionText; diff --git a/Playlist/PlaylistEntry.m b/Playlist/PlaylistEntry.m index c8544451c..dea01c4c5 100644 --- a/Playlist/PlaylistEntry.m +++ b/Playlist/PlaylistEntry.m @@ -63,6 +63,10 @@ extern NSMutableDictionary *__artworkDictionary; return [NSSet setWithObjects:@"albumartist", @"artist", @"rawTitle", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", nil]; } ++ (NSSet *)keyPathsForValuesAffectingIndexedSpam { + return [NSSet setWithObjects:@"albumartist", @"artist", @"rawTitle", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", @"index", nil]; +} + + (NSSet *)keyPathsForValuesAffectingTrackText { return [NSSet setWithObjects:@"track", @"disc", nil]; } @@ -121,6 +125,11 @@ extern NSMutableDictionary *__artworkDictionary; } } +@dynamic indexedSpam; +- (NSString *)indexedSpam { + return [NSString stringWithFormat:@"%llu. %@", self.index, self.spam]; +} + @dynamic spam; - (NSString *)spam { BOOL hasBitrate = (self.bitrate != 0); diff --git a/Playlist/PlaylistView.m b/Playlist/PlaylistView.m index 7edd7c084..b614abc49 100644 --- a/Playlist/PlaylistView.m +++ b/Playlist/PlaylistView.m @@ -220,10 +220,15 @@ NSUInteger capacity = [entries count]; NSMutableArray *selectedURLs = [NSMutableArray arrayWithCapacity:capacity]; + NSMutableArray *fileSpams = [NSMutableArray array]; + for(PlaylistEntry *pe in entries) { [selectedURLs addObject:pe.url]; + [fileSpams addObject:pe.indexedSpam]; } + [pboard writeObjects:@[[fileSpams componentsJoinedByString:@"\n"]]]; + NSError *error; NSData *data; if(@available(macOS 10.13, *)) {