Commit db054bbf authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: allow trashing items referenced by the media library (closes #22760)

parent 40035be6
......@@ -41,6 +41,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
- (instancetype)initWithFile:(struct vlc_ml_file_t *)p_file;
@property (readonly) NSString *MRL;
@property (readonly) NSURL *fileURL;
@property (readonly) vlc_ml_file_type_t fileType;
@property (readonly) BOOL external;
@property (readonly) BOOL removable;
......
......@@ -58,6 +58,11 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
return [NSString stringWithFormat:@"%@ — type: %i, MRL: %@", NSStringFromClass([self class]), _fileType, _MRL];
}
- (NSURL *)fileURL
{
return [NSURL URLWithString:_MRL];
}
@end
@implementation VLCMediaLibraryTrack
......
......@@ -55,9 +55,11 @@
addItem.target = self;
NSMenuItem *revealItem = [[NSMenuItem alloc] initWithTitle:_NS("Reveal in Finder") action:@selector(revealInFinder:) keyEquivalent:@""];
revealItem.target = self;
NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:_NS("Delete from Library") action:@selector(moveToTrash:) keyEquivalent:@""];
deleteItem.target = self;
_libraryMenu = [[NSMenu alloc] initWithTitle:@""];
_libraryMenu.itemArray = @[playItem, appendItem, revealItem, [NSMenuItem separatorItem], addItem];
_libraryMenu.itemArray = @[playItem, appendItem, revealItem, deleteItem, [NSMenuItem separatorItem], addItem];
}
- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView
......@@ -102,4 +104,16 @@
[[[VLCMain sharedInstance] libraryController] showItemInFinder:self.representedMediaItem];
}
- (void)moveToTrash:(id)sender
{
NSArray *filesToTrash = self.representedMediaItem.files;
NSUInteger trashCount = filesToTrash.count;
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSUInteger x = 0; x < trashCount; x++) {
VLCMediaLibraryFile *fileToTrash = filesToTrash[x];
[fileManager trashItemAtURL:fileToTrash.fileURL resultingItemURL:nil error:nil];
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment