Skip to content

Commit 1ac3107

Browse files
author
Chris Wilson
committed
Adds logic to simplify the opening of simulators core data.
1 parent 72ee557 commit 1ac3107

4 files changed

Lines changed: 339 additions & 91 deletions

File tree

CoreDataUtil/OpenFileSheetController.m

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,16 @@ - (IBAction)simulatorTabSimulatorAppButtonAction:(id)sender
515515
[self.processSelectorBox setLineBreakMode:NSLineBreakByTruncatingMiddle];
516516
[self.processSelectorBox setPlaceholderString:@"Select Managed Object Model"];
517517

518-
NSURL* simulatorUrl = [[self applicationSupportDirectory] URLByAppendingPathComponent:@"iPhone Simulator"];
518+
NSURL* simulatorUrl = nil; //[[self applicationSupportDirectory] URLByAppendingPathComponent:@"iPhone Simulator"];
519+
//SimulatorItem* simulatorItem = [self.simulatorSourceList itemAtRow:[self.simulatorSourceList selectedRow]];
520+
if ([self.simulatorTabModelTextField stringValue] == nil || [[self.simulatorTabModelTextField stringValue] length] == 0) {
521+
NSLog(@"TODO: prompt user to select an app first.");
522+
NSBeep();
523+
return;
524+
} else {
525+
simulatorUrl = [NSURL URLWithString: [self.simulatorTabModelTextField stringValue]];
526+
}
527+
519528

520529
NSSet* paths = [self filesWithExtension:[simulatorUrl path] :MFL_MOM_FILE_EXTENSION];
521530
NSMutableArray* apps = [NSMutableArray arrayWithCapacity:0];
@@ -565,8 +574,46 @@ - (IBAction)simulatorTabSimulatorAppButtonAction:(id)sender
565574

566575
- (IBAction)tabStoreFileButtonAction:(id)sender
567576
{
568-
NSTextField* storeTextField = [self currentPersistenceTextField];
569-
[self selectDbFileButtonAction:self.simulatorTabModelTextField persistenceTextField:storeTextField directoryURL:nil];
577+
if (currentTab == SimulatorTab) {
578+
SimulatorItem* simulatorItem = [self.simulatorSourceList itemAtRow:[self.simulatorSourceList selectedRow]];
579+
if (simulatorItem.itemType != MFLAppItem) {
580+
NSLog(@"TODO: prompt user to select app first.");
581+
NSBeep();
582+
return;
583+
}
584+
585+
NSURL* directoryURL = [NSURL URLWithString:simulatorItem.documentsFolder];
586+
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
587+
if (directoryURL != nil) {
588+
[openDlg setDirectoryURL:directoryURL];
589+
} else {
590+
[openDlg setDirectoryURL:self.momFileUrl];
591+
}
592+
593+
[openDlg setCanChooseFiles:YES];
594+
595+
if ([openDlg runModal] == NSOKButton)
596+
{
597+
NSString *fileString = [[openDlg URLs][0] absoluteString];
598+
if ([fileString hasSuffix:MFL_COREDATA_PROJECT_EXTENSION])
599+
{
600+
NSDictionary *filePaths = [[NSDictionary alloc] initWithContentsOfURL:[openDlg URLs][0]];
601+
self.dbFileUrl = [NSURL URLWithString:filePaths[MFL_DB_FILE_KEY]];
602+
[[self currentPersistenceTextField] setStringValue:[self.dbFileUrl relativePath]];
603+
}
604+
else
605+
{
606+
self.dbFileUrl = [openDlg URLs][0];
607+
[[self currentPersistenceTextField] setStringValue:[self.dbFileUrl relativePath]];
608+
}
609+
610+
[self showOrHideOpenButton];
611+
}
612+
613+
} else {
614+
NSTextField* storeTextField = [self currentPersistenceTextField];
615+
[self selectDbFileButtonAction:self.simulatorTabModelTextField persistenceTextField:storeTextField directoryURL:nil];
616+
}
570617
}
571618

572619
- (IBAction)tabStoreApplicationSupportButtonAction:(id)sender
@@ -797,5 +844,20 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableC
797844
return NO;
798845
}
799846

847+
- (void)outlineViewSelectionDidChange:(NSNotification *)notification {
848+
//NSLog(@"Item Selected: %@", notification);
849+
850+
SimulatorItem* simulatorItem = [self.simulatorSourceList itemAtRow:[self.simulatorSourceList selectedRow]];
851+
if (simulatorItem.itemType == MFLAppItem) {
852+
NSLog(@"Selected Application: %@", simulatorItem.label);
853+
//self.momFileUrl = [NSURL URLWithString:simulatorItem.fullPath];
854+
[self.simulatorTabModelTextField setStringValue:simulatorItem.fullAppPath];
855+
[self showOrHidePersistenceButtons];
856+
//NSLog(@"Documents: %@", simulatorItem.documentsFolder);
857+
//[self.currentPersistenceTextField setStringValue:simulatorItem.documentsFolder];
858+
}
859+
}
860+
861+
800862

801863
@end

0 commit comments

Comments
 (0)