Commit ca3fcd38 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/VLC_app: Support drag and drop to the category view.

parent fb3f9b25
......@@ -31,7 +31,7 @@
/******************************************************************************
* VLCMainWindow (MasterViewDataSource)
*/
@implementation VLCMainWindow (MasterViewDataSource)
@implementation VLCMainWindow (MasterViewDelegate)
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
{
return [[item representedObject] isKindOfClass:[NSDictionary class]];
......@@ -46,6 +46,55 @@
}
@end
@implementation VLCMainWindow (MasterViewDataSource)
/* Drag and drop */
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index
{
int i;
if(![item respondsToSelector:@selector(representedObject)])
return NO;
NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:@"VLCMediaURLType"];
if( !droppedItems )
droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
if( !droppedItems )
droppedItems = [[info draggingPasteboard] propertyListForType:NSURLPboardType];
NSAssert( droppedItems, @"Dropped an unsupported object type on the outline View" );
VLCMediaList * mediaList = [(VLCMedia *)[item representedObject] subitems];
for (i = 0; i < [droppedItems count]; i++)
{
NSString * filename = [droppedItems objectAtIndex:i];
VLCMedia *media = [VLCMedia mediaWithPath:filename];
[mediaList lock];
[mediaList insertMedia:media atIndex:index+1];
[mediaList unlock];
}
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
{
NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:@"VLCMediaURLType"];
if( !droppedItems )
droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
if( !droppedItems )
droppedItems = [[info draggingPasteboard] propertyListForType:NSURLPboardType];
if(! droppedItems ||
![item respondsToSelector:@selector(representedObject)] ||
![[item representedObject] isKindOfClass:[VLCMedia class]] )
{
return NSDragOperationNone;
}
return NSDragOperationMove;
}
@end
/******************************************************************************
* VLCMainWindow
*/
......@@ -54,9 +103,6 @@
{
NSTableColumn * tableColumn;
/* This one will be removable, so we keep a reference of it so we can safely call removeFromSuperview */
[navigatorView retain];
/* Check ib outlets */
NSAssert( mainSplitView, @"No split view or wrong split view");
NSAssert( fullScreenButton, @"No fullscreen button");
......@@ -94,6 +140,8 @@
[categoryList setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
[categoryList setDelegate:self];
[categoryList registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, @"VLCMediaURLType", nil]];
[categoryList setDataSource: self];
/***********************************
* detailList setup
......
......@@ -51,7 +51,7 @@
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info
proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
return [contentMediaList isReadOnly] ? NSDragOperationNone : NSDragOperationGeneric;
return [contentMediaList isReadOnly] || op == NSTableViewDropOn ? NSDragOperationNone : NSDragOperationGeneric;
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
......@@ -60,15 +60,29 @@
int i;
row = 0;
NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
if( !droppedItems )
droppedItems = [[info draggingPasteboard] propertyListForType:NSURLPboardType];
for (i = 0; i < [droppedItems count]; i++)
{
NSString * filename = [droppedItems objectAtIndex:i];
VLCMedia *media = [VLCMedia mediaWithPath:filename];
[contentMediaList lock];
[contentMediaList insertMedia:media atIndex:[contentMediaList count] > 0 ? [contentMediaList count]-1 : 0];
[contentMediaList insertMedia:media atIndex:row];
[contentMediaList unlock];
}
return YES;
}
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
int i = [rowIndexes firstIndex];
do {
[array addObject:[[contentMediaList mediaAtIndex:i] url]];
} while ((i = [rowIndexes indexGreaterThanIndex:i]) != NSNotFound);
[pboard declareTypes:[NSArray arrayWithObject:@"VLCMediaURLType"] owner:self];
[pboard setPropertyList:array forType:@"VLCMediaURLType"];
return YES;
}
@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