• R/O
  • HTTP
  • SSH
  • HTTPS

Tombo: Commit

TOMBO source code


Commit MetaInfo

Révision4aa1293ba1c7842e877e4fa2b8443d69aa5133b2 (tree)
l'heure2012-04-14 18:50:07
AuteurHirami <tomohisa.hirami@nift...>
CommiterHirami

Message de Log

Notes ordering.

Change Summary

Modification

--- a/iOS/Tombo/Tombo.xcodeproj/project.pbxproj
+++ b/iOS/Tombo/Tombo.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
1717 9243C825153487640092B506 /* key-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 9243C823153487640092B506 /* key-32.png */; };
1818 9243C826153487640092B506 /* key-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 9243C824153487640092B506 /* key-48.png */; };
1919 9243C83115352EB20092B506 /* SinglePasswordDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 9243C83015352EB20092B506 /* SinglePasswordDialog.m */; };
20+ 9244E4D115397C300028FD10 /* FileItemTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9244E4D015397C300028FD10 /* FileItemTest.m */; };
2021 92DE332D151E277D00AD06EC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332C151E277D00AD06EC /* UIKit.framework */; };
2122 92DE332F151E277D00AD06EC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332E151E277D00AD06EC /* Foundation.framework */; };
2223 92DE3331151E277D00AD06EC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE3330151E277D00AD06EC /* CoreGraphics.framework */; };
@@ -69,6 +70,8 @@
6970 9243C824153487640092B506 /* key-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "key-48.png"; sourceTree = "<group>"; };
7071 9243C82F15352EB20092B506 /* SinglePasswordDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SinglePasswordDialog.h; sourceTree = "<group>"; };
7172 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>"; };
7275 92DE3328151E277D00AD06EC /* Tombo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tombo.app; sourceTree = BUILT_PRODUCTS_DIR; };
7376 92DE332C151E277D00AD06EC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
7477 92DE332E151E277D00AD06EC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -210,6 +213,8 @@
210213 children = (
211214 9243C7F61532435B0092B506 /* CryptTest.h */,
212215 9243C7F71532435B0092B506 /* CryptTest.m */,
216+ 9244E4CF15397C300028FD10 /* FileItemTest.h */,
217+ 9244E4D015397C300028FD10 /* FileItemTest.m */,
213218 92DE3357151E277E00AD06EC /* Supporting Files */,
214219 );
215220 path = TomboTests;
@@ -374,6 +379,7 @@
374379 buildActionMask = 2147483647;
375380 files = (
376381 9243C7F81532435C0092B506 /* CryptTest.m in Sources */,
382+ 9244E4D115397C300028FD10 /* FileItemTest.m in Sources */,
377383 );
378384 runOnlyForDeploymentPostprocessing = 0;
379385 };
--- a/iOS/Tombo/Tombo/FileItem.h
+++ b/iOS/Tombo/Tombo/FileItem.h
@@ -18,4 +18,6 @@
1818
1919 - (BOOL)isNewItem;
2020
21+- (NSComparisonResult)compare:(FileItem*)other;
22+
2123 @end
--- a/iOS/Tombo/Tombo/FileItem.m
+++ b/iOS/Tombo/Tombo/FileItem.m
@@ -26,4 +26,24 @@
2626 - (BOOL)isNewItem {
2727 return self.name == nil;
2828 }
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+
2949 @end
--- a/iOS/Tombo/Tombo/MasterViewController.m
+++ b/iOS/Tombo/Tombo/MasterViewController.m
@@ -124,8 +124,20 @@
124124 if (!_objects) {
125125 _objects = [[NSMutableArray alloc] init];
126126 }
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];
129141 [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
130142 withRowAnimation:UITableViewRowAnimationAutomatic];
131143 }
--- /dev/null
+++ b/iOS/Tombo/TomboTests/FileItemTest.h
@@ -0,0 +1,5 @@
1+#import <SenTestingKit/SenTestingKit.h>
2+
3+@interface FileItemTest : SenTestCase
4+
5+@end
--- /dev/null
+++ b/iOS/Tombo/TomboTests/FileItemTest.m
@@ -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
Afficher sur ancien navigateur de dépôt.