diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index ccd5dbe8..ae549760 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -7,6 +7,7 @@ #import #import #import +#import #import #import #import @@ -271,6 +272,7 @@ namespace [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:[NSUserDefaults standardUserDefaults]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActiveNotification:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidResignActiveNotification:) name:NSApplicationDidResignActiveNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileManagerWillDeleteItemAtPath:) name:OakFileManagerWillDeleteItemAtPath object:nil]; } return self; } @@ -568,6 +570,25 @@ namespace return NO; } +- (void)fileManagerWillDeleteItemAtPath:(NSNotification*)aNotification +{ + NSDictionary* userInfo = [aNotification userInfo]; + NSString* path = userInfo[OakFileManagerPathKey]; + + NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; + for(size_t i = 0; i < _documents.size(); ++i) + { + document::document_ptr doc = _documents[i]; + if(!doc->is_modified() && path::is_child(doc->path(), to_s(path))) + [indexSet addIndex:i]; + } + + id oldFirstResponder = self.window.firstResponder; + [self closeTabsAtIndexes:indexSet askToSaveChanges:NO createDocumentIfEmpty:YES]; + if(oldFirstResponder && oldFirstResponder != self.window.firstResponder) + [self.window makeFirstResponder:oldFirstResponder]; +} + + (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender { BOOL restoresSession = ![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableSessionRestoreKey];