| 1 |
masaki |
281 |
// |
| 2 |
|
|
// XspfMCoverFlowViewController.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 10/01/21. |
| 6 |
|
|
// Copyright 2010 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMCoverFlowViewController.h" |
| 10 |
|
|
|
| 11 |
|
|
#import "XspfMListViewController.h" |
| 12 |
|
|
|
| 13 |
masaki |
301 |
#import "XspfMXspfObject.h" |
| 14 |
|
|
#import <Quartz/Quartz.h> |
| 15 |
masaki |
281 |
|
| 16 |
masaki |
301 |
#import <objc/runtime.h> |
| 17 |
masaki |
281 |
|
| 18 |
masaki |
301 |
@interface NSObject(XpsfMIKImageFlowViewSupport) |
| 19 |
|
|
- (void)setShowSplitter:(BOOL)flag; |
| 20 |
|
|
- (void)setInlinePreviewEnabled:(BOOL)flag; |
| 21 |
|
|
- (void)setSelectedIndex:(NSUInteger)index; |
| 22 |
|
|
@end |
| 23 |
|
|
|
| 24 |
masaki |
281 |
@implementation XspfMCoverFlowViewController |
| 25 |
|
|
|
| 26 |
masaki |
301 |
static IMP originalKeyDown = NULL; |
| 27 |
|
|
+ (void)initialize |
| 28 |
|
|
{ |
| 29 |
|
|
static BOOL isFirst = YES; |
| 30 |
|
|
if(isFirst) { |
| 31 |
|
|
isFirst = NO; |
| 32 |
|
|
|
| 33 |
|
|
Method originalMethod = class_getInstanceMethod(NSClassFromString(@"IKImageFlowView"), @selector(keyDown:)); |
| 34 |
|
|
Method replacedMethod = class_getInstanceMethod(self, @selector(hackKeyDown:)); |
| 35 |
|
|
IMP replacedIMP = method_getImplementation(replacedMethod); |
| 36 |
|
|
originalKeyDown = method_setImplementation(originalMethod, replacedIMP); |
| 37 |
|
|
} |
| 38 |
|
|
} |
| 39 |
|
|
- (void)hackKeyDown:(NSEvent *)theEvent |
| 40 |
|
|
{ |
| 41 |
|
|
if([theEvent isARepeat]) goto finish; |
| 42 |
|
|
|
| 43 |
|
|
unsigned short code = [theEvent keyCode]; |
| 44 |
|
|
switch(code) { |
| 45 |
|
|
case 49: |
| 46 |
|
|
[NSApp sendAction:@selector(togglePreviewPanel:) to:nil from:nil]; |
| 47 |
|
|
return; |
| 48 |
|
|
} |
| 49 |
|
|
finish: |
| 50 |
|
|
originalKeyDown(self, _cmd, theEvent); |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
masaki |
281 |
- (id)init |
| 54 |
|
|
{ |
| 55 |
|
|
self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil]; |
| 56 |
|
|
|
| 57 |
|
|
return self; |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
- (void)awakeFromNib |
| 61 |
|
|
{ |
| 62 |
|
|
NSArrayController *rep = [self representedObject]; |
| 63 |
|
|
|
| 64 |
masaki |
301 |
[coverFlow setShowSplitter:YES]; |
| 65 |
|
|
[coverFlow setInlinePreviewEnabled:YES]; |
| 66 |
|
|
[coverFlow setDataSource:self]; |
| 67 |
|
|
[coverFlow setDelegate:self]; |
| 68 |
|
|
// NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSColor darkGrayColor] forKey:NSForegroundColorAttributeName]; |
| 69 |
|
|
// [coverFlow setValue:attr forKey:IKImageBrowserCellsSubtitleAttributesKey]; |
| 70 |
masaki |
281 |
|
| 71 |
|
|
listViewController = [[XspfMListViewController alloc] init]; |
| 72 |
|
|
[listViewController view]; |
| 73 |
|
|
[listViewController setRepresentedObject:rep]; |
| 74 |
|
|
[listViewController recalculateKeyViewLoop]; |
| 75 |
|
|
[listPlaceHolder addSubview:[listViewController view]]; |
| 76 |
|
|
[[listViewController view] setFrame:[listPlaceHolder bounds]]; |
| 77 |
|
|
[self recalculateKeyViewLoop]; |
| 78 |
|
|
|
| 79 |
masaki |
294 |
[splitView setDelegate:self]; |
| 80 |
masaki |
281 |
} |
| 81 |
|
|
|
| 82 |
|
|
- (void)setRepresentedObject:(id)representedObject |
| 83 |
|
|
{ |
| 84 |
masaki |
301 |
id oldRep = [self representedObject]; |
| 85 |
|
|
if([oldRep isEqual:representedObject]) return; |
| 86 |
masaki |
281 |
|
| 87 |
masaki |
301 |
[oldRep unbind:@"arrangedObjects"]; |
| 88 |
|
|
[oldRep unbind:@"selectionIndex"]; |
| 89 |
|
|
|
| 90 |
masaki |
281 |
if(representedObject) { |
| 91 |
masaki |
301 |
[representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL]; |
| 92 |
|
|
[representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL]; |
| 93 |
|
|
[coverFlow setSelectedIndex:[representedObject selectionIndex]]; |
| 94 |
masaki |
281 |
} |
| 95 |
masaki |
301 |
|
| 96 |
|
|
[super setRepresentedObject:representedObject]; |
| 97 |
|
|
[listViewController setRepresentedObject:representedObject]; |
| 98 |
|
|
[coverFlow reloadData]; |
| 99 |
masaki |
281 |
} |
| 100 |
|
|
|
| 101 |
masaki |
301 |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context |
| 102 |
masaki |
281 |
{ |
| 103 |
masaki |
301 |
if([keyPath isEqualToString:@"arrangedObjects"]) { |
| 104 |
|
|
[coverFlow reloadData]; |
| 105 |
|
|
return; |
| 106 |
|
|
} |
| 107 |
|
|
if([keyPath isEqualToString:@"selectionIndex"]) { |
| 108 |
|
|
[coverFlow setSelectedIndex:[[self representedObject] selectionIndex]]; |
| 109 |
|
|
return; |
| 110 |
|
|
} |
| 111 |
masaki |
281 |
|
| 112 |
masaki |
301 |
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
| 113 |
masaki |
281 |
} |
| 114 |
|
|
|
| 115 |
masaki |
301 |
|
| 116 |
|
|
- (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView |
| 117 |
|
|
{ |
| 118 |
|
|
return [[[self representedObject] arrangedObjects] count]; |
| 119 |
|
|
} |
| 120 |
|
|
- (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index |
| 121 |
|
|
{ |
| 122 |
|
|
return [[[self representedObject] arrangedObjects] objectAtIndex:index]; |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
- (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index |
| 126 |
|
|
{ |
| 127 |
|
|
[[self representedObject] setSelectionIndex:index]; |
| 128 |
|
|
} |
| 129 |
|
|
- (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index |
| 130 |
|
|
{ |
| 131 |
|
|
[NSApp sendAction:@selector(openXspf:) to:nil from:nil]; |
| 132 |
|
|
} |
| 133 |
|
|
- (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent |
| 134 |
|
|
{ |
| 135 |
|
|
NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 136 |
|
|
|
| 137 |
|
|
NSWindow *window = [imageFlowView window]; |
| 138 |
|
|
while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) { |
| 139 |
|
|
if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break; |
| 140 |
|
|
|
| 141 |
|
|
NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 142 |
|
|
[splitView setPosition:p.y+offset.y ofDividerAtIndex:0]; |
| 143 |
|
|
} |
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
|
|
|
| 147 |
masaki |
294 |
#pragma mark#### NSSplitView Delegate #### |
| 148 |
|
|
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex |
| 149 |
|
|
{ |
| 150 |
|
|
return 130; |
| 151 |
|
|
} |
| 152 |
masaki |
281 |
|
| 153 |
masaki |
301 |
@end |
| 154 |
masaki |
294 |
|
| 155 |
|
|
|
| 156 |
masaki |
301 |
@implementation XspfMXspfObject(XspfMIKImageBrowserItem) |
| 157 |
|
|
/*! |
| 158 |
|
|
@method imageUID |
| 159 |
|
|
@abstract Returns a unique string that identify this data source item (required). |
| 160 |
|
|
@discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item |
| 161 |
|
|
*/ |
| 162 |
|
|
- (NSString *) imageUID |
| 163 |
|
|
{ |
| 164 |
|
|
return self.urlString; |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
|
|
/*! |
| 168 |
|
|
@method imageRepresentationType |
| 169 |
|
|
@abstract Returns the representation of the image to display (required). |
| 170 |
|
|
@discussion Keys for imageRepresentationType are defined below. |
| 171 |
|
|
*/ |
| 172 |
|
|
- (NSString *) imageRepresentationType |
| 173 |
|
|
{ |
| 174 |
|
|
return IKImageBrowserQuickLookPathRepresentationType; |
| 175 |
|
|
} |
| 176 |
|
|
|
| 177 |
|
|
/*! |
| 178 |
|
|
@method imageRepresentation |
| 179 |
|
|
@abstract Returns the image to display (required). Can return nil if the item has no image to display. |
| 180 |
|
|
@discussion This methods is called frequently, so the receiver should cache the returned instance. |
| 181 |
|
|
*/ |
| 182 |
|
|
- (id) imageRepresentation |
| 183 |
|
|
{ |
| 184 |
|
|
return self.url; |
| 185 |
|
|
} |
| 186 |
|
|
|
| 187 |
|
|
/*! |
| 188 |
|
|
@method imageVersion |
| 189 |
|
|
@abstract Returns a version of this item. The receiver can return a new version to let the image browser knows that it shouldn't use its cache for this item |
| 190 |
|
|
*/ |
| 191 |
|
|
//- (NSUInteger) imageVersion; |
| 192 |
|
|
|
| 193 |
|
|
/*! |
| 194 |
|
|
@method imageTitle |
| 195 |
|
|
@abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes. |
| 196 |
|
|
*/ |
| 197 |
|
|
- (NSString *) imageTitle |
| 198 |
|
|
{ |
| 199 |
|
|
return self.title; |
| 200 |
|
|
} |
| 201 |
|
|
|
| 202 |
|
|
/*! |
| 203 |
|
|
@method imageSubtitle |
| 204 |
|
|
@abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes. |
| 205 |
|
|
*/ |
| 206 |
|
|
- (NSString *) imageSubtitle |
| 207 |
|
|
{ |
| 208 |
|
|
return [NSString stringWithFormat: |
| 209 |
|
|
NSLocalizedString(@"%@ Movies", @"%@ Movies"), |
| 210 |
|
|
self.movieNum]; |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
/*! |
| 214 |
|
|
@method isSelectable |
| 215 |
|
|
@abstract Returns whether this item is selectable. |
| 216 |
|
|
@discussion The receiver can implement this methods to forbid selection of this item by returning NO. |
| 217 |
|
|
*/ |
| 218 |
|
|
//- (BOOL) isSelectable; |
| 219 |
|
|
|
| 220 |
masaki |
281 |
@end |