OSDN Git Service

AlertView related refactoring.
[tombo/Tombo.git] / iOS / Tombo / Tombo / MasterViewController.m
index 21f278e..bc7fdf6 100644 (file)
@@ -8,29 +8,7 @@
 #import "FileItem.h"
 #import "PasswordManager.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> {
+@interface MasterViewController () <UITableViewDelegate, UISplitViewControllerDelegate> {
     NSMutableArray *_objects;
     Storage *storage;
     PasswordManager *passwordManager;
 }
 
 - (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];
+    NewFolderAlert *alert = [[NewFolderAlert alloc] initWithDefault];
+    NSString *folderName = [alert showAndWait];
+    if (folderName) {
+        FileItem *item = [storage newFolder:folderName];
+        [self insertItem:item];
+    }
 }
 #pragma mark - Item operations
 
 
 - (void)editViewControllerDidCancel:(EditViewController *)controller {
     if (controller.isModify) {
-        UIAlertView *alert = [[EditCancelAlert alloc] initWithTitle:@"Confirm" 
-                                                        message:@"Note is modified. Are you sure to discard changes?" delegate:self 
-                                              cancelButtonTitle:@"OK"
-                                              otherButtonTitles:@"Cancel", nil];
-        [alert show];
+        EditCancelAlert *cancel = [[EditCancelAlert alloc] initWithDefault];
+        if ([cancel showAndWait]) {
+            [self dismissModalViewControllerAnimated:YES];                    
+        }
     } else {
         [self dismissModalViewControllerAnimated:YES];                
     }
     [self insertItem:newItem];
 }
 
-#pragma mark - AlertViewDelegate
-
--(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
-    if ([alertView isKindOfClass:[EditCancelAlert class]]) {
-        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