forked from jerrykrinock/CategoriesObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSDocumentController+MoreRecents.m
46 lines (40 loc) · 1.33 KB
/
NSDocumentController+MoreRecents.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
42
43
44
45
46
#import "NSDocumentController+MoreRecents.h"
#import "NSURL+FileDisplayName.h"
#import "NSMenuItem+Font.h"
@implementation NSDocumentController (MoreRecents)
- (void)forgetRecentDocumentUrl:(NSURL*)url {
if (url) {
NSArray* recentDocumentURLs = [self recentDocumentURLs] ;
[self clearRecentDocuments:self] ;
// Because noteNewRecentDocumentURL: adds to the top
// of the list, I need a reverse enumeration to avoid
// reversing the order of the remaining recent documents
NSEnumerator* e = [recentDocumentURLs reverseObjectEnumerator] ;
for (NSURL* aUrl in e) {
if (![aUrl isEqual:url]) {
[self noteNewRecentDocumentURL:aUrl] ;
}
}
}
}
- (NSArray*)recentDocumentDisplayNames {
return [[self recentDocumentURLs] valueForKey:@"fileDisplayName"] ;
}
- (NSMenu*)recentDocumentsSubmenuWithTarget:(id)target
action:(SEL)action
fontSize:(CGFloat)fontSize {
NSMenu* submenu = [[NSMenu alloc] initWithTitle:@"reecentDox"] ;
for (NSURL* url in [self recentDocumentURLs]) {
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:[url fileDisplayName]
action:action
keyEquivalent:@""] ;
[item setFontColor:nil
size:fontSize] ;
[item setTarget:target] ;
[item setRepresentedObject:url] ;
[submenu addItem:item] ;
[item release] ;
}
return [submenu autorelease] ;
}
@end