[vlc-commits] macosx: implemented drag & drop from playlist to media library and vice verca. additionally, drag from SD to ML or PL is supported. (close #6044)

Felix Paul Kühne git at videolan.org
Sun Apr 8 21:25:11 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sun Apr  8 21:20:47 2012 +0200| [230b2823d0182d4c3042e0a8a5786f3047f868b4] | committer: Felix Paul Kühne

macosx: implemented drag & drop from playlist to media library and vice verca. additionally, drag from SD to ML or PL is supported. (close #6044)
(cherry picked from commit 09aae32b04734a520c0087fe12af8deab518bd7d)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=230b2823d0182d4c3042e0a8a5786f3047f868b4
---

 NEWS                                               |    4 +
 .../macosx/Resources/English.lproj/MainMenu.xib    |   12 ++--
 modules/gui/macosx/MainWindow.m                    |   68 ++++++++++++++++++++
 modules/gui/macosx/playlist.h                      |    1 +
 modules/gui/macosx/playlist.m                      |   17 ++---
 5 files changed, 85 insertions(+), 17 deletions(-)

diff --git a/NEWS b/NEWS
index 9e7d2c7..e034fb0 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,10 @@ Audio filters and output:
  * Fix DirectSound device selection
 
 Mac OS X:
+ * Enable drag and drop of playlist items between the temporary playlist and
+   the persistant media library
+ * Enable import of playlist items taken from the service discovery modules
+   to the media library or the temporary playlist
  * Fullscreen fixes and video output improvements
  * Keep Aspect Ratio when resizing is back
  * Fix crash when trying to open an Audio CD by drag & drop
diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.xib b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
index 5078bf5..11ee3ff 100644
--- a/extras/package/macosx/Resources/English.lproj/MainMenu.xib
+++ b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
@@ -22,15 +22,15 @@
     <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
       <bool key="EncodedWithXMLCoder">YES</bool>
       <integer value="4850"/>
-      <integer value="29"/>
+      <integer value="2770"/>
       <integer value="4596"/>
-      <integer value="4722"/>
-      <integer value="21"/>
       <integer value="1617"/>
-      <integer value="2730"/>
+      <integer value="29"/>
+      <integer value="4722"/>
       <integer value="4948"/>
-      <integer value="2770"/>
       <integer value="915"/>
+      <integer value="2730"/>
+      <integer value="21"/>
     </object>
     <object class="NSArray" key="IBDocument.PluginDependencies">
       <bool key="EncodedWithXMLCoder">YES</bool>
@@ -89,7 +89,7 @@
                             <bool key="EncodedWithXMLCoder">YES</bool>
                             <object class="NSOutlineView" id="1064884668">
                               <reference key="NSNextResponder" ref="18556274"/>
-                              <int key="NSvFlags">4354</int>
+                              <int key="NSvFlags">258</int>
                               <string key="NSFrameSize">{199, 272}</string>
                               <reference key="NSSuperview" ref="18556274"/>
                               <int key="NSViewLayerContentsRedrawPolicy">2</int>
diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 93d610a..facab5e 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -446,6 +446,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
         [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex: x] expandChildren: YES];
     [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
+    [o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
+    [o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
 
     if( b_dark_interface )
     {
@@ -2239,6 +2241,72 @@ static VLCMainWindow *_o_sharedInstance = nil;
     PL_UNLOCK;
 }
 
+- (NSDragOperation)sourceList:(PXSourceList *)aSourceList validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
+{
+    if ([[item identifier] isEqualToString:@"playlist"] || [[item identifier] isEqualToString:@"medialibrary"] )
+    {
+        NSPasteboard *o_pasteboard = [info draggingPasteboard];
+        if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] || [[o_pasteboard types] containsObject: NSFilenamesPboardType])
+            return NSDragOperationGeneric;
+    }
+    return NSDragOperationNone;
+}
+
+- (BOOL)sourceList:(PXSourceList *)aSourceList acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
+{
+    NSPasteboard *o_pasteboard = [info draggingPasteboard];
+
+    playlist_t * p_playlist = pl_Get( VLCIntf );
+    playlist_item_t *p_node;
+
+    if ([[item identifier] isEqualToString:@"playlist"])
+        p_node = p_playlist->p_local_category;
+    else
+        p_node = p_playlist->p_ml_category;
+
+    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 = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
+            if( !psz_uri )
+                continue;
+
+            o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
+
+            free( psz_uri );
+
+            [o_array addObject: o_dic];
+        }
+
+        [[[VLCMain sharedInstance] playlist] appendNodeArray:o_array inNode: p_node atPos:-1 enqueue:YES];
+        return YES;
+    }
+    else if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
+    {
+        NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
+
+        NSUInteger count = [array count];
+        playlist_item_t * p_item = NULL;
+
+        PL_LOCK;
+        for( NSUInteger i = 0; i < count; i++ )
+        {
+            p_item = [[array objectAtIndex:i] pointerValue];
+            if( !p_item ) continue;
+            playlist_NodeAddCopy( p_playlist, p_item, p_node, PLAYLIST_END );
+        }
+        PL_UNLOCK;
+
+        return YES;
+    }
+    return NO;
+}
 @end
 
 @implementation VLCDetachedVideoWindow
diff --git a/modules/gui/macosx/playlist.h b/modules/gui/macosx/playlist.h
index 00d405b..8fc879e 100644
--- a/modules/gui/macosx/playlist.h
+++ b/modules/gui/macosx/playlist.h
@@ -148,6 +148,7 @@
 - (IBAction)recursiveExpandNode:(id)sender;
 
 - (id)playingItem;
+- (NSArray *)draggedItems;
 
 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue;
 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue;
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 26a2577..14c0f2b 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -1443,6 +1443,11 @@
 
     return o_playing_item;
 }
+
+- (NSArray *)draggedItems
+{
+    return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
+}
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)
@@ -1471,15 +1476,6 @@
     {
         id o_item = [items objectAtIndex: i];
 
-        /* Refuse to move items that are not in the General Node
-           (Service Discovery) */
-        if( (![self isItem: [o_item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] &&
-            var_CreateGetBool( p_playlist, "media-library" ) && ![self isItem: [o_item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO]) ||
-            [o_item pointerValue] == p_playlist->p_local_category ||
-            [o_item pointerValue] == p_playlist->p_ml_category )
-        {
-            return NO;
-        }
         /* Fill the items and nodes to move in 2 different arrays */
         if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
             [o_nodes_array addObject: o_item];
@@ -1563,8 +1559,7 @@
     {
         int i_row, i_removed_from_node = 0;
         playlist_item_t *p_new_parent, *p_item = NULL;
-        NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
-                                                                o_items_array];
+        NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
         /* If the item is to be dropped as root item of the outline, make it a
            child of the respective general node, if is either the pl or the ml
            Else, choose the proposed parent as parent. */



More information about the vlc-commits mailing list