//
//  CreateDirectoryViewController.m
//  FilesystemExplorer
//
//  Created by Chris Adamson on 11/5/08.
//  Copyright 2008 Subsequently and Furthermore, Inc.. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//


#import "CreateDirectoryViewController.h"


@implementation CreateDirectoryViewController

@synthesize parentDirectoryPath, directoryViewController;

 
//START:code.FileSystemExplorer.create-directory
- (void)  createNewDirectory {
	[directoryNameField resignFirstResponder];
	NSString *newDirectoryPath =
		[parentDirectoryPath stringByAppendingPathComponent:
			directoryNameField.text];
	[[NSFileManager defaultManager] 
		createDirectoryAtPath:newDirectoryPath
		attributes: nil];
	
	[directoryViewController loadDirectoryContents];
	[directoryViewController.tableView reloadData];
	[self.navigationController popViewControllerAnimated:YES];
}
//END:code.FileSystemExplorer.create-directory


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (textField == directoryNameField)
		[directoryNameField resignFirstResponder];
	return YES;
}


// Implement viewDidLoad to do additional setup after loading the view.
//START:code.FilesystemExplorer.create-directory-viewdidload
- (void)viewDidLoad {
    [super viewDidLoad];
	UIBarButtonItem *saveButton =
		[[UIBarButtonItem alloc]
			initWithBarButtonSystemItem: UIBarButtonSystemItemSave
			target: self
			action: @selector(createNewDirectory)];
	self.navigationItem.rightBarButtonItem = saveButton;
	[saveButton release];
}
//END:code.FilesystemExplorer.create-directory-viewdidload

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[parentDirectoryPath release];
	[directoryViewController release];
    [super dealloc];
}


@end
