[Drawkit] NSDocument based application, nil drawing

Graham Cox graham.cox at bigpond.com
Fri May 22 21:22:32 PDT 2009


On 23/05/2009, at 10:30 AM, Graham Cox wrote:

> The document may make another one, but only if the document type is  
> set up so that the default DKDrawingDocument recognises it. (See - 
> initWithType:error:)


Thinking on this, it might make more sense if the DKDrawingDocument is  
changed to go ahead and make a drawing regardless of the filetype  
passed here. Since the intention is that the class is meant as a base  
class for further refinement in an app, requiring a type here is  
probably not necessary. You'd need to override if you are handling  
different filetypes, or using a custom DKDrawing subclass, but  
currently you need to do that anyway. (Or you can override - 
makeDefaultDrawing)

The advantage would be that it would not be necessary to set up any  
filetype or UTI mappings just to get the document working.


In other words, the method becomes:

- (id)	initWithType:(NSString*) typeName error:(NSError**) outError
{
	[super initWithType:typeName error:outError];
	
	DKDrawing* dr = [self makeDefaultDrawing];
	[self setDrawing:dr];

	return self;
}


instead of:

- (id)	initWithType:(NSString*) typeName error:(NSError**) outError
{
	LogEvent_(kLifeEvent, @"initialising default drawing, type = '%@'",  
typeName );

	[super initWithType:typeName error:outError];
	
	// note - <typeName> will be different when linking against the 10.5  
SDK. On 10.4, this is "Drawing", on 10.5 this is the UTI,
	// "net.apptree.drawing". For now, we just accept either type here.

	if([typeName isEqualToString:kDKDrawingDocumentType] || [typeName  
isEqualToString:kDKDrawingDocumentUTI])
	{
		DKDrawing* dr = [self makeDefaultDrawing];
		[self setDrawing:dr];
	}
	return self;
}



Anyone got any comment?

--Graham




More information about the Drawkit mailing list