Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 325 - (hide annotations) (download)
Sun Feb 7 13:16:40 2010 UTC (14 years, 2 months ago) by masaki
File size: 7179 byte(s)
[Mod] CoverFlowの期限切れキャッシュを捨てるアクションを実装。ただし使ってない。
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 masaki 304 - (NSRect)selectedImageFrame;
23 masaki 325 - (id)cacheManager;
24    
25    
26     - (void)IKCleanTimedOutCache;
27 masaki 301 @end
28    
29 masaki 281 @implementation XspfMCoverFlowViewController
30    
31 masaki 301 static IMP originalKeyDown = NULL;
32     + (void)initialize
33     {
34     static BOOL isFirst = YES;
35     if(isFirst) {
36     isFirst = NO;
37    
38     Method originalMethod = class_getInstanceMethod(NSClassFromString(@"IKImageFlowView"), @selector(keyDown:));
39     Method replacedMethod = class_getInstanceMethod(self, @selector(hackKeyDown:));
40     IMP replacedIMP = method_getImplementation(replacedMethod);
41     originalKeyDown = method_setImplementation(originalMethod, replacedIMP);
42     }
43     }
44     - (void)hackKeyDown:(NSEvent *)theEvent
45     {
46     if([theEvent isARepeat]) goto finish;
47    
48     unsigned short code = [theEvent keyCode];
49     switch(code) {
50     case 49:
51     [NSApp sendAction:@selector(togglePreviewPanel:) to:nil from:nil];
52     return;
53     }
54     finish:
55     originalKeyDown(self, _cmd, theEvent);
56     }
57    
58 masaki 281 - (id)init
59     {
60     self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil];
61    
62     return self;
63     }
64    
65     - (void)awakeFromNib
66     {
67     NSArrayController *rep = [self representedObject];
68    
69 masaki 301 [coverFlow setShowSplitter:YES];
70 masaki 302 if([coverFlow respondsToSelector:@selector(setInlinePreviewEnabled:)]) {
71     [coverFlow setInlinePreviewEnabled:YES];
72     }
73 masaki 301 [coverFlow setDataSource:self];
74     [coverFlow setDelegate:self];
75     // NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSColor darkGrayColor] forKey:NSForegroundColorAttributeName];
76     // [coverFlow setValue:attr forKey:IKImageBrowserCellsSubtitleAttributesKey];
77 masaki 281
78     listViewController = [[XspfMListViewController alloc] init];
79     [listViewController view];
80     [listViewController setRepresentedObject:rep];
81     [listViewController recalculateKeyViewLoop];
82     [listPlaceHolder addSubview:[listViewController view]];
83     [[listViewController view] setFrame:[listPlaceHolder bounds]];
84     [self recalculateKeyViewLoop];
85    
86 masaki 294 [splitView setDelegate:self];
87 masaki 281 }
88    
89     - (void)setRepresentedObject:(id)representedObject
90     {
91 masaki 301 id oldRep = [self representedObject];
92     if([oldRep isEqual:representedObject]) return;
93 masaki 310
94 masaki 281 if(representedObject) {
95 masaki 301 [representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL];
96     [representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL];
97     [coverFlow setSelectedIndex:[representedObject selectionIndex]];
98 masaki 281 }
99 masaki 301
100     [super setRepresentedObject:representedObject];
101     [listViewController setRepresentedObject:representedObject];
102     [coverFlow reloadData];
103 masaki 281 }
104    
105 masaki 301 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
106 masaki 281 {
107 masaki 301 if([keyPath isEqualToString:@"arrangedObjects"]) {
108     [coverFlow reloadData];
109     return;
110     }
111     if([keyPath isEqualToString:@"selectionIndex"]) {
112     [coverFlow setSelectedIndex:[[self representedObject] selectionIndex]];
113     return;
114     }
115 masaki 281
116 masaki 301 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
117 masaki 281 }
118    
119 masaki 301
120 masaki 325 - (IBAction)clearCoverFlowCache:(id)sender
121     {
122     if(![coverFlow respondsToSelector:@selector(cacheManager)]) {
123     NSBeep();
124     return;
125     }
126     id cacheManager = [coverFlow cacheManager];
127     if(![cacheManager respondsToSelector:@selector(IKCleanTimedOutCache)]) {
128     NSBeep();
129     return;
130     }
131     [cacheManager IKCleanTimedOutCache];
132     }
133     - (IBAction)test01:(id)sender
134     {
135     [self clearCoverFlowCache:sender];
136     }
137    
138 masaki 301 - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView
139     {
140     return [[[self representedObject] arrangedObjects] count];
141     }
142     - (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index
143     {
144     return [[[self representedObject] arrangedObjects] objectAtIndex:index];
145     }
146    
147     - (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index
148     {
149     [[self representedObject] setSelectionIndex:index];
150     }
151     - (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index
152     {
153     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
154     }
155     - (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent
156     {
157     NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil];
158    
159     NSWindow *window = [imageFlowView window];
160     while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) {
161     if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break;
162    
163     NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil];
164     [splitView setPosition:p.y+offset.y ofDividerAtIndex:0];
165     }
166     }
167    
168    
169 masaki 304 // QLPreviewPanel support
170     - (NSRect)selectionItemRect
171     {
172     NSRect rect = [coverFlow selectedImageFrame];
173     rect = [coverFlow convertRectToBase:rect];
174     rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin];
175     return rect;
176     }
177    
178 masaki 294 #pragma mark#### NSSplitView Delegate ####
179     - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex
180     {
181     return 130;
182     }
183 masaki 281
184 masaki 301 @end
185 masaki 294
186    
187 masaki 301 @implementation XspfMXspfObject(XspfMIKImageBrowserItem)
188     /*!
189     @method imageUID
190     @abstract Returns a unique string that identify this data source item (required).
191     @discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item
192     */
193     - (NSString *) imageUID
194     {
195     return self.urlString;
196     }
197    
198     /*!
199     @method imageRepresentationType
200     @abstract Returns the representation of the image to display (required).
201     @discussion Keys for imageRepresentationType are defined below.
202     */
203     - (NSString *) imageRepresentationType
204     {
205     return IKImageBrowserQuickLookPathRepresentationType;
206     }
207    
208     /*!
209     @method imageRepresentation
210     @abstract Returns the image to display (required). Can return nil if the item has no image to display.
211     @discussion This methods is called frequently, so the receiver should cache the returned instance.
212     */
213     - (id) imageRepresentation
214     {
215     return self.url;
216     }
217    
218     /*!
219     @method imageVersion
220     @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
221     */
222     //- (NSUInteger) imageVersion;
223    
224     /*!
225     @method imageTitle
226     @abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes.
227     */
228     - (NSString *) imageTitle
229     {
230     return self.title;
231     }
232    
233     /*!
234     @method imageSubtitle
235     @abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes.
236     */
237     - (NSString *) imageSubtitle
238     {
239     return [NSString stringWithFormat:
240     NSLocalizedString(@"%@ Movies", @"%@ Movies"),
241     self.movieNum];
242     }
243    
244     /*!
245     @method isSelectable
246     @abstract Returns whether this item is selectable.
247     @discussion The receiver can implement this methods to forbid selection of this item by returning NO.
248     */
249     //- (BOOL) isSelectable;
250    
251 masaki 281 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26