| 1 |
masaki |
21 |
// |
| 2 |
|
|
// XspfMListViewController.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/11/07. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMListViewController.h" |
| 10 |
|
|
|
| 11 |
masaki |
192 |
#import "XspfManager.h" |
| 12 |
masaki |
21 |
|
| 13 |
masaki |
212 |
#import "XspfMTableView.h" |
| 14 |
|
|
|
| 15 |
masaki |
238 |
#import "XspfMXspfObject.h" |
| 16 |
masaki |
192 |
|
| 17 |
masaki |
205 |
|
| 18 |
masaki |
21 |
@implementation XspfMListViewController |
| 19 |
|
|
|
| 20 |
masaki |
24 |
- (id)init |
| 21 |
|
|
{ |
| 22 |
|
|
[super initWithNibName:@"ListView" bundle:nil]; |
| 23 |
|
|
|
| 24 |
|
|
return self; |
| 25 |
|
|
} |
| 26 |
masaki |
212 |
- (void)awakeFromNib |
| 27 |
|
|
{ |
| 28 |
|
|
[tableView setDoubleAction:@selector(openXspf:)]; |
| 29 |
|
|
[tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]]; |
| 30 |
|
|
} |
| 31 |
masaki |
24 |
|
| 32 |
masaki |
238 |
- (NSMenu *)contextMenuForObject:(XspfMXspfObject *)object |
| 33 |
masaki |
212 |
{ |
| 34 |
masaki |
258 |
NSMenu *objMenu = [[NSApp delegate] menuForXspfObject:object]; |
| 35 |
|
|
return objMenu; |
| 36 |
masaki |
205 |
} |
| 37 |
|
|
|
| 38 |
masaki |
212 |
- (NSMenu *)tableView:(XspfMTableView *)table menuForEvent:(NSEvent *)event |
| 39 |
masaki |
32 |
{ |
| 40 |
masaki |
212 |
NSPoint mouse = [table convertPoint:[event locationInWindow] fromView:nil]; |
| 41 |
|
|
NSInteger row = [table rowAtPoint:mouse]; |
| 42 |
|
|
if(row == NSNotFound || row == -1) return nil; |
| 43 |
masaki |
205 |
|
| 44 |
masaki |
238 |
XspfMXspfObject *object = [[[self representedObject] arrangedObjects] objectAtIndex:row]; |
| 45 |
masaki |
212 |
return [self contextMenuForObject:object]; |
| 46 |
masaki |
32 |
} |
| 47 |
masaki |
192 |
- (void)tableView:(NSTableView *)table sortDescriptorsDidChange:(NSArray *)oldDescriptors |
| 48 |
|
|
{ |
| 49 |
masaki |
204 |
// HMLog(HMLogLevelDebug, @"Enter %@, desc-> %@", NSStringFromSelector(_cmd), [table sortDescriptors]); |
| 50 |
masaki |
192 |
id controller = [self representedObject]; |
| 51 |
|
|
[controller willChangeValueForKey:@"selectionIndexes"]; |
| 52 |
|
|
[controller didChangeValueForKey:@"selectionIndexes"]; |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
masaki |
111 |
- (NSDragOperation)tableView:(NSTableView*)table |
| 57 |
|
|
validateDrop:(id <NSDraggingInfo>)info |
| 58 |
|
|
proposedRow:(NSInteger)row |
| 59 |
|
|
proposedDropOperation:(NSTableViewDropOperation)dropOperation |
| 60 |
|
|
{ |
| 61 |
|
|
id pb = [info draggingPasteboard]; |
| 62 |
|
|
id plist = [pb propertyListForType:NSFilenamesPboardType]; |
| 63 |
|
|
|
| 64 |
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace]; |
| 65 |
|
|
NSError *error = nil; |
| 66 |
|
|
for(NSString *filePath in plist) { |
| 67 |
|
|
NSString *type = [ws typeOfFile:filePath error:&error]; |
| 68 |
|
|
if(![ws type:type conformsToType:@"com.masakih.xspf"]) { |
| 69 |
|
|
return NSDragOperationNone; |
| 70 |
|
|
} |
| 71 |
|
|
} |
| 72 |
|
|
[table setDropRow:row dropOperation:NSTableViewDropAbove]; |
| 73 |
|
|
|
| 74 |
|
|
return NSDragOperationCopy; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
- (BOOL)tableView:(NSTableView*)table |
| 78 |
|
|
acceptDrop:(id <NSDraggingInfo>)info |
| 79 |
|
|
row:(NSInteger)row |
| 80 |
|
|
dropOperation:(NSTableViewDropOperation)dropOperation |
| 81 |
|
|
{ |
| 82 |
|
|
id pb = [info draggingPasteboard]; |
| 83 |
|
|
id plist = [pb propertyListForType:NSFilenamesPboardType]; |
| 84 |
|
|
|
| 85 |
masaki |
184 |
[[NSApp delegate] registerFilePaths:plist]; |
| 86 |
masaki |
111 |
|
| 87 |
|
|
return YES; |
| 88 |
|
|
} |
| 89 |
|
|
|
| 90 |
masaki |
304 |
|
| 91 |
|
|
// QLPreviewPanel support |
| 92 |
|
|
- (NSRect)selectionItemRect |
| 93 |
|
|
{ |
| 94 |
|
|
NSInteger col = [tableView columnWithIdentifier:@"title"]; |
| 95 |
|
|
NSInteger row = [tableView selectedRow]; |
| 96 |
|
|
NSRect rect = [tableView frameOfCellAtColumn:col row:row]; |
| 97 |
masaki |
308 |
|
| 98 |
|
|
if(!NSIntersectsRect([tableView visibleRect], rect)) { |
| 99 |
|
|
return NSZeroRect; |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
masaki |
304 |
rect = [tableView convertRectToBase:rect]; |
| 103 |
|
|
rect.origin = [[tableView window] convertBaseToScreen:rect.origin]; |
| 104 |
|
|
rect.size.width = rect.size.height; |
| 105 |
|
|
return rect; |
| 106 |
|
|
} |
| 107 |
masaki |
21 |
@end |