| 1 |
masaki |
41 |
// |
| 2 |
|
|
// XspfMLibraryViewController.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/11/08. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMLibraryViewController.h" |
| 10 |
|
|
|
| 11 |
masaki |
43 |
@interface XspfMLibraryViewController (HMPrivate) |
| 12 |
|
|
- (NSArray *)sortDescriptors; |
| 13 |
|
|
- (void)setupXspfList; |
| 14 |
|
|
@end |
| 15 |
masaki |
41 |
|
| 16 |
|
|
@implementation XspfMLibraryViewController |
| 17 |
|
|
- (id)init |
| 18 |
|
|
{ |
| 19 |
|
|
[super initWithNibName:@"LibraryView" bundle:nil]; |
| 20 |
|
|
|
| 21 |
masaki |
43 |
[self setupXspfList]; |
| 22 |
|
|
|
| 23 |
masaki |
41 |
return self; |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
masaki |
43 |
- (void)awakeFromNib |
| 27 |
|
|
{ |
| 28 |
|
|
[[self representedObject] setSortDescriptors:[self sortDescriptors]]; |
| 29 |
|
|
} |
| 30 |
masaki |
41 |
- (NSArray *)sortDescriptors |
| 31 |
|
|
{ |
| 32 |
masaki |
61 |
id desc = [[NSSortDescriptor alloc] initWithKey:@"order" ascending:YES]; |
| 33 |
|
|
return [NSArray arrayWithObject:[desc autorelease]]; |
| 34 |
masaki |
41 |
} |
| 35 |
masaki |
43 |
|
| 36 |
|
|
- (void)setupXspfList |
| 37 |
|
|
{ |
| 38 |
masaki |
48 |
NSManagedObjectContext *moc = [self managedObjectContext]; |
| 39 |
masaki |
43 |
NSError *error = nil; |
| 40 |
|
|
NSFetchRequest *fetch; |
| 41 |
|
|
NSInteger num; |
| 42 |
|
|
|
| 43 |
|
|
fetch = [[[NSFetchRequest alloc] init] autorelease]; |
| 44 |
|
|
[fetch setEntity:[NSEntityDescription entityForName:@"XspfList" |
| 45 |
|
|
inManagedObjectContext:moc]]; |
| 46 |
|
|
num = [moc countForFetchRequest:fetch |
| 47 |
|
|
error:&error]; |
| 48 |
|
|
if(num != 0) return; |
| 49 |
|
|
|
| 50 |
|
|
id obj = [NSEntityDescription insertNewObjectForEntityForName:@"XspfList" |
| 51 |
|
|
inManagedObjectContext:moc]; |
| 52 |
|
|
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"urlString <> %@", @""]; |
| 53 |
|
|
[obj setValue:predicate forKey:@"predicate"]; |
| 54 |
|
|
[obj setValue:NSLocalizedString(@"Library", @"Library") forKey:@"name"]; |
| 55 |
|
|
[obj setValue:[NSNumber numberWithInt:0] forKey:@"order"]; |
| 56 |
|
|
|
| 57 |
|
|
obj = [NSEntityDescription insertNewObjectForEntityForName:@"XspfList" |
| 58 |
|
|
inManagedObjectContext:moc]; |
| 59 |
|
|
predicate = [NSPredicate predicateWithFormat:@"favorites = %@", [NSNumber numberWithBool:YES]]; |
| 60 |
|
|
[obj setValue:predicate forKey:@"predicate"]; |
| 61 |
|
|
[obj setValue:NSLocalizedString(@"Favorites", @"Favorites") forKey:@"name"]; |
| 62 |
|
|
[obj setValue:[NSNumber numberWithInt:1] forKey:@"order"]; |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
masaki |
112 |
- (IBAction)newPredicate:(id)sender |
| 66 |
masaki |
43 |
{ |
| 67 |
masaki |
112 |
if([editor numberOfRows] == 0) { |
| 68 |
|
|
[editor addRow:self]; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
[NSApp beginSheet:predicatePanel |
| 72 |
|
|
modalForWindow:[tableView window] |
| 73 |
|
|
modalDelegate:self |
| 74 |
|
|
didEndSelector:@selector(didEndEditPredicate:returnCode:contextInfo:) |
| 75 |
|
|
contextInfo:@"Createion"]; |
| 76 |
masaki |
43 |
} |
| 77 |
masaki |
112 |
- (IBAction)didEndEditPredicate:(id)sender |
| 78 |
|
|
{ |
| 79 |
|
|
[predicatePanel orderOut:self]; |
| 80 |
|
|
[NSApp endSheet:predicatePanel returnCode:[sender tag]]; |
| 81 |
|
|
} |
| 82 |
|
|
- (void)didEndEditPredicate:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo |
| 83 |
|
|
{ |
| 84 |
|
|
if(returnCode == NSCancelButton) return; |
| 85 |
|
|
|
| 86 |
|
|
NSPredicate *predicate = [editor predicate]; |
| 87 |
|
|
NSLog(@"predicate -> %@", predicate); |
| 88 |
|
|
|
| 89 |
|
|
} |
| 90 |
|
|
- (IBAction)test01:(id)sender |
| 91 |
|
|
{ |
| 92 |
|
|
NSArray *array = [editor rowTemplates]; |
| 93 |
|
|
|
| 94 |
|
|
// for(id templ in array) { |
| 95 |
|
|
// NSLog(@"Views -> %@", [templ templateViews]); |
| 96 |
|
|
// for(id v in [templ templateViews]) { |
| 97 |
|
|
// if([v respondsToSelector:@selector(tag)]) { |
| 98 |
|
|
// NSLog(@"tag -> %d", [v tag]); |
| 99 |
|
|
// } |
| 100 |
|
|
// } |
| 101 |
|
|
// } |
| 102 |
|
|
for(id templ in array) { |
| 103 |
|
|
NSLog(@"template -> %@", templ); |
| 104 |
|
|
} |
| 105 |
|
|
} |
| 106 |
masaki |
43 |
|
| 107 |
masaki |
41 |
@end |