mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 11:00:59 +00:00
Basic implementation of the initWithData:.. methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27437 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b842490265
commit
d0f3a643c4
2 changed files with 122 additions and 42 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSAttributedString.m (-initWithData:...,
|
||||||
|
-initWithURL:...): Basic implementation.
|
||||||
|
* Source/NSAttributedString.m
|
||||||
|
(NSMutableAttributedString-readFromData:...): Implement.
|
||||||
|
|
||||||
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSDocumentController.m: Remove now unused override helper
|
* Source/NSDocumentController.m: Remove now unused override helper
|
||||||
|
|
|
@ -139,9 +139,9 @@ Class converter_bundles(NSString *format, BOOL producer)
|
||||||
dpath = [dpath stringByAppendingPathComponent: @"Bundles"];
|
dpath = [dpath stringByAppendingPathComponent: @"Bundles"];
|
||||||
dpath = [dpath stringByAppendingPathComponent: @"TextConverters"];
|
dpath = [dpath stringByAppendingPathComponent: @"TextConverters"];
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath: dpath])
|
if ([[NSFileManager defaultManager] fileExistsAtPath: dpath])
|
||||||
direnum = [[NSFileManager defaultManager] enumeratorAtPath: dpath];
|
direnum = [[NSFileManager defaultManager] enumeratorAtPath: dpath];
|
||||||
else
|
else
|
||||||
direnum = nil;
|
direnum = nil;
|
||||||
while (direnum && (path = [direnum nextObject]))
|
while (direnum && (path = [direnum nextObject]))
|
||||||
{
|
{
|
||||||
Class bclass;
|
Class bclass;
|
||||||
|
@ -619,25 +619,20 @@ static Class converter_class(NSString *format, BOOL producer)
|
||||||
fw = [[NSFileWrapper alloc] initWithPath: path];
|
fw = [[NSFileWrapper alloc] initWithPath: path];
|
||||||
AUTORELEASE (fw);
|
AUTORELEASE (fw);
|
||||||
|
|
||||||
return [self initWithRTFDFileWrapper: fw documentAttributes: dict];
|
return [self initWithRTFDFileWrapper: fw documentAttributes: dict];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithURL: (NSURL *)url
|
- (id) initWithURL: (NSURL *)url
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
NSData *data = [url resourceDataUsingCache: YES];
|
NSError *error;
|
||||||
|
NSDictionary *options = [NSDictionary dictionaryWithObject: [url baseURL]
|
||||||
if (data == nil)
|
forKey: NSBaseURLDocumentOption];
|
||||||
{
|
|
||||||
RELEASE (self);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return [self initWithURL: url
|
||||||
// FIXME: This expects the URL to point to a HTML page
|
options: options
|
||||||
return [self initWithHTML: data
|
documentAttributes: dict
|
||||||
baseURL: [url baseURL]
|
error: &error];
|
||||||
documentAttributes: dict];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithRTFDFileWrapper: (NSFileWrapper *)wrapper
|
- (id) initWithRTFDFileWrapper: (NSFileWrapper *)wrapper
|
||||||
|
@ -752,18 +747,32 @@ documentAttributes: (NSDictionary **)dict
|
||||||
- (id) initWithDocFormat: (NSData *)data
|
- (id) initWithDocFormat: (NSData *)data
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
// FIXME
|
NSAttributedString *new;
|
||||||
RELEASE(self);
|
|
||||||
return nil;
|
if (data == nil)
|
||||||
|
{
|
||||||
|
RELEASE (self);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
new = [converter_class(@"DOC", NO)
|
||||||
|
parseData: data
|
||||||
|
documentAttributes: dict
|
||||||
|
class: [self class]];
|
||||||
|
// We do not return self but the newly created object
|
||||||
|
RELEASE (self);
|
||||||
|
return RETAIN (new);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithHTML: (NSData *)data
|
- (id) initWithHTML: (NSData *)data
|
||||||
options: (NSDictionary *)options
|
options: (NSDictionary *)options
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
// FIXME
|
NSURL *baseURL = [options objectForKey: NSBaseURLDocumentOption];
|
||||||
RELEASE(self);
|
|
||||||
return nil;
|
return [self initWithHTML: data
|
||||||
|
baseURL: baseURL
|
||||||
|
documentAttributes: dict];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithData: (NSData *)data
|
- (id) initWithData: (NSData *)data
|
||||||
|
@ -771,7 +780,49 @@ documentAttributes: (NSDictionary **)dict
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSString *type = [options objectForKey: NSDocumentTypeDocumentOption];
|
||||||
|
|
||||||
|
if (type == nil)
|
||||||
|
{
|
||||||
|
// FIXME: try to determine type
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([type isEqualToString: NSDocFormatTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithDocFormat: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSHTMLTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithHTML: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSRTFDTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithRTFD: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSRTFTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithRTF: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSPlainTextDocumentType])
|
||||||
|
{
|
||||||
|
NSStringEncoding encoding = [[options objectForKey: @"CharacterEncoding"]
|
||||||
|
intValue];
|
||||||
|
NSDictionary *defaultAttrs = [options objectForKey: @"DefaultAttributes"];
|
||||||
|
NSString *str = [[NSString alloc] initWithData: data
|
||||||
|
encoding: encoding];
|
||||||
|
|
||||||
|
self = [self initWithString: str
|
||||||
|
attributes: defaultAttrs];
|
||||||
|
RELEASE(str);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Set error
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -781,9 +832,19 @@ documentAttributes: (NSDictionary **)dict
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSData *data = [url resourceDataUsingCache: YES];
|
||||||
RELEASE(self);
|
|
||||||
return nil;
|
if (data == nil)
|
||||||
|
{
|
||||||
|
// FIXME: Set error
|
||||||
|
RELEASE(self);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self initWithData: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: dict
|
||||||
|
error: error];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *) docFormatFromRange: (NSRange)range
|
- (NSData *) docFormatFromRange: (NSRange)range
|
||||||
|
@ -1302,7 +1363,7 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
NSTextAttachment *attachment;
|
NSTextAttachment *attachment;
|
||||||
|
|
||||||
if (!eRange.length)
|
if (!eRange.length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
attachment = [self attribute: NSAttachmentAttributeName
|
attachment = [self attribute: NSAttachmentAttributeName
|
||||||
atIndex: eRange.location
|
atIndex: eRange.location
|
||||||
|
@ -1310,10 +1371,10 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
|
|
||||||
if (attachment == nil)
|
if (attachment == nil)
|
||||||
{
|
{
|
||||||
[self deleteCharactersInRange: NSMakeRange (eRange.location, 1)];
|
[self deleteCharactersInRange: NSMakeRange (eRange.location, 1)];
|
||||||
eRange.length--;
|
eRange.length--;
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = NSMaxRange (eRange);
|
location = NSMaxRange (eRange);
|
||||||
}
|
}
|
||||||
|
@ -1351,7 +1412,7 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) readFromURL: (NSURL *)url
|
- (BOOL) readFromURL: (NSURL *)url
|
||||||
options: (NSDictionary *)options
|
options: (NSDictionary *)options
|
||||||
documentAttributes: (NSDictionary**)documentAttributes
|
documentAttributes: (NSDictionary**)documentAttributes
|
||||||
{
|
{
|
||||||
return [self readFromURL: url
|
return [self readFromURL: url
|
||||||
|
@ -1380,13 +1441,12 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
if ([type isEqualToString: @"html"])
|
if ([type isEqualToString: @"html"])
|
||||||
{
|
{
|
||||||
NSData *data = [url resourceDataUsingCache: YES];
|
NSData *data = [url resourceDataUsingCache: YES];
|
||||||
NSURL *baseURL = [options objectForKey: @"BaseURL"];
|
|
||||||
NSAttributedString *attr;
|
NSAttributedString *attr;
|
||||||
|
|
||||||
attr = [[NSAttributedString alloc]
|
attr = [[NSAttributedString alloc]
|
||||||
initWithHTML: data
|
initWithHTML: data
|
||||||
baseURL: baseURL
|
options: options
|
||||||
documentAttributes: documentAttributes];
|
documentAttributes: documentAttributes];
|
||||||
[self setAttributedString: attr];
|
[self setAttributedString: attr];
|
||||||
RELEASE(attr);
|
RELEASE(attr);
|
||||||
|
|
||||||
|
@ -1398,8 +1458,8 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
NSAttributedString *attr;
|
NSAttributedString *attr;
|
||||||
|
|
||||||
attr = [[NSAttributedString alloc]
|
attr = [[NSAttributedString alloc]
|
||||||
initWithRTFD: data
|
initWithRTFD: data
|
||||||
documentAttributes: documentAttributes];
|
documentAttributes: documentAttributes];
|
||||||
[self setAttributedString: attr];
|
[self setAttributedString: attr];
|
||||||
RELEASE(attr);
|
RELEASE(attr);
|
||||||
|
|
||||||
|
@ -1411,8 +1471,8 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
NSAttributedString *attr;
|
NSAttributedString *attr;
|
||||||
|
|
||||||
attr = [[NSAttributedString alloc]
|
attr = [[NSAttributedString alloc]
|
||||||
initWithRTF: data
|
initWithRTF: data
|
||||||
documentAttributes: documentAttributes];
|
documentAttributes: documentAttributes];
|
||||||
[self setAttributedString: attr];
|
[self setAttributedString: attr];
|
||||||
RELEASE(attr);
|
RELEASE(attr);
|
||||||
|
|
||||||
|
@ -1429,8 +1489,8 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
NSAttributedString *attr;
|
NSAttributedString *attr;
|
||||||
|
|
||||||
attr = [[NSAttributedString alloc]
|
attr = [[NSAttributedString alloc]
|
||||||
initWithString: str
|
initWithString: str
|
||||||
attributes: defaultAttrs];
|
attributes: defaultAttrs];
|
||||||
RELEASE(str);
|
RELEASE(str);
|
||||||
[self setAttributedString: attr];
|
[self setAttributedString: attr];
|
||||||
RELEASE(attr);
|
RELEASE(attr);
|
||||||
|
@ -1457,7 +1517,20 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
documentAttributes: (NSDictionary **)documentAttributes
|
documentAttributes: (NSDictionary **)documentAttributes
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSAttributedString *attr;
|
||||||
|
|
||||||
|
attr = [[NSAttributedString alloc]
|
||||||
|
initWithData: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: documentAttributes
|
||||||
|
error: error];
|
||||||
|
if (attr)
|
||||||
|
{
|
||||||
|
[self setAttributedString: attr];
|
||||||
|
RELEASE(attr);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue