OSDN Git Service

Scan document directory.
authorHirami <tomohisa.hirami@nifty.com>
Wed, 28 Mar 2012 08:48:57 +0000 (17:48 +0900)
committerHirami <tomohisa.hirami@nifty.com>
Wed, 28 Mar 2012 08:48:57 +0000 (17:48 +0900)
Stop transition to detail view when item is folder.

15 files changed:
.gitignore
iOS/Tombo/Tombo.xcodeproj/project.pbxproj
iOS/Tombo/Tombo/AppDelegate.h
iOS/Tombo/Tombo/AppDelegate.m
iOS/Tombo/Tombo/CustomSegue.h [new file with mode: 0644]
iOS/Tombo/Tombo/CustomSegue.m [new file with mode: 0644]
iOS/Tombo/Tombo/DetailViewController.h
iOS/Tombo/Tombo/FileItem.h [new file with mode: 0644]
iOS/Tombo/Tombo/FileItem.m [new file with mode: 0644]
iOS/Tombo/Tombo/MasterViewController.h
iOS/Tombo/Tombo/MasterViewController.m
iOS/Tombo/Tombo/Storage.h
iOS/Tombo/Tombo/Storage.m
iOS/Tombo/Tombo/en.lproj/MainStoryboard_iPhone.storyboard
iOS/Tombo/Tombo/main.m

index a5405fe..a063d70 100644 (file)
@@ -10,3 +10,4 @@ Release
 \r
 .DS_Store\r
 iOS/Tombo/Tombo.xcodeproj/project.xcworkspace/xcuserdata/\r
+iOS/Tombo/Tombo.xcodeproj/xcuserdata/\r
index b5d9f73..f88166f 100644 (file)
@@ -23,6 +23,8 @@
                92DE335B151E277E00AD06EC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 92DE3359151E277E00AD06EC /* InfoPlist.strings */; };
                92DE335E151E277E00AD06EC /* TomboTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE335D151E277E00AD06EC /* TomboTests.m */; };
                92DE33861522998700AD06EC /* Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE33851522998700AD06EC /* Storage.m */; };
+               92DE338D1522F61200AD06EC /* CustomSegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE338C1522F61200AD06EC /* CustomSegue.m */; };
+               92DE33901522FFEC00AD06EC /* FileItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE338F1522FFEB00AD06EC /* FileItem.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                92DE335D151E277E00AD06EC /* TomboTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TomboTests.m; sourceTree = "<group>"; };
                92DE33841522998700AD06EC /* Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Storage.h; sourceTree = "<group>"; };
                92DE33851522998700AD06EC /* Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Storage.m; sourceTree = "<group>"; };
+               92DE338B1522F61200AD06EC /* CustomSegue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSegue.h; sourceTree = "<group>"; };
+               92DE338C1522F61200AD06EC /* CustomSegue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomSegue.m; sourceTree = "<group>"; };
+               92DE338E1522FFEB00AD06EC /* FileItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileItem.h; sourceTree = "<group>"; };
+               92DE338F1522FFEB00AD06EC /* FileItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileItem.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                92DE3333151E277D00AD06EC /* Supporting Files */,
                                92DE33841522998700AD06EC /* Storage.h */,
                                92DE33851522998700AD06EC /* Storage.m */,
+                               92DE338E1522FFEB00AD06EC /* FileItem.h */,
+                               92DE338F1522FFEB00AD06EC /* FileItem.m */,
+                               92DE338B1522F61200AD06EC /* CustomSegue.h */,
+                               92DE338C1522F61200AD06EC /* CustomSegue.m */,
                        );
                        path = Tombo;
                        sourceTree = "<group>";
                                92DE3346151E277D00AD06EC /* MasterViewController.m in Sources */,
                                92DE3349151E277D00AD06EC /* DetailViewController.m in Sources */,
                                92DE33861522998700AD06EC /* Storage.m in Sources */,
+                               92DE338D1522F61200AD06EC /* CustomSegue.m in Sources */,
+                               92DE33901522FFEC00AD06EC /* FileItem.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 2a72a3c..a5a8b38 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  AppDelegate.h
-//  Tombo
-//
-//  Created by 平見 知久 on 12/03/25.
-//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
 #import <UIKit/UIKit.h>
 
 @interface AppDelegate : UIResponder <UIApplicationDelegate>
index 2de89d4..9a58669 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  AppDelegate.m
-//  Tombo
-//
-//  Created by 平見 知久 on 12/03/25.
-//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
 #import "AppDelegate.h"
 
 @implementation AppDelegate
diff --git a/iOS/Tombo/Tombo/CustomSegue.h b/iOS/Tombo/Tombo/CustomSegue.h
new file mode 100644 (file)
index 0000000..d32afd5
--- /dev/null
@@ -0,0 +1,13 @@
+/* 
+ * Custom segue
+ * 
+ * if isStop is set to YES, transition is disabled.
+ * This segue is used by MainStoryboard_iPhone.
+ */
+#import <UIKit/UIKit.h>
+
+@interface CustomSegue : UIStoryboardSegue
+
+@property BOOL isStop;
+
+@end
diff --git a/iOS/Tombo/Tombo/CustomSegue.m b/iOS/Tombo/Tombo/CustomSegue.m
new file mode 100644 (file)
index 0000000..bc33d24
--- /dev/null
@@ -0,0 +1,14 @@
+#import "CustomSegue.h"
+
+@implementation CustomSegue
+
+@synthesize isStop;
+
+- (void)perform {
+    if (self.isStop) return;
+    
+    UINavigationController *ctrl = [self.sourceViewController navigationController];
+    [ctrl pushViewController:self.destinationViewController 
+                    animated:YES];
+}
+@end
index 7e4a00e..3260b33 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  DetailViewController.h
-//  Tombo
-//
-//  Created by 平見 知久 on 12/03/25.
-//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
 #import <UIKit/UIKit.h>
 
 @interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
diff --git a/iOS/Tombo/Tombo/FileItem.h b/iOS/Tombo/Tombo/FileItem.h
new file mode 100644 (file)
index 0000000..44383e7
--- /dev/null
@@ -0,0 +1,15 @@
+// File/directory placeholder
+
+#import <Foundation/Foundation.h>
+
+@interface FileItem : NSObject
+
+@property NSString *name;
+@property NSString *path;
+@property BOOL isDirectory;
+
+-(NSString*)description;
+
++(id)allocWithName:(NSString *)name;
+
+@end
diff --git a/iOS/Tombo/Tombo/FileItem.m b/iOS/Tombo/Tombo/FileItem.m
new file mode 100644 (file)
index 0000000..43a3559
--- /dev/null
@@ -0,0 +1,20 @@
+#import "FileItem.h"
+
+@implementation FileItem
+
+@synthesize name;
+@synthesize path;
+@synthesize isDirectory;
+
+-(NSString*)description {
+    return name;
+}
+
++(id)allocWithName:(NSString *)name {
+    FileItem *fileItem = [FileItem alloc];
+    fileItem.name = name;
+    fileItem.isDirectory = NO;
+    return fileItem;
+}
+
+@end
index 0caa1d4..70db8bc 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  MasterViewController.h
-//  Tombo
-//
-//  Created by 平見 知久 on 12/03/25.
-//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
 #import <UIKit/UIKit.h>
 
 @class DetailViewController;
index e55c2ae..b2dc76b 100644 (file)
@@ -2,6 +2,8 @@
 #import "DetailViewController.h"
 
 #import "Storage.h"
+#import "CustomSegue.h"
+#import "FileItem.h"
 
 @interface MasterViewController () {
     NSMutableArray *_objects;
 }
 */
 
-// set item (for iPad)
+// Select Row(iPhone/iPad)
+// set item for iPad
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
 {
     if ([[segue identifier] isEqualToString:@"showDetail"]) {
         NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
-        NSDate *object = [_objects objectAtIndex:indexPath.row];
-        [[segue destinationViewController] setDetailItem:object];
+        FileItem *item = [_objects objectAtIndex:indexPath.row];
+        if (item.isDirectory) {
+            CustomSegue *customSegue = (CustomSegue*)segue;
+            customSegue.isStop = YES;
+        } else {
+            [[segue destinationViewController] setDetailItem:item];
+        }
     }
 }
 
index 8ac4973..86247e7 100644 (file)
@@ -6,7 +6,9 @@
 
 @interface Storage : NSObject
 
+@property NSString *documentRoot;
 @property NSString *currentDirectory;
+@property NSFileManager *fileManager;
 
 + (id)init;
 
index 86fdd1a..024065c 100644 (file)
@@ -1,17 +1,47 @@
 #import "Storage.h"
+#import "FileItem.h"
 
 @implementation Storage
 
 @synthesize currentDirectory;
+@synthesize documentRoot;
+@synthesize fileManager;
 
 +(id)init {
     Storage *storage = [Storage alloc];
-    storage.currentDirectory = @"";
+    storage.currentDirectory = @"/";
+
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    storage.documentRoot = [paths objectAtIndex:0];
+
+    storage.fileManager = [NSFileManager defaultManager];
+
     return storage;
 }
 
+/*
+ * Enumerate current directory and return array of FileItem.
+ */
 -(NSArray*)listItems {
-    return [NSArray arrayWithObjects:@"abc", @"def", @"ghi", @"jkl", @"mno", @"pqr", nil];
+    NSError *error = nil;
+    NSString *currentPath = [documentRoot stringByAppendingString: currentDirectory];
+    NSArray *files = [fileManager contentsOfDirectoryAtPath: currentPath
+                                                      error: &error];
+    if (error) {
+        return [NSArray alloc];
+    }
+    
+    NSMutableArray *result = [NSMutableArray arrayWithCapacity: files.count];
+    for (NSString *f in files) {
+        FileItem *item = [FileItem alloc];
+        item.path = [currentPath stringByAppendingString: f];
+        item.name = [f stringByDeletingPathExtension];
+        BOOL bDir = NO;
+        [fileManager fileExistsAtPath:item.path isDirectory:&bDir];
+        item.isDirectory = bDir;
+        [result addObject:item];
+    }
+    return result;
 }
 
 @end
index 722c7af..56409ae 100644 (file)
@@ -50,7 +50,7 @@
                                 </view>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <connections>
-                                    <segue destination="21" kind="push" identifier="showDetail" id="jZb-fq-zAk"/>
+                                    <segue destination="21" kind="custom" identifier="showDetail" customClass="CustomSegue" id="jZb-fq-zAk"/>
                                 </connections>
                             </tableViewCell>
                         </prototypes>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="23" sceneMemberID="firstResponder"/>
                 <viewController storyboardIdentifier="" title="Detail" id="21" customClass="DetailViewController" sceneMemberID="viewController">
                     <view key="view" contentMode="scaleToFill" id="22">
-                        <rect key="frame" x="0.0" y="64" width="320" height="416"/>
+                        <rect key="frame" x="0.0" y="20" width="320" height="460"/>
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                         <subviews>
                             <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="dcM-3R-DB6">
-                                <rect key="frame" x="0.0" y="0.0" width="320" height="416"/>
+                                <rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                                 <fontDescription key="fontDescription" type="system" pointSize="14"/>
             <point key="canvasLocation" x="902" y="64"/>
         </scene>
     </scenes>
+    <classes>
+        <class className="DetailViewController" superclassName="UIViewController">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/DetailViewController.h"/>
+            <relationships>
+                <relationship kind="outlet" name="detailText" candidateClass="UITextView"/>
+            </relationships>
+        </class>
+        <class className="MasterViewController" superclassName="UITableViewController">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/MasterViewController.h"/>
+        </class>
+    </classes>
     <simulatedMetricsContainer key="defaultSimulatedMetrics">
         <simulatedStatusBarMetrics key="statusBar"/>
         <simulatedOrientationMetrics key="orientation"/>
         <simulatedScreenMetrics key="destination"/>
     </simulatedMetricsContainer>
-</document>
\ No newline at end of file
+</document>
index 8e02a13..02b7316 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  main.m
-//  Tombo
-//
-//  Created by 平見 知久 on 12/03/25.
-//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
 #import <UIKit/UIKit.h>
 
 #import "AppDelegate.h"