File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -546,7 +546,14 @@ - (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName
546546 self.editor .selectedRange = selection;
547547 }
548548 }
549- return [super writeToURL: url ofType: typeName error: outError];
549+ BOOL ok = [super writeToURL: url ofType: typeName error: outError];
550+ if (ok)
551+ {
552+ NSDocumentController *controller =
553+ [NSDocumentController sharedDocumentController ];
554+ [controller mp_noteNewRecentDocumentURL: url];
555+ }
556+ return ok;
550557}
551558
552559- (NSData *)dataOfType : (NSString *)typeName error : (NSError **)outError
@@ -564,6 +571,11 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
564571
565572 self.loadedString = content;
566573 [self reloadFromLoadedString ];
574+
575+ // Ensure the file is registered for the system "Open Recent" menu.
576+ NSDocumentController *controller =
577+ [NSDocumentController sharedDocumentController ];
578+ [controller mp_noteNewRecentDocumentURL: self .fileURL];
567579 return YES ;
568580}
569581
Original file line number Diff line number Diff line change 1313- (__kindof NSDocument *)createNewEmptyDocumentForURL : (NSURL *)url
1414 display : (BOOL )display error : (NSError * __autoreleasing *)error ;
1515
16+ // Explicitly note a recently used document URL for the system "Open Recent"
17+ // menu. We filter out temporary files to avoid polluting the list with app
18+ // internals (help/treat files, etc.).
19+ - (void )mp_noteNewRecentDocumentURL : (NSURL *)url ;
20+
1621@end
Original file line number Diff line number Diff line change 1010
1111@implementation NSDocumentController (Document)
1212
13+ - (void )mp_noteNewRecentDocumentURL : (NSURL *)url
14+ {
15+ if (!url || !url.isFileURL )
16+ return ;
17+
18+ NSString *path = url.path ;
19+ if (!path.length )
20+ return ;
21+
22+ // Skip temp files (help, treats, other internal/generated docs).
23+ NSString *tmp = NSTemporaryDirectory ();
24+ if (tmp.length )
25+ {
26+ NSString *tmpResolved =
27+ [[tmp stringByStandardizingPath ] stringByResolvingSymlinksInPath ];
28+ if (tmpResolved.length && ![tmpResolved hasSuffix: @" /" ])
29+ tmpResolved = [tmpResolved stringByAppendingString: @" /" ];
30+
31+ NSString *pathResolved =
32+ [[path stringByStandardizingPath ] stringByResolvingSymlinksInPath ];
33+ if (tmpResolved.length && [pathResolved hasPrefix: tmpResolved])
34+ return ;
35+ }
36+
37+ // Recent-documents updates are UI-adjacent; keep it on the main queue.
38+ dispatch_async (dispatch_get_main_queue (), ^{
39+ [self noteNewRecentDocumentURL: url];
40+ });
41+ }
42+
1343- (__kindof NSDocument *)createNewEmptyDocumentForURL : (NSURL *)url
1444 display : (BOOL )display error : (NSError * __autoreleasing *)error
1545{
@@ -24,6 +54,7 @@ - (__kindof NSDocument *)createNewEmptyDocumentForURL:(NSURL *)url
2454
2555 doc.draft = YES ;
2656 doc.fileURL = url;
57+ [self mp_noteNewRecentDocumentURL: url];
2758 return doc;
2859}
2960
You can’t perform that action at this time.
0 commit comments