[vlc-commits] macosx: allow trashing items referenced by the media library (closes #22760)
Felix Paul Kühne
git at videolan.org
Mon Sep 16 20:39:17 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Sep 15 13:37:34 2019 +0200| [db054bbff1243cdcc04064e3b84bb6aee8435e08] | committer: Felix Paul Kühne
macosx: allow trashing items referenced by the media library (closes #22760)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=db054bbff1243cdcc04064e3b84bb6aee8435e08
---
modules/gui/macosx/library/VLCLibraryDataTypes.h | 1 +
modules/gui/macosx/library/VLCLibraryDataTypes.m | 5 +++++
modules/gui/macosx/library/VLCLibraryMenuController.m | 16 +++++++++++++++-
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.h b/modules/gui/macosx/library/VLCLibraryDataTypes.h
index b9149a7a3a..d168a618d5 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.h
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.h
@@ -41,6 +41,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
- (instancetype)initWithFile:(struct vlc_ml_file_t *)p_file;
@property (readonly) NSString *MRL;
+ at property (readonly) NSURL *fileURL;
@property (readonly) vlc_ml_file_type_t fileType;
@property (readonly) BOOL external;
@property (readonly) BOOL removable;
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.m b/modules/gui/macosx/library/VLCLibraryDataTypes.m
index 4329e09c43..ba13bff823 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.m
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.m
@@ -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
diff --git a/modules/gui/macosx/library/VLCLibraryMenuController.m b/modules/gui/macosx/library/VLCLibraryMenuController.m
index 69284fb5e5..4a8c50c73d 100644
--- a/modules/gui/macosx/library/VLCLibraryMenuController.m
+++ b/modules/gui/macosx/library/VLCLibraryMenuController.m
@@ -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
More information about the vlc-commits
mailing list