//
//  iViewController.m
//  oscSenderExample
//
//  Created by Robert Tubb on 07/01/2013.
//
//
#include "presetManager.h"

#import "PresetAlertViewController.h"


extern PresetManager presetManager;
@implementation PresetAlertViewController

- (void)showPresetNamePrompt{
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Save"
                                                     message:@"Enter preset name:"
                                                    delegate:self
                                           cancelButtonTitle:@"Cancel"
                                           otherButtonTitles:@"Enter",nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField * alertTextField = [alert textFieldAtIndex:0];
    alertTextField.keyboardType = UIKeyboardTypeDefault;
    alertTextField.placeholder = @"Preset Name";
    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    NSLog(@"Preset save ");
    if(buttonIndex == 0){
        // cancel
        NSLog(@"preset save was cancelled");
    }else{
        // save it
        presetManager.addPreset([[[alertView textFieldAtIndex:0] text] cStringUsingEncoding:NSASCIIStringEncoding]);
    }
}


- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    UITextField *textField = [alertView textFieldAtIndex:0];
    if ([textField.text length] == 0)
    {
        return NO;
    }
    return YES;
}



@end


// global? again.
PresetAlertViewController *presetAlertViewController = [[PresetAlertViewController alloc] init];
