From 9f095a52bc84e8bcfa993bb3ed7188610c664083 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 15 Feb 2013 15:27:55 +0100 Subject: [PATCH] Close files deleted via file browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files with changes are kept open and only files deleted via file browser actually close. It’ll make sense to also close files which are “moved to trash” (but want to do some refactoring before adding that). Closes #512. --- .../DocumentWindow/src/DocumentController.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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];