-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCodaAutosaveOnDeactivatePlugin.m
41 lines (33 loc) · 1.37 KB
/
CodaAutosaveOnDeactivatePlugin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#import "CodaAutosaveOnDeactivatePlugin.h"
@implementation CodaAutosaveOnDeactivatePlugin
- (id)initWithPlugInController:(CodaPlugInsController*)controller_ bundle:(NSBundle*)bundle_ {
self = [super init];
if (self) {
NSString *codaVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
if ([codaVersion hasPrefix:@"1.6."] || [codaVersion hasPrefix:@"1.7"]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidResignActive:)
name:NSApplicationDidResignActiveNotification
object:nil];
}
}
return self;
}
- (void)appDidResignActive:(NSNotification*)notification_ {
NSArray *documents = [[NSDocumentController sharedDocumentController] documents];
NSMutableSet *dirtyEditors = [NSMutableSet set];
for (NSDocument *document in documents) {
[dirtyEditors addObjectsFromArray:[document valueForKey:@"dirtyEditors"]];
}
for (NSDocument *dirtyEditor in dirtyEditors) {
[dirtyEditor saveDocument:nil];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (NSString*)name {
return @"CodaAutosaveOnDeactivate";
}
@end