TOMBO source code
Révision | 4aa1293ba1c7842e877e4fa2b8443d69aa5133b2 (tree) |
---|---|
l'heure | 2012-04-14 18:50:07 |
Auteur | Hirami <tomohisa.hirami@nift...> |
Commiter | Hirami |
Notes ordering.
@@ -17,6 +17,7 @@ | ||
17 | 17 | 9243C825153487640092B506 /* key-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 9243C823153487640092B506 /* key-32.png */; }; |
18 | 18 | 9243C826153487640092B506 /* key-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 9243C824153487640092B506 /* key-48.png */; }; |
19 | 19 | 9243C83115352EB20092B506 /* SinglePasswordDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 9243C83015352EB20092B506 /* SinglePasswordDialog.m */; }; |
20 | + 9244E4D115397C300028FD10 /* FileItemTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9244E4D015397C300028FD10 /* FileItemTest.m */; }; | |
20 | 21 | 92DE332D151E277D00AD06EC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332C151E277D00AD06EC /* UIKit.framework */; }; |
21 | 22 | 92DE332F151E277D00AD06EC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332E151E277D00AD06EC /* Foundation.framework */; }; |
22 | 23 | 92DE3331151E277D00AD06EC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE3330151E277D00AD06EC /* CoreGraphics.framework */; }; |
@@ -69,6 +70,8 @@ | ||
69 | 70 | 9243C824153487640092B506 /* key-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "key-48.png"; sourceTree = "<group>"; }; |
70 | 71 | 9243C82F15352EB20092B506 /* SinglePasswordDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SinglePasswordDialog.h; sourceTree = "<group>"; }; |
71 | 72 | 9243C83015352EB20092B506 /* SinglePasswordDialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SinglePasswordDialog.m; sourceTree = "<group>"; }; |
73 | + 9244E4CF15397C300028FD10 /* FileItemTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileItemTest.h; sourceTree = "<group>"; }; | |
74 | + 9244E4D015397C300028FD10 /* FileItemTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileItemTest.m; sourceTree = "<group>"; }; | |
72 | 75 | 92DE3328151E277D00AD06EC /* Tombo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tombo.app; sourceTree = BUILT_PRODUCTS_DIR; }; |
73 | 76 | 92DE332C151E277D00AD06EC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; |
74 | 77 | 92DE332E151E277D00AD06EC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; |
@@ -210,6 +213,8 @@ | ||
210 | 213 | children = ( |
211 | 214 | 9243C7F61532435B0092B506 /* CryptTest.h */, |
212 | 215 | 9243C7F71532435B0092B506 /* CryptTest.m */, |
216 | + 9244E4CF15397C300028FD10 /* FileItemTest.h */, | |
217 | + 9244E4D015397C300028FD10 /* FileItemTest.m */, | |
213 | 218 | 92DE3357151E277E00AD06EC /* Supporting Files */, |
214 | 219 | ); |
215 | 220 | path = TomboTests; |
@@ -374,6 +379,7 @@ | ||
374 | 379 | buildActionMask = 2147483647; |
375 | 380 | files = ( |
376 | 381 | 9243C7F81532435C0092B506 /* CryptTest.m in Sources */, |
382 | + 9244E4D115397C300028FD10 /* FileItemTest.m in Sources */, | |
377 | 383 | ); |
378 | 384 | runOnlyForDeploymentPostprocessing = 0; |
379 | 385 | }; |
@@ -18,4 +18,6 @@ | ||
18 | 18 | |
19 | 19 | - (BOOL)isNewItem; |
20 | 20 | |
21 | +- (NSComparisonResult)compare:(FileItem*)other; | |
22 | + | |
21 | 23 | @end |
@@ -26,4 +26,24 @@ | ||
26 | 26 | - (BOOL)isNewItem { |
27 | 27 | return self.name == nil; |
28 | 28 | } |
29 | + | |
30 | +- (NSComparisonResult)compare:(FileItem*)other { | |
31 | + if (self.isUp) return NSOrderedAscending; | |
32 | + if (other.isUp) return NSOrderedDescending; | |
33 | + | |
34 | + if (self.isDirectory) { | |
35 | + if (other.isDirectory) { | |
36 | + return [self.name compare:other.name]; | |
37 | + } else { | |
38 | + return NSOrderedAscending; | |
39 | + } | |
40 | + } else { | |
41 | + if (other.isDirectory) { | |
42 | + return NSOrderedDescending; | |
43 | + } else { | |
44 | + return [self.name compare:other.name]; | |
45 | + } | |
46 | + } | |
47 | +} | |
48 | + | |
29 | 49 | @end |
@@ -124,8 +124,20 @@ | ||
124 | 124 | if (!_objects) { |
125 | 125 | _objects = [[NSMutableArray alloc] init]; |
126 | 126 | } |
127 | - [_objects insertObject:item atIndex:0]; | |
128 | - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; | |
127 | + NSUInteger n = [_objects count]; | |
128 | + NSUInteger i; | |
129 | + for (i = 0; i < n; i++) { | |
130 | + if (item.isUp) break; | |
131 | + | |
132 | + FileItem *cur = [_objects objectAtIndex:i]; | |
133 | + NSComparisonResult r = [item compare:cur]; | |
134 | + if (r == NSOrderedAscending || r == NSOrderedSame) { | |
135 | + break; | |
136 | + } | |
137 | + } | |
138 | + | |
139 | + [_objects insertObject:item atIndex:i]; | |
140 | + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; | |
129 | 141 | [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] |
130 | 142 | withRowAnimation:UITableViewRowAnimationAutomatic]; |
131 | 143 | } |
@@ -0,0 +1,5 @@ | ||
1 | +#import <SenTestingKit/SenTestingKit.h> | |
2 | + | |
3 | +@interface FileItemTest : SenTestCase | |
4 | + | |
5 | +@end |
@@ -0,0 +1,44 @@ | ||
1 | +#import "FileItemTest.h" | |
2 | +#import "FileItem.h" | |
3 | + | |
4 | +@implementation FileItemTest | |
5 | + | |
6 | +- (void)testCompare1 { | |
7 | + FileItem *f1 = [FileItem allocWithName:@"abc"]; | |
8 | + FileItem *f2 = [FileItem allocWithName:@"def"]; | |
9 | + | |
10 | + NSComparisonResult r = [f1 compare:f2]; | |
11 | + STAssertTrue(r == NSOrderedAscending, @"A1"); | |
12 | + | |
13 | + r = [f1 compare:f1]; | |
14 | + STAssertTrue(r == NSOrderedSame, @"A2"); | |
15 | + | |
16 | + r = [f2 compare:f1]; | |
17 | + STAssertTrue(r == NSOrderedDescending, @"A3"); | |
18 | +} | |
19 | + | |
20 | +- (void)testCompare2 { | |
21 | + FileItem *f1 = [FileItem allocWithName:@"abc"]; | |
22 | + FileItem *f2 = [FileItem allocWithName:@"def"]; | |
23 | + f2.isDirectory = YES; | |
24 | + | |
25 | + NSComparisonResult r = [f1 compare:f2]; | |
26 | + STAssertTrue(r == NSOrderedDescending, @"A4"); | |
27 | + | |
28 | + r = [f2 compare:f1]; | |
29 | + STAssertTrue(r == NSOrderedAscending, @"A5"); | |
30 | +} | |
31 | + | |
32 | +- (void)testCompare3 { | |
33 | + FileItem *f1 = [FileItem allocWithName:@"abc"]; | |
34 | + FileItem *f2 = [FileItem allocWithName:@"def"]; | |
35 | + f2.isUp = YES; | |
36 | + | |
37 | + NSComparisonResult r = [f1 compare:f2]; | |
38 | + STAssertTrue(r == NSOrderedDescending, @"A6"); | |
39 | + | |
40 | + r = [f2 compare:f1]; | |
41 | + STAssertTrue(r == NSOrderedAscending, @"A7"); | |
42 | + | |
43 | +} | |
44 | +@end |