| 1 |
masakih |
500 |
// |
| 2 |
|
|
// XspfMListController.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 11/01/03. |
| 6 |
|
|
// |
| 7 |
|
|
|
| 8 |
masakih |
501 |
/* |
| 9 |
|
|
This source code is release under the New BSD License. |
| 10 |
|
|
Copyright (c) 2011, 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) 2011, 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 |
|
|
|
| 63 |
masakih |
500 |
#import "XspfMListController.h" |
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
@implementation XspfMListController |
| 67 |
|
|
|
| 68 |
masakih |
506 |
- (BOOL)isSelected |
| 69 |
|
|
{ |
| 70 |
|
|
return [self selectionIndex] != NSNotFound; |
| 71 |
|
|
} |
| 72 |
|
|
- (XspfMXspfObject *)selectedItem |
| 73 |
|
|
{ |
| 74 |
|
|
return [self valueForKeyPath:@"selection.self"]; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
masakih |
500 |
- (void)sortByKey:(NSString *)key |
| 78 |
|
|
{ |
| 79 |
|
|
NSMutableArray *sortDescs = [[[self sortDescriptors] mutableCopy] autorelease]; |
| 80 |
|
|
NSSortDescriptor *sortDesc = nil; |
| 81 |
|
|
|
| 82 |
|
|
// key is descs first key. |
| 83 |
|
|
if([sortDescs count] > 1) { |
| 84 |
|
|
NSSortDescriptor *firstDesc = [sortDescs objectAtIndex:0]; |
| 85 |
|
|
if([key isEqualToString:[firstDesc key]]) { |
| 86 |
|
|
sortDesc = [[[NSSortDescriptor alloc] initWithKey:key ascending:![firstDesc ascending]] autorelease]; |
| 87 |
|
|
[sortDescs removeObject:firstDesc]; |
| 88 |
|
|
} |
| 89 |
|
|
} |
| 90 |
|
|
// remove same key. |
| 91 |
|
|
if(!sortDesc) { |
| 92 |
|
|
BOOL newAscending = NO; |
| 93 |
|
|
NSSortDescriptor *foundDesc = nil; |
| 94 |
|
|
for(id desc in sortDescs) { |
| 95 |
|
|
if([key isEqualToString:[desc key]]) { |
| 96 |
|
|
foundDesc = desc; |
| 97 |
|
|
break; |
| 98 |
|
|
} |
| 99 |
|
|
} |
| 100 |
|
|
if(foundDesc) { |
| 101 |
|
|
newAscending = [foundDesc ascending]; |
| 102 |
|
|
[sortDescs removeObject:foundDesc]; |
| 103 |
|
|
} |
| 104 |
|
|
|
| 105 |
|
|
sortDesc = [[[NSSortDescriptor alloc] initWithKey:key ascending:newAscending] autorelease]; |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
[sortDescs insertObject:sortDesc atIndex:0]; |
| 109 |
|
|
|
| 110 |
|
|
NSArray *selectedObjects = [self selectedObjects]; |
| 111 |
|
|
[self setSortDescriptors:sortDescs]; |
| 112 |
|
|
[self setSelectedObjects:selectedObjects]; |
| 113 |
|
|
} |
| 114 |
|
|
- (IBAction)sortByTitle:(id)sender |
| 115 |
|
|
{ |
| 116 |
|
|
[self sortByKey:@"title"]; |
| 117 |
|
|
} |
| 118 |
|
|
- (IBAction)sortByLastPlayDate:(id)sender |
| 119 |
|
|
{ |
| 120 |
|
|
[self sortByKey:@"lastPlayDate"]; |
| 121 |
|
|
} |
| 122 |
|
|
- (IBAction)sortByModificationDate:(id)sender |
| 123 |
|
|
{ |
| 124 |
|
|
[self sortByKey:@"modificationDate"]; |
| 125 |
|
|
} |
| 126 |
|
|
- (IBAction)sortByCreationDate:(id)sender |
| 127 |
|
|
{ |
| 128 |
|
|
[self sortByKey:@"creationDate"]; |
| 129 |
|
|
} |
| 130 |
|
|
- (IBAction)sortByRegisterDate:(id)sender |
| 131 |
|
|
{ |
| 132 |
|
|
[self sortByKey:@"registerDate"]; |
| 133 |
|
|
} |
| 134 |
|
|
- (IBAction)sortByRate:(id)sender |
| 135 |
|
|
{ |
| 136 |
|
|
[self sortByKey:@"rating"]; |
| 137 |
|
|
} |
| 138 |
|
|
- (IBAction)sortByMovieNumber:(id)sender |
| 139 |
|
|
{ |
| 140 |
|
|
[self sortByKey:@"movieNum"]; |
| 141 |
|
|
} |
| 142 |
|
|
- (IBAction)sortByLabel:(id)sender |
| 143 |
|
|
{ |
| 144 |
|
|
[self sortByKey:@"label"]; |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
masakih |
560 |
static inline void setUpSortMenuItemEnabled(NSMenuItem *menuItem, NSString *currentKey, NSString *key, SEL selector) |
| 148 |
|
|
{ |
| 149 |
|
|
if([menuItem action] == selector) { |
| 150 |
|
|
if([key isEqualToString:currentKey]) { |
| 151 |
|
|
[menuItem setState:NSOnState]; |
| 152 |
|
|
} else { |
| 153 |
|
|
[menuItem setState:NSOffState]; |
| 154 |
|
|
} |
| 155 |
|
|
} |
| 156 |
|
|
} |
| 157 |
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
| 158 |
|
|
{ |
| 159 |
|
|
NSArray *sorts = [self sortDescriptors]; |
| 160 |
|
|
if(!sorts || [sorts count] == 0) return YES; |
| 161 |
|
|
|
| 162 |
|
|
NSSortDescriptor *firstSort = [sorts objectAtIndex:0]; |
| 163 |
|
|
NSString *key = [firstSort key]; |
| 164 |
|
|
|
| 165 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"title", @selector(sortByTitle:)); |
| 166 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"lastPlayDate", @selector(sortByLastPlayDate:)); |
| 167 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"modificationDate", @selector(sortByModificationDate:)); |
| 168 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"creationDate", @selector(sortByCreationDate:)); |
| 169 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"registerDate", @selector(sortByRegisterDate:)); |
| 170 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"rating", @selector(sortByRate:)); |
| 171 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"movieNum", @selector(sortByMovieNumber:)); |
| 172 |
|
|
setUpSortMenuItemEnabled(menuItem, key, @"label", @selector(sortByLabel:)); |
| 173 |
|
|
|
| 174 |
|
|
return YES; |
| 175 |
|
|
} |
| 176 |
masakih |
500 |
|
| 177 |
masakih |
560 |
|
| 178 |
masakih |
500 |
@end |