Permalink
Browse files

Makes it able to drag items as plain text.

  • Loading branch information...
1 parent 3f5e6a7 commit d7b200d2ef342a8cda3abfccf28a13927d3707d3 @zonble committed Aug 26, 2012
Showing with 16 additions and 0 deletions.
  1. +14 −0 NativeDrag/NDAppDelegate.m
  2. +2 −0 NativeDrag/test.html
View
@@ -41,6 +41,18 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [songs count];
}
+
+- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+ if ([cell respondsToSelector:@selector(setFont:)]) {
+ [cell setFont:[NSFont systemFontOfSize:18.0]];
+ }
+}
+- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
+{
+ return 25.0;
+}
+
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSDictionary *d = songs[row];
@@ -60,10 +72,12 @@ - (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)ro
{
NSInteger row = [rowIndexes lastIndex];
NSDictionary *d = songs[row];
+ [pboard declareTypes:@[kSongObjectType, kSongNameType, kArtistNameType, kAlbumNameType, NSStringPboardType] owner:self];
[pboard setString:@"song" forType:kSongObjectType];
[pboard setString:d[kSongNameType] forType:kSongNameType];
[pboard setString:d[kArtistNameType] forType:kArtistNameType];
[pboard setString:d[kAlbumNameType] forType:kAlbumNameType];
+ [pboard setString:[NSString stringWithFormat:@"\nSong: %@\nArtist: %@\nAlbum: %@", d[kSongNameType], d[kArtistNameType], d[kAlbumNameType]] forType:NSStringPboardType];
return YES;
}
- (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
View
@@ -20,6 +20,8 @@
dataTransfer.setData(window.artistName, artistName);
dataTransfer.setData(window.albumName, albumName);
dataTransfer.setData(window.songObejctType, "song");
+ var textPresnetation = "\nSong: " + songName + "\nArtist: " + artistName + "\nAlbum: " + albumName;
+ dataTransfer.setData("public.utf8-plain-text", textPresnetation);
return true;
};
handler.drag = function() {

0 comments on commit d7b200d

Please sign in to comment.