@@ -26,74 +26,8 @@ @implementation MFLAppDelegate
2626
2727
2828- (BOOL ) openFileHelper : (NSString *) filename {
29- if ([filename hasSuffix: MFL_COREDATA_PROJECT_EXTENSION ]) {
30-
31- NSLog (@" Load Project File: [%@ ]" , filename);
32- NSDictionary * project = [NSDictionary dictionaryWithContentsOfFile: filename];
33- NSString * momFilePath = project[MFL_MOM_FILE_KEY ];
34- NSString * dbFilePath = project[MFL_DB_FILE_KEY ];
35- NSNumber * persistenceFormat = project[MFL_DB_FORMAT_KEY ];
36- if (persistenceFormat == nil ) {
37- persistenceFormat = [NSNumber numberWithInt: MFL_SQLiteStoreType];
38- }
39-
40- NSURL * momUrl = nil ;
41- NSURL * dbUrl = nil ;
42- if (momFilePath != nil ) {
43- momUrl = [NSURL URLWithString: momFilePath];
44- }
45-
46- if (dbFilePath != nil ) {
47- dbUrl = [NSURL URLWithString: dbFilePath];
48- }
49-
50- // if iOS, check if file exists otherwise search for it because it may have moved.
51- NSError *err;
52- if ([momUrl checkResourceIsReachableAndReturnError: &err] == NO ) {
53- // is iOS Simulator?
54- NSRange pathRange = [momFilePath rangeOfString: APPLICATIONS_DIR ];
55- if (pathRange.location != NSNotFound ) {
56- // This is an iOS simpulator project
57- NSLog (@" momPath: %@ " , momFilePath);
58- NSString * applicationsPath = [self convertToIosApplicationsBasePath: momFilePath];
59- NSString * relativeMomPath = [self convertToApplicationPath: momFilePath];
60- NSString * relativeDBPath = [self convertToApplicationPath: dbFilePath];
61-
62- // Scan through UUID directories to see if any match our paths
63- // Search through each UUID to find our files
64- NSFileManager *fileManager = [NSFileManager defaultManager ];
65- NSError * error;
66- NSArray * contents = [fileManager contentsOfDirectoryAtURL: [NSURL URLWithString: applicationsPath] includingPropertiesForKeys: @[NSURLFileResourceTypeDirectory ] options: 0 error: &error];
67- for (NSString * content in contents) {
68- NSLog (@" Found: %@ " , content);
69- NSString * testMomPath = [NSString stringWithFormat: @" %@%@ " ,content, relativeMomPath];
70- NSURL * testMomUrl = [NSURL URLWithString: testMomPath];
71- if ([testMomUrl checkResourceIsReachableAndReturnError: &err] == NO ) {
72- continue ;
73- }
74-
75- NSString * testDBPath = [NSString stringWithFormat: @" %@%@ " , content, relativeDBPath];
76- NSURL * testDBUrl = [NSURL URLWithString: testDBPath];
77- if ([testDBUrl checkResourceIsReachableAndReturnError: &err] == NO ) {
78- continue ;
79- }
80-
81- // Both files exist so use this path instead.
82- momFilePath = testMomPath;
83- dbFilePath = testDBPath;
84-
85- momUrl = [NSURL URLWithString: momFilePath];
86- dbUrl = [NSURL URLWithString: dbFilePath];
87-
88- // Exit for loop
89- break ;
90- }
91- }
92- }
93-
94-
95- BOOL result = [self .mainWindowController openFiles: momUrl persistenceFile: dbUrl persistenceType: [persistenceFormat intValue ]];
96-
29+ if ([filename hasSuffix: MFL_COREDATA_PROJECT_EXTENSION ]) {
30+ BOOL result = [self .mainWindowController openProject: filename];
9731 if (result)
9832 {
9933 [self addRecentDocument: [NSURL fileURLWithPath: filename]];
@@ -210,6 +144,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
210144 [self newAction: aNotification];
211145 }
212146 }
147+
148+ // bring app to foreground
149+ [NSApp activateIgnoringOtherApps: YES ];
213150}
214151
215152+ (NSUInteger )indexOfArgument : (NSString *)argumentName inArguments : (NSArray *)arguments
@@ -421,14 +358,17 @@ - (IBAction)saveAction:(id)sender
421358 MFL_MOM_FILE_KEY : [momfileUrl absoluteString ],
422359 MFL_DB_FORMAT_KEY : @((int )persistenceType),
423360 MFL_DB_FILE_KEY : [persistenceUrl absoluteString ]};
424-
425- if (![stuffToSave writeToURL: [saveDlg URL ] atomically: NO ])
361+
362+ NSURL *saveUrl = [saveDlg URL ];
363+ if (![stuffToSave writeToURL: saveUrl atomically: NO ])
426364 {
427365 NSLog (@" Error in saving file!" );
428366 }
429367 else
430368 {
431- [self addRecentDocument: [saveDlg URL ]];
369+ [self addRecentDocument: saveUrl];
370+
371+ [self .mainWindowController setProjectFile: saveUrl.absoluteString];
432372 }
433373 self.projectHasChanged = NO ;
434374 } else {
@@ -441,7 +381,7 @@ - (IBAction)saveAction:(id)sender
441381- (NSApplicationTerminateReply )applicationShouldTerminate : (NSApplication *)sender
442382{
443383 if (self.projectHasChanged ) {
444- // Promt user to save project before exiting
384+ // Prompt user to save project before exiting
445385 NSString *question = NSLocalizedString(@" Core Data Pro project not saved. Quit without saving?" , @" UnsavedProjectChanges" );
446386 NSString *info = NSLocalizedString(@" Quitting now will lose any changes you have made since the last successful save" , @" QuitDiscardsChangesText" );
447387 NSString *quitButton = NSLocalizedString(@" Exit" , @" QuitAnywayButtonText" );
@@ -495,29 +435,5 @@ - (IBAction)reportAnIssueAction:(id)sender
495435 [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" https://github.com/yepher/CoreDataUtility/issues" ]];
496436}
497437
498- - (NSString *) convertToIosApplicationsBasePath : (NSString *) filePath {
499- NSRange pathRange = [filePath rangeOfString: APPLICATIONS_DIR ];
500- if (pathRange.location == NSNotFound ) {
501- return nil ;
502- }
503-
504- return [filePath substringToIndex: pathRange.location+pathRange.length];
505- }
506-
507- - (NSString *) convertToApplicationPath : (NSString *) filePath {
508- NSRange pathRange = [filePath rangeOfString: APPLICATIONS_DIR ];
509- if (pathRange.location == NSNotFound ) {
510- return nil ;
511- }
512-
513- NSUInteger len = ((pathRange.location +pathRange.length ) +36 );
514-
515- if ([filePath length ] <= len) {
516- return nil ;
517- }
518-
519- return [filePath substringFromIndex: len];
520- }
521-
522438
523439@end
0 commit comments