OSDN Git Service

Implement to create new folder.
authorHirami <tomohisa.hirami@nifty.com>
Tue, 3 Apr 2012 10:09:08 +0000 (19:09 +0900)
committerHirami <tomohisa.hirami@nifty.com>
Tue, 3 Apr 2012 10:09:08 +0000 (19:09 +0900)
iOS/Tombo/Tombo.xcodeproj/project.pbxproj
iOS/Tombo/Tombo/MasterViewController.m
iOS/Tombo/Tombo/NewFolderAlert.h [new file with mode: 0644]
iOS/Tombo/Tombo/NewFolderAlert.m [new file with mode: 0644]
iOS/Tombo/Tombo/Storage.h
iOS/Tombo/Tombo/Storage.m
iOS/Tombo/Tombo/en.lproj/MainStoryboard_iPhone.storyboard

index af4575d..2ada379 100644 (file)
@@ -10,6 +10,7 @@
                9228CF2815298F7200E20355 /* EditCancelAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 9228CF2715298F7200E20355 /* EditCancelAlert.m */; };
                922F592A15295FAA009B1E32 /* EditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 922F592915295FAA009B1E32 /* EditViewController.m */; };
                9243C7B51529D8610092B506 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9243C7B41529D8610092B506 /* DetailViewController.m */; };
+               9243C7BC152AC7430092B506 /* NewFolderAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 9243C7BB152AC7430092B506 /* NewFolderAlert.m */; };
                92DE332D151E277D00AD06EC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332C151E277D00AD06EC /* UIKit.framework */; };
                92DE332F151E277D00AD06EC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE332E151E277D00AD06EC /* Foundation.framework */; };
                92DE3331151E277D00AD06EC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DE3330151E277D00AD06EC /* CoreGraphics.framework */; };
@@ -51,6 +52,8 @@
                922F592915295FAA009B1E32 /* EditViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditViewController.m; sourceTree = "<group>"; };
                9243C7B31529D8610092B506 /* DetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = "<group>"; };
                9243C7B41529D8610092B506 /* DetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = "<group>"; };
+               9243C7BA152AC7430092B506 /* NewFolderAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewFolderAlert.h; sourceTree = "<group>"; };
+               9243C7BB152AC7430092B506 /* NewFolderAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewFolderAlert.m; sourceTree = "<group>"; };
                92DE3328151E277D00AD06EC /* Tombo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tombo.app; sourceTree = BUILT_PRODUCTS_DIR; };
                92DE332C151E277D00AD06EC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
                92DE332E151E277D00AD06EC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
                                92DE338F1522FFEB00AD06EC /* FileItem.m */,
                                9243C7B31529D8610092B506 /* DetailViewController.h */,
                                9243C7B41529D8610092B506 /* DetailViewController.m */,
+                               9243C7BA152AC7430092B506 /* NewFolderAlert.h */,
+                               9243C7BB152AC7430092B506 /* NewFolderAlert.m */,
                        );
                        path = Tombo;
                        sourceTree = "<group>";
                                922F592A15295FAA009B1E32 /* EditViewController.m in Sources */,
                                9228CF2815298F7200E20355 /* EditCancelAlert.m in Sources */,
                                9243C7B51529D8610092B506 /* DetailViewController.m in Sources */,
+                               9243C7BC152AC7430092B506 /* NewFolderAlert.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 0188964..3932a6d 100644 (file)
@@ -2,10 +2,33 @@
 #import "EditViewController.h"
 #import "DetailViewController.h"
 #import "EditCancelAlert.h"
+#import "NewFolderAlert.h"
 
 #import "Storage.h"
 #import "FileItem.h"
 
+@interface BackgroundView : UIView {
+}
+@end
+
+@implementation BackgroundView
+- (id)initWithFrame:(CGRect)frame {
+    self = [super initWithFrame:frame];
+    if (self) {
+        self.backgroundColor = [UIColor clearColor];
+    }
+    return self;
+}
+
+- (void)drawRect:(CGRect)rect {
+    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:5.0];
+    [path moveToPoint:CGPointMake(0, self.bounds.size.height/2.0)];
+    [path addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height/2.0)];
+    [[UIColor whiteColor] set];
+    [path fill];
+}
+@end
+
 @interface MasterViewController () <UIAlertViewDelegate, UITableViewDelegate, UISplitViewControllerDelegate> {
     NSMutableArray *_objects;
     Storage *storage;
     self.detailViewController.master = self;
     self.splitViewController.delegate = self;
     
+    UIBarButtonItem *newFolderBtn = [[UIBarButtonItem alloc] initWithTitle:@"New Folder"
+                                                                     style:UIBarButtonItemStyleBordered
+                                                                    target:self
+                                                                    action:@selector(createNewFolder:)];
+    [self setToolbarItems:[NSArray arrayWithObjects:newFolderBtn, nil] animated:YES];
+    [self.navigationController setToolbarHidden:NO];
+    
     imgFolder = nil;
     imgDocument = nil;
     if (!storage) {
     }
 }
 
+- (void)createNewFolder:(id)sender {
+    NewFolderAlert *alert = [[NewFolderAlert alloc] initWithTitle:@"Folder name:" 
+                                                    message:@"\n"
+                                                   delegate:self
+                                          cancelButtonTitle:@"Cancel"
+                                          otherButtonTitles:@"Done", nil];
+    BackgroundView *back = [[BackgroundView alloc] initWithFrame:CGRectMake(20.0, 43.0, 245.0, 25.0)];
+    [alert addSubview:back];
+    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
+    [alert addSubview:textField];
+    
+    [alert show];
+//    [textField becomeFirstResponder];
+}
 #pragma mark - Item operations
 
 - (void)insertItems {
         if (buttonIndex == 0) {
             [self dismissModalViewControllerAnimated:YES];        
         }
+    } else if ([alertView isKindOfClass:[NewFolderAlert class]]) {
+        if (buttonIndex == 1) {
+            //
+            UITextField *field = [alertView.subviews lastObject];
+            NSString *folderName = [field.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+            if (folderName.length > 0) {
+                FileItem *item = [storage newFolder:folderName];
+                [self insertItem:item];
+            }
+        }
     }
 }
 @end
diff --git a/iOS/Tombo/Tombo/NewFolderAlert.h b/iOS/Tombo/Tombo/NewFolderAlert.h
new file mode 100644 (file)
index 0000000..ff81409
--- /dev/null
@@ -0,0 +1,5 @@
+#import <UIKit/UIKit.h>
+
+@interface NewFolderAlert : UIAlertView
+
+@end
diff --git a/iOS/Tombo/Tombo/NewFolderAlert.m b/iOS/Tombo/Tombo/NewFolderAlert.m
new file mode 100644 (file)
index 0000000..8994bdf
--- /dev/null
@@ -0,0 +1,5 @@
+#import "NewFolderAlert.h"
+
+@implementation NewFolderAlert
+
+@end
index 1525cd3..0060a2b 100644 (file)
@@ -42,4 +42,7 @@
 -(FileItem *)save:(NSString *)note item:(FileItem *)item;
 
 - (void)deleteItem:(FileItem*)item;
+
+- (FileItem *)newFolder:(NSString *)folder;
+
 @end
index f273205..34c2f43 100644 (file)
     [fileManager removeItemAtPath:item.path error:nil];
 }
 
+- (FileItem *)newFolder:(NSString *)folder {
+    NSMutableString *path = [[NSMutableString alloc]initWithCapacity:256];
+    [path appendString:documentRoot];
+    [path appendString:currentDirectory];
+    [path appendString:folder];
+    NSError *error = nil;
+    [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
+    
+    FileItem *item = [FileItem allocWithName:folder];
+    item.path = path;
+    item.isDirectory = YES;
+    return item;
+}
+
 @end
index 01b4d95..ade9701 100644 (file)
             <point key="canvasLocation" x="891" y="64"/>
         </scene>
     </scenes>
-    <classes>
-        <class className="EditViewController" superclassName="UIViewController">
-            <source key="sourceIdentifier" type="project" relativePath="./Classes/EditViewController.h"/>
-            <relationships>
-                <relationship kind="action" name="cancel:"/>
-                <relationship kind="action" name="done:"/>
-                <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"/>
     <inferredMetricsTieBreakers>
         <segue reference="aht-5S-Kxw"/>
     </inferredMetricsTieBreakers>
-</document>
\ No newline at end of file
+</document>