From d8df42dcb4f5b97ac5e732b3a4203c100f703ed4 Mon Sep 17 00:00:00 2001 From: Hirami Date: Tue, 3 Apr 2012 19:06:00 +0900 Subject: [PATCH] Implement delete file/folder. --- iOS/Tombo/Tombo/MasterViewController.m | 17 +++++++++++++++-- iOS/Tombo/Tombo/Storage.h | 2 ++ iOS/Tombo/Tombo/Storage.m | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/iOS/Tombo/Tombo/MasterViewController.m b/iOS/Tombo/Tombo/MasterViewController.m index e12687f..0188964 100644 --- a/iOS/Tombo/Tombo/MasterViewController.m +++ b/iOS/Tombo/Tombo/MasterViewController.m @@ -6,7 +6,7 @@ #import "Storage.h" #import "FileItem.h" -@interface MasterViewController () { +@interface MasterViewController () { NSMutableArray *_objects; Storage *storage; @@ -35,6 +35,7 @@ // Do any additional setup after loading the view, typically from a nib. self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController]; self.detailViewController.master = self; + self.splitViewController.delegate = self; imgFolder = nil; imgDocument = nil; @@ -58,6 +59,7 @@ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { + return YES; } } @@ -120,6 +122,11 @@ i++; } } + +- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation { + return NO; +} + #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -161,14 +168,20 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. + FileItem *item = [_objects objectAtIndex:indexPath.row]; + if (item.isUp) return NO; return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { + FileItem *item = [_objects objectAtIndex:indexPath.row]; + [storage deleteItem:item]; + [_objects removeObjectAtIndex:indexPath.row]; - [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } diff --git a/iOS/Tombo/Tombo/Storage.h b/iOS/Tombo/Tombo/Storage.h index 1a25abe..1525cd3 100644 --- a/iOS/Tombo/Tombo/Storage.h +++ b/iOS/Tombo/Tombo/Storage.h @@ -40,4 +40,6 @@ * If path is not changed, returns item itself. */ -(FileItem *)save:(NSString *)note item:(FileItem *)item; + +- (void)deleteItem:(FileItem*)item; @end diff --git a/iOS/Tombo/Tombo/Storage.m b/iOS/Tombo/Tombo/Storage.m index 012ec76..f273205 100644 --- a/iOS/Tombo/Tombo/Storage.m +++ b/iOS/Tombo/Tombo/Storage.m @@ -153,4 +153,8 @@ return p; } +- (void)deleteItem:(FileItem*)item { + [fileManager removeItemAtPath:item.path error:nil]; +} + @end -- 2.11.0