| 1 |
// |
| 2 |
// XspfMListViewController.m |
| 3 |
// XspfManager |
| 4 |
// |
| 5 |
// Created by Hori,Masaki on 09/11/07. |
| 6 |
// |
| 7 |
|
| 8 |
/* |
| 9 |
This source code is release under the New BSD License. |
| 10 |
Copyright (c) 2009-2010, masakih |
| 11 |
All rights reserved. |
| 12 |
|
| 13 |
ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に |
| 14 |
限り、再頒布および使用が許可されます。 |
| 15 |
|
| 16 |
1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含 |
| 17 |
めること。 |
| 18 |
2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表 |
| 19 |
示、本条件一覧、および下記免責条項を含めること。 |
| 20 |
3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、 |
| 21 |
コントリビューターの名前を使用してはならない。 |
| 22 |
本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、 |
| 23 |
明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証 |
| 24 |
も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター |
| 25 |
も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか |
| 26 |
厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する |
| 27 |
可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用 |
| 28 |
サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定 |
| 29 |
されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい |
| 30 |
て、一切責任を負わないものとします。 |
| 31 |
------------------------------------------------------------------- |
| 32 |
Copyright (c) 2009-2010, masakih |
| 33 |
All rights reserved. |
| 34 |
|
| 35 |
Redistribution and use in source and binary forms, with or without |
| 36 |
modification, are permitted provided that the following conditions |
| 37 |
are met: |
| 38 |
|
| 39 |
1, Redistributions of source code must retain the above copyright |
| 40 |
notice, this list of conditions and the following disclaimer. |
| 41 |
2, Redistributions in binary form must reproduce the above copyright |
| 42 |
notice, this list of conditions and the following disclaimer in |
| 43 |
the documentation and/or other materials provided with the |
| 44 |
distribution. |
| 45 |
3, The names of its contributors may be used to endorse or promote |
| 46 |
products derived from this software without specific prior |
| 47 |
written permission. |
| 48 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 49 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 50 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 51 |
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 52 |
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 53 |
INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 54 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 55 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 56 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 57 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 58 |
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 59 |
POSSIBILITY OF SUCH DAMAGE. |
| 60 |
*/ |
| 61 |
|
| 62 |
#import "XspfMListViewController.h" |
| 63 |
|
| 64 |
#import "XspfManager.h" |
| 65 |
|
| 66 |
#import "XspfMTableView.h" |
| 67 |
|
| 68 |
#import "XspfMXspfObject.h" |
| 69 |
|
| 70 |
|
| 71 |
@implementation XspfMListViewController |
| 72 |
|
| 73 |
- (id)init |
| 74 |
{ |
| 75 |
[super initWithNibName:@"ListView" bundle:nil]; |
| 76 |
|
| 77 |
return self; |
| 78 |
} |
| 79 |
- (void)awakeFromNib |
| 80 |
{ |
| 81 |
[tableView setDoubleAction:@selector(openXspf:)]; |
| 82 |
[tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]]; |
| 83 |
} |
| 84 |
|
| 85 |
- (NSMenu *)contextMenuForObject:(XspfMXspfObject *)object |
| 86 |
{ |
| 87 |
NSMenu *objMenu = [[NSApp delegate] menuForXspfObject:object]; |
| 88 |
return objMenu; |
| 89 |
} |
| 90 |
|
| 91 |
- (NSMenu *)tableView:(XspfMTableView *)table menuForEvent:(NSEvent *)event |
| 92 |
{ |
| 93 |
NSPoint mouse = [table convertPoint:[event locationInWindow] fromView:nil]; |
| 94 |
NSInteger row = [table rowAtPoint:mouse]; |
| 95 |
if(row == NSNotFound || row == -1) return nil; |
| 96 |
|
| 97 |
XspfMXspfObject *object = [[[self representedObject] arrangedObjects] objectAtIndex:row]; |
| 98 |
return [self contextMenuForObject:object]; |
| 99 |
} |
| 100 |
- (void)tableView:(NSTableView *)table sortDescriptorsDidChange:(NSArray *)oldDescriptors |
| 101 |
{ |
| 102 |
// HMLog(HMLogLevelDebug, @"Enter %@, desc-> %@", NSStringFromSelector(_cmd), [table sortDescriptors]); |
| 103 |
id controller = [self representedObject]; |
| 104 |
[controller willChangeValueForKey:@"selectionIndexes"]; |
| 105 |
[controller didChangeValueForKey:@"selectionIndexes"]; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
- (NSDragOperation)tableView:(NSTableView*)table |
| 110 |
validateDrop:(id <NSDraggingInfo>)info |
| 111 |
proposedRow:(NSInteger)row |
| 112 |
proposedDropOperation:(NSTableViewDropOperation)dropOperation |
| 113 |
{ |
| 114 |
id pb = [info draggingPasteboard]; |
| 115 |
id plist = [pb propertyListForType:NSFilenamesPboardType]; |
| 116 |
|
| 117 |
NSWorkspace *ws = [NSWorkspace sharedWorkspace]; |
| 118 |
NSError *error = nil; |
| 119 |
for(NSString *filePath in plist) { |
| 120 |
NSString *type = [ws typeOfFile:filePath error:&error]; |
| 121 |
if(![ws type:type conformsToType:@"com.masakih.xspf"]) { |
| 122 |
return NSDragOperationNone; |
| 123 |
} |
| 124 |
} |
| 125 |
[table setDropRow:row dropOperation:NSTableViewDropAbove]; |
| 126 |
|
| 127 |
return NSDragOperationCopy; |
| 128 |
} |
| 129 |
|
| 130 |
- (BOOL)tableView:(NSTableView*)table |
| 131 |
acceptDrop:(id <NSDraggingInfo>)info |
| 132 |
row:(NSInteger)row |
| 133 |
dropOperation:(NSTableViewDropOperation)dropOperation |
| 134 |
{ |
| 135 |
id pb = [info draggingPasteboard]; |
| 136 |
id plist = [pb propertyListForType:NSFilenamesPboardType]; |
| 137 |
|
| 138 |
[[NSApp delegate] registerFilePaths:plist]; |
| 139 |
|
| 140 |
return YES; |
| 141 |
} |
| 142 |
|
| 143 |
- (IBAction)scrollToSelection:(id)sender |
| 144 |
{ |
| 145 |
NSInteger col = [tableView columnWithIdentifier:@"title"]; |
| 146 |
NSInteger row = [tableView selectedRow]; |
| 147 |
NSRect rect = [tableView frameOfCellAtColumn:col row:row]; |
| 148 |
|
| 149 |
[tableView scrollRectToVisible:rect]; |
| 150 |
} |
| 151 |
- (void)moveUp:(id)sender |
| 152 |
{ |
| 153 |
NSUInteger row = [tableView selectedRow]; |
| 154 |
if(row == 0) return; |
| 155 |
|
| 156 |
NSIndexSet *newSelection = [NSIndexSet indexSetWithIndex:row - 1]; |
| 157 |
[tableView selectRowIndexes:newSelection byExtendingSelection:NO]; |
| 158 |
[self scrollToSelection:nil]; |
| 159 |
} |
| 160 |
- (void)moveDown:(id)sender |
| 161 |
{ |
| 162 |
NSUInteger row = [tableView selectedRow]; |
| 163 |
if(row == [tableView numberOfRows] - 1) return; |
| 164 |
|
| 165 |
NSIndexSet *newSelection = [NSIndexSet indexSetWithIndex:row + 1]; |
| 166 |
[tableView selectRowIndexes:newSelection byExtendingSelection:NO]; |
| 167 |
[self scrollToSelection:nil]; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
// QLPreviewPanel support |
| 172 |
- (NSRect)selectionItemRect |
| 173 |
{ |
| 174 |
NSInteger col = [tableView columnWithIdentifier:@"title"]; |
| 175 |
NSInteger row = [tableView selectedRow]; |
| 176 |
NSRect rect = [tableView frameOfCellAtColumn:col row:row]; |
| 177 |
|
| 178 |
if(!NSIntersectsRect([tableView visibleRect], rect)) { |
| 179 |
return NSZeroRect; |
| 180 |
} |
| 181 |
|
| 182 |
rect = [tableView convertRectToBase:rect]; |
| 183 |
rect.origin = [[tableView window] convertBaseToScreen:rect.origin]; |
| 184 |
rect.size.width = rect.size.height; |
| 185 |
return rect; |
| 186 |
} |
| 187 |
@end |