add NSDocumentController type discovery

This commit is contained in:
ckegel 2023-04-12 19:02:09 -04:00
parent bb0c134428
commit 81d2422c67
3 changed files with 7 additions and 12 deletions

View File

@ -159,7 +159,7 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
error: (NSError **) error
{
NSUnimplementedMethod();
NSString *docType = [options objectForKey:NSDocumentTypeDocumentAttribute];
NSString *docType = [options objectForKey:@"NSDocumentTypeDocumentAttribute"];
if(docType == nil){
NSLog(@"NSAttributedString initFromData - inferring document type");
@ -207,6 +207,7 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
}
else {
return nil;
}
}
- initWithDocFormat: (NSData *) werd
@ -252,6 +253,7 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
}
- initWithRTF: (NSData *) rtf documentAttributes: (NSDictionary **) attributes {
NSLog(@"NSAttributedString - initializing from RTF");
NSAttributedString *string =
[NSRichTextReader attributedStringWithData: rtf];
if (string == nil) {
@ -285,7 +287,6 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
documentAttributes: (NSDictionary **) attributes
error: (NSError **) error
{
NSUnimplementedMethod();
NSLog(@"NSAttributedString - initializing from URL");
NSData *data = [NSData dataWithContentsOfURL: url];
return [self initWithData:data options:options documentAttributes:attributes error:error];

View File

@ -305,13 +305,11 @@ static NSDocumentController *shared = nil;
//TODO: move below code to documentClassForType
for(NSDictionary *type in _fileTypes){
for(NSString *contentType in [type objectForKey:@"LSItemContentTypes"]){
return [type objectForKey:@"CFBundleTypeName"];
if([contentType isEqual: UTI])
return [type objectForKey:@"CFBundleTypeName"];
}
}
}
else{
//TODO:Handle Error Here
}
return nil;
}
@ -330,13 +328,11 @@ static NSDocumentController *shared = nil;
error: (NSError **) error
{
id result;
NSLog(@"DocController - making %@ from URL", type);
Class class = [self documentClassForType: type];
NSLog(@"DocController - initializing Document");
result = [[[class alloc] initWithContentsOfURL: url
ofType: type ] autorelease];
NSLog(@"NSDocController - made from URL");
ofType: type] autorelease];
return result;
}
@ -422,7 +418,6 @@ static NSDocumentController *shared = nil;
- openUntitledDocumentAndDisplay: (BOOL) display error: (NSError **) error {
NSString *type = [self defaultType];
/* Cocoa documentation says:
"For backward binary compatibility with Mac OS X v10.3 and earlier,
the default implementation of this method instead invokes

View File

@ -213,5 +213,4 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
NSLog(@"NSMutableAttributedString readFromURL: - hopefully finished reading!");
return true;
}
@end