mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 04:38:13 -05:00
Close files deleted via file browser
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.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#import <OakAppKit/NSMenuItem Additions.h>
|
||||
#import <OakAppKit/OakAppKit.h>
|
||||
#import <OakAppKit/OakFileIconImage.h>
|
||||
#import <OakAppKit/OakFileManager.h>
|
||||
#import <OakAppKit/OakPasteboard.h>
|
||||
#import <OakAppKit/OakSavePanel.h>
|
||||
#import <OakAppKit/OakTabBarView.h>
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user