OSDN Git Service

Implement move folder.
authorHirami <tomohisa.hirami@nifty.com>
Thu, 29 Mar 2012 10:06:08 +0000 (19:06 +0900)
committerHirami <tomohisa.hirami@nifty.com>
Thu, 29 Mar 2012 10:06:08 +0000 (19:06 +0900)
Share UIImage instance for memory reservation.

iOS/Tombo/COPYRIGHT.txt
iOS/Tombo/Tombo.xcodeproj/project.pbxproj
iOS/Tombo/Tombo/FileItem.h
iOS/Tombo/Tombo/FileItem.m
iOS/Tombo/Tombo/MasterViewController.m
iOS/Tombo/Tombo/Storage.h
iOS/Tombo/Tombo/Storage.m
iOS/Tombo/Tombo/sub_blue_up-32.png [new file with mode: 0644]
iOS/Tombo/Tombo/sub_blue_up-48.png [new file with mode: 0644]

index ad2cd37..cb0485e 100644 (file)
@@ -3,6 +3,8 @@ Source code:
 
 ====
 Icons:
+  Folder-*.png
+  TextDocument-*.png
        By Photoshopedia
                http://www.photoshopedia.com/
                http://www.iconspedia.com/pack/xedia-2164/
@@ -11,3 +13,24 @@ License:  The icons are free to use for both personal and commercial projects. Y
 
 All rights reserved Photoshopedia - http://www.photoshopedia.com/373
 ====
+Icons:
+    sub_blue_up-*.png
+               http://www.iconspedia.com/icon/sub-blue-up-14-07.html
+----------------------------------------------------
+Primo Icon Set by Webdesigner Depot
+http://www.webdesignerdepot.com
+----------------------------------------------------
+
+TERMS OF USE:
+
+This product may be used free of charge for personal or commercial purposes. Attribution is not necessary but will be appreciated.
+
+You may not modify, sell or distribute this file on any websites, CD-Roms or any other means, either electronically or other without written consent from Webdesigner Depot. 
+
+If you'd like to share this file with others, please direct them to our website where they can download their copy.
+
+Thanks for supporting our website and enjoy!
+
+
+Webdesigner Depot
+
index 7167c05..4226a57 100644 (file)
@@ -29,6 +29,8 @@
                92DE33A015231CFC00AD06EC /* Folder-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339C15231CFC00AD06EC /* Folder-48.png */; };
                92DE33A115231CFC00AD06EC /* TextDocument-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339D15231CFC00AD06EC /* TextDocument-32.png */; };
                92DE33A215231CFC00AD06EC /* TextDocument-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339E15231CFC00AD06EC /* TextDocument-48.png */; };
+               92DE33B11524478E00AD06EC /* sub_blue_up-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */; };
+               92DE33B21524478E00AD06EC /* sub_blue_up-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE33B01524478E00AD06EC /* sub_blue_up-48.png */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -74,6 +76,8 @@
                92DE339C15231CFC00AD06EC /* Folder-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Folder-48.png"; sourceTree = "<group>"; };
                92DE339D15231CFC00AD06EC /* TextDocument-32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TextDocument-32.png"; sourceTree = "<group>"; };
                92DE339E15231CFC00AD06EC /* TextDocument-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TextDocument-48.png"; sourceTree = "<group>"; };
+               92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sub_blue_up-32.png"; sourceTree = "<group>"; };
+               92DE33B01524478E00AD06EC /* sub_blue_up-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sub_blue_up-48.png"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                92DE339C15231CFC00AD06EC /* Folder-48.png */,
                                92DE339D15231CFC00AD06EC /* TextDocument-32.png */,
                                92DE339E15231CFC00AD06EC /* TextDocument-48.png */,
+                               92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */,
+                               92DE33B01524478E00AD06EC /* sub_blue_up-48.png */,
                        );
                        name = images;
                        sourceTree = "<group>";
                                92DE33A015231CFC00AD06EC /* Folder-48.png in Resources */,
                                92DE33A115231CFC00AD06EC /* TextDocument-32.png in Resources */,
                                92DE33A215231CFC00AD06EC /* TextDocument-48.png in Resources */,
+                               92DE33B11524478E00AD06EC /* sub_blue_up-32.png in Resources */,
+                               92DE33B21524478E00AD06EC /* sub_blue_up-48.png in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 44383e7..d5c2535 100644 (file)
@@ -7,6 +7,7 @@
 @property NSString *name;
 @property NSString *path;
 @property BOOL isDirectory;
+@property BOOL isUp;
 
 -(NSString*)description;
 
index 43a3559..08eb0dc 100644 (file)
@@ -5,6 +5,7 @@
 @synthesize name;
 @synthesize path;
 @synthesize isDirectory;
+@synthesize isUp;
 
 -(NSString*)description {
     return name;
@@ -14,6 +15,7 @@
     FileItem *fileItem = [FileItem alloc];
     fileItem.name = name;
     fileItem.isDirectory = NO;
+    fileItem.isUp = NO;
     return fileItem;
 }
 
index a282608..c89bffb 100644 (file)
@@ -8,6 +8,10 @@
 @interface MasterViewController () {
     NSMutableArray *_objects;
     Storage *storage;
+    
+    UIImage *imgFolder;
+    UIImage *imgDocument;
+    UIImage *imgUp;
 }
 @end
 
     self.navigationItem.rightBarButtonItem = addButton;
     self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
     
+    imgFolder = nil;
+    imgDocument = nil;
     if (!storage) {
         storage = [Storage init];
     }
     // Load initial items.
-    for (NSString *file in [storage listItems]) {
-        [self insertItem: file];
-    }
+    [self insertItems];
 }
 
 - (void)viewDidUnload
 
 - (void)insertNewObject:(id)sender
 {
-    if (!_objects) {
-        _objects = [[NSMutableArray alloc] init];
+    FileItem *item = [FileItem allocWithName: [[NSDate date] description]];
+    [self insertItem: item];
+}
+
+#pragma mark - Item operations
+
+- (void)insertItems {
+    for (FileItem *file in [storage listItems]) {
+        [self insertItem: file];
+    }    
+    if (!storage.isTopDir) {
+        FileItem *up = [FileItem allocWithName:@"UP"];
+        up.isUp = YES;
+        [self insertItem: up];
     }
-    [_objects insertObject:[NSDate date] atIndex:0];
-    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
-    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
 }
 
-- (void)insertItem:(NSString *)item {
+- (void)removeAllItems {
+    NSUInteger n = [_objects count];
+    
+    NSMutableArray *rmItems = [[NSMutableArray alloc] initWithCapacity:n];
+    for (int i = 0; i < n; i++) {
+        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
+        [rmItems addObject: indexPath];
+    }
+    [_objects removeAllObjects];
+    [self.tableView deleteRowsAtIndexPaths: rmItems withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
+- (void)insertItem:(FileItem *)item {
     if (!_objects) {
         _objects = [[NSMutableArray alloc] init];
     }
 
     FileItem *fItem = [_objects objectAtIndex:indexPath.row];
     cell.textLabel.text = [fItem name];
-    if (fItem.isDirectory) {
-        cell.imageView.image = [UIImage imageNamed:@"Folder-32"];
+    if (fItem.isUp) {
+        if (!imgUp) {
+            imgUp = [UIImage imageNamed:@"sub_blue_up-32"];
+        }
+        cell.imageView.image = imgUp;
+    } else if (fItem.isDirectory) {
+        if (!imgFolder) {
+            imgFolder = [UIImage imageNamed:@"Folder-32"];
+
+        }
+        cell.imageView.image = imgFolder;
     } else {
-        cell.imageView.image = [UIImage imageNamed:@"TextDocument-32"];
+        if (!imgDocument) {
+            imgDocument = [UIImage imageNamed:@"TextDocument-32"];
+        }
+        cell.imageView.image = imgDocument;
     }
     return cell;
 }
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
-        NSDate *object = [_objects objectAtIndex:indexPath.row];
-        self.detailViewController.detailItem = object;
+        FileItem *item = [_objects objectAtIndex:indexPath.row];
+        if (item.isUp) {
+            // switch view items
+            [self removeAllItems];
+            [storage updir];
+            [self insertItems];
+        } else if (item.isDirectory) {
+            // switch view items
+            [self removeAllItems];
+            [storage chdir: item.name];
+            [self insertItems];
+            
+        } else {
+            [self.detailViewController setDetailItem:item];
+        }
     }
 }
 
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
     if ([[segue identifier] isEqualToString:@"showDetail"]) {
-        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
+        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];         
         FileItem *item = [_objects objectAtIndex:indexPath.row];
-        if (item.isDirectory) {
+        if (item.isUp) {
+            CustomSegue *customSegue = (CustomSegue*)segue;
+            customSegue.isStop = YES;
+
+            // switch view items
+            [self removeAllItems];
+            [storage updir];
+            [self insertItems];
+        } else if (item.isDirectory) {
             CustomSegue *customSegue = (CustomSegue*)segue;
             customSegue.isStop = YES;
+            
+            // switch view items
+            [self removeAllItems];
+            [storage chdir: item.name];
+            [self insertItems];
+            
         } else {
             [[segue destinationViewController] setDetailItem:item];
         }
index 86247e7..cb44521 100644 (file)
 
 + (id)init;
 
+/*
+ * Enumerate current directory and return array of FileItem.
+ */
 -(NSArray*)listItems;
 
+/*
+ * Change directory.
+ */
+-(void)chdir:(NSString *)subdir;
+
+-(void)updir;
+
+/*
+ * Is current directory Top?
+ */
+-(BOOL)isTopDir;
 @end
index 024065c..9dca1f3 100644 (file)
@@ -19,9 +19,6 @@
     return storage;
 }
 
-/*
- * Enumerate current directory and return array of FileItem.
- */
 -(NSArray*)listItems {
     NSError *error = nil;
     NSString *currentPath = [documentRoot stringByAppendingString: currentDirectory];
     return result;
 }
 
+-(void)chdir:(NSString *)subdir {
+    NSString *newCurrent = [currentDirectory stringByAppendingPathComponent:subdir];
+    self.currentDirectory = newCurrent;
+}
+
+-(void)updir {
+    NSString *parent = [currentDirectory stringByDeletingLastPathComponent];
+    if ([parent isEqualToString:@"/"]) {
+        self.currentDirectory = parent;
+    } else {
+        self.currentDirectory = [parent stringByAppendingString:@"/"];        
+    }
+}
+
+-(BOOL)isTopDir {
+    return [currentDirectory isEqualToString:@"/"];
+}
 @end
diff --git a/iOS/Tombo/Tombo/sub_blue_up-32.png b/iOS/Tombo/Tombo/sub_blue_up-32.png
new file mode 100644 (file)
index 0000000..01ee7db
Binary files /dev/null and b/iOS/Tombo/Tombo/sub_blue_up-32.png differ
diff --git a/iOS/Tombo/Tombo/sub_blue_up-48.png b/iOS/Tombo/Tombo/sub_blue_up-48.png
new file mode 100644 (file)
index 0000000..98aca4c
Binary files /dev/null and b/iOS/Tombo/Tombo/sub_blue_up-48.png differ