NSDocument and new windows.
NSDocument and new windows.
- Subject: NSDocument and new windows.
- From: Teunis Peters <email@hidden>
- Date: Tue, 24 May 2005 03:22:42 -0700
Okay - I've decided I am as a matter of fact going to use NSDocument in interacting with the database. Permanent links (a record containing enough information to connect to the database) will exist as an NSDocument form.
Okay I've got some problems.
- Can an NSDocument object exist -without- having a window for it?
- How does one create new windows for said document?
I've got new windows opening, but default data is not set and no data in the window is set.... I've got NO idea how to set this up properly - I have yet to find any examples that overload NSWindowController. At least not in xCode 1.5.
I also overload NSDocumentController but that code seems to work okay.
As an added bonus - source for the NSDocument data could be filesystem or database. I'm not sure what to overload to allow the second - NSFileWrapper? the NSURL methods? Still scratching my head on that one.
Current code: (yes these are extracts)
in Document:
(overloaded:
isNativeType, readableTypes, writableTypes, dataRepresentationOfType,loadDataRepresentation and a whole bunch more.
- (void)windowControllerDidLoadNib:(NSWindowController *) windowController {
[super windowControllerDidLoadNib:windowController];
wgCatViewController* cv = (wgCatViewController*)windowController;
[cv setDataFrom:self];
}
- (void)makeWindowControllers {
controller = [[[wgCatViewController alloc] init] retain];
[controller setDataFrom:self];
[self addWindowController:controller];
}
- (NSString *)displayName {
return [self name];
}
in window controller:
-init {
if (self = [self initWithWindowNibName:@"dCategory"]){
// used to log some stuff. Does nothing now, but IS run.
}
return self;
}
- (void)windowWillLoad {
NSLog(@"%s", __FUNCTION__);
}
- (void)windowDidLoad {
NSLog(@"%s", __FUNCTION__); // this is called. None of this data is reflected in the window.
[desc setStringValue:@"this is only a test"];
if (category) {
[[self window] setTitle:[category name]];
[desc setStringValue:@"testing"];
[icon setImage:[category icon]];
[scroll setHasHorizontalScroller:TRUE];
[scroll setHasVerticalScroller:TRUE];
}
}
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName {
if (category) return [category name];
return [super windowTitleForDocumentDisplayName:displayName];
}
-setDataFrom:(dbcategory*)src {
category = [src retain];
if ([self window] && category) {
[[self window] setTitle:[category name]];
[desc setStringValue:@"testing"];
[icon setImage:[category icon]];
[scroll setHasHorizontalScroller:TRUE];
[scroll setHasVerticalScroller:TRUE];
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden