Commit e66d8e65 authored by David Fuhrmann's avatar David Fuhrmann

macosx: Factor code for drop handling of external files

Adds helper method createItemsFromExternalPasteboard: returning
an array of file items from the pasteboard.
performDragOperation: in VLCCoreInteraction is the now only place
where we try to add the dropped file as a subtitle.
parent f82f77ba
......@@ -71,6 +71,7 @@
- (void)stopListeningWithAppleRemote;
- (void)addSubtitlesToCurrentInput:(NSArray *)paths;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (void)toggleFullscreen;
......
......@@ -628,48 +628,36 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
}
}
#pragma mark - drag and drop support for VLCVoutView, VLCDragDropView and VLCThreePartDropView
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *o_paste = [sender draggingPasteboard];
NSArray *o_types = [NSArray arrayWithObject:NSFilenamesPboardType];
NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
NSData *o_carried_data = [o_paste dataForType:o_desired_type];
#pragma mark - Drop support for files into the video, controls bar or drop box
if (o_carried_data) {
if ([o_desired_type isEqualToString:NSFilenamesPboardType]) {
NSArray *o_array = [NSArray array];
NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
{
NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:[sender draggingPasteboard]];
input_thread_t * p_input = pl_CurrentInput(VLCIntf);
if (items.count == 0)
return NO;
if (count == 1 && p_input) {
int i_result = input_AddSubtitleOSD(p_input, [[o_values firstObject] UTF8String], true, true);
vlc_object_release(p_input);
if (i_result == VLC_SUCCESS)
return YES;
}
else if (p_input)
// Try to add file as a subtitle
input_thread_t *p_input = pl_CurrentInput(VLCIntf);
if (items.count == 1 && p_input) {
NSString *url = [[items firstObject] valueForKey:@"ITEM_URL"];
char *path = vlc_uri2path([url UTF8String]);
if (path) {
int i_result = input_AddSubtitleOSD(p_input, path, true, true);
free(path);
if (i_result == VLC_SUCCESS) {
vlc_object_release(p_input);
for (NSUInteger i = 0; i < count; i++) {
NSDictionary *o_dic;
char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
if (!psz_uri)
continue;
o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
o_array = [o_array arrayByAddingObject: o_dic];
return YES;
}
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
return YES;
}
}
return NO;
if (p_input)
vlc_object_release(p_input);
[[[VLCMain sharedInstance] playlist] addPlaylistItems:items];
return YES;
}
#pragma mark - video output stuff
......
......@@ -1197,28 +1197,7 @@ static const float f_min_window_height = 307.;
else
p_node = p_playlist->p_media_library;
if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
for(NSUInteger i = 0; i < count; i++) {
NSDictionary *o_dic;
char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
if (!psz_uri)
continue;
o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
[o_array addObject: o_dic];
}
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array withParentItemId:p_node->i_id atPos:-1 startPlayback:NO];
return YES;
}
else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
NSUInteger count = [array count];
......@@ -1233,7 +1212,17 @@ static const float f_min_window_height = 307.;
return YES;
}
return NO;
// check if dropped item is a file
NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:o_pasteboard];
if (items.count == 0)
return NO;
[[[VLCMain sharedInstance] playlist] addPlaylistItems:items
withParentItemId:p_node->i_id
atPos:-1
startPlayback:NO];
return YES;
}
- (id)sourceList:(PXSourceList *)aSourceList persistentObjectForItem:(id)item
......
......@@ -733,42 +733,20 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
return YES;
}
else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
// try file drop
NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
input_thread_t *p_input = playlist_CurrentInput(p_playlist);
if (count == 1 && p_input) {
int i_result = input_AddSubtitleOSD(p_input, vlc_path2uri([[o_values firstObject] UTF8String], NULL), true, true);
vlc_object_release(p_input);
if (i_result == VLC_SUCCESS)
return YES;
}
else if (p_input)
vlc_object_release(p_input);
// drop on a node itself will append entries at the end
static_assert(NSOutlineViewDropOnItemIndex == -1, "Expect NSOutlineViewDropOnItemIndex to be -1");
for (NSUInteger i = 0; i < count; i++) {
NSDictionary *o_dic;
char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
if (!psz_uri)
continue;
o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
[o_array addObject: o_dic];
}
NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:o_pasteboard];
if (items.count == 0)
return NO;
// drop on a node itself will append entries at the end
static_assert(NSOutlineViewDropOnItemIndex == -1, "Expect NSOutlineViewDropOnItemIndex to be -1");
[_playlist addPlaylistItems:o_array withParentItemId:[targetItem plItemId] atPos:index startPlayback:NO];
return YES;
}
return NO;
[[[VLCMain sharedInstance] playlist] addPlaylistItems:items
withParentItemId:[targetItem plItemId]
atPos:index
startPlayback:NO];
return YES;
}
@end
......@@ -73,6 +73,14 @@
- (NSArray *)draggedItems;
/**
* Prepares an array of playlist items for all suitable pasteboard types.
*
* This function checks external pasteboard objects (like files). If suitable,
* an array of all objects is prepared.
*/
- (NSArray *)createItemsFromExternalPasteboard:(NSPasteboard *)pasteboard;
/**
* Simplified version to add new items at the end of the current playlist
*/
......
......@@ -497,6 +497,30 @@
return p_input;
}
- (NSArray *)createItemsFromExternalPasteboard:(NSPasteboard *)pasteboard
{
NSArray *o_array = [NSArray array];
if (![[pasteboard types] containsObject: NSFilenamesPboardType])
return o_array;
NSArray *o_values = [[pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
for (NSUInteger i = 0; i < count; i++) {
NSDictionary *o_dic;
char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
if (!psz_uri)
continue;
o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
o_array = [o_array arrayByAddingObject: o_dic];
}
return o_array;
}
- (void)addPlaylistItems:(NSArray*)array
{
......
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