zootbobbalu
Registered
I have a document based Cocoa app created in PB and I would like to set the delegate for the shared NSSavePanel the entire application uses.
I'm assuming that the NSSavePanel returned from:
id savePanel = [NSSavePanel savePanel]
will be the shared NSSavePanel (the documentation says this is the case), but when I try to set the savePanel delegate to the window controller, the window controller does not receive delegate messages.
The documentation also states that NSSavePanel will check to make sure that all the delegate methods are implemented before changing where the delegate instance points to, so I made sure that all methods are implemented.
- (NSComparisonResult)panelid)sender compareFilenameNSString *)fileName1 withNSString *)fileName2 caseSensitiveBOOL)flag {
NSLog(@"fileName1: %@ fileName: %@", fileName1, fileName2);
return [fileName1 compare:fileName2];
}
- (BOOL)panelid)sender isValidFilenameNSString *)filename {
NSLog(@"savePanel isValidFilename: filename: %@", filename);
return YES;
}
- (BOOL)panelid)sender shouldShowFilenameNSString *)filename {
NSLog(@"savePanel shouldShowFilename: filename: %@", filename);
return YES;
}
- (NSString *)panelid)sender userEnteredFilenameNSString *)filename confirmedBOOL)okFlag {
NSLog(@"savePanel filename: %@", filename);
return filename;
}
- (void)panelid)sender willExpandBOOL)expanding {
}
when I build/run the app nothing gets logged by the savePanel delegate when I save a document. I set the savePanel delegate by overriding the NSDocument saveDocument: method.
-(void)saveDocumentid)sender {
id savePanel=[NSSavePanel savePanel];
[savePanel setDelegate:windowController];
NSLog(@"saveDocument: savePanelDelegate: %@ savePanel: %@", [[savePanel delegate] description], [savePanel description]);
[super saveDocument:sender];
}
- (NSData *)dataRepresentationOfTypeNSString *)aType {
NSLog(@"dataRep: savePanelDelegate: %@", [[[NSSavePanel savePanel] delegate] description]);
return docData;
}
the following gets logged when I run and save a document:
2002-12-19 09:56:54.675 DocApp?[4901] saveDocument: savePanelDelegate: (MyWindowController: 0x19800c0) savePanel: (NSSavePanel: 0x1a14550)
2002-12-19 09:56:59.606 DocApp?[4901] dataRep: savePanelDelegate: (null)
(for those of you really paying attention I had to modify the object descriptions in these logs so that I could get the text to show up in this post - object descriptions are placed between less than greater than characters not parenthesis);
If you noticed, the savePanel delegate was successfully changed to the window controller (MyWindowController?), but the savePanel delegate is set back to null by the time the document is asked to return the data that needs to be saved.
the application state is:
window delegate = window controller
NSApp delegate = document controller
any ideas what I'm doing wrong?
I'm assuming that the NSSavePanel returned from:
id savePanel = [NSSavePanel savePanel]
will be the shared NSSavePanel (the documentation says this is the case), but when I try to set the savePanel delegate to the window controller, the window controller does not receive delegate messages.
The documentation also states that NSSavePanel will check to make sure that all the delegate methods are implemented before changing where the delegate instance points to, so I made sure that all methods are implemented.
- (NSComparisonResult)panelid)sender compareFilenameNSString *)fileName1 withNSString *)fileName2 caseSensitiveBOOL)flag {
NSLog(@"fileName1: %@ fileName: %@", fileName1, fileName2);
return [fileName1 compare:fileName2];
}
- (BOOL)panelid)sender isValidFilenameNSString *)filename {
NSLog(@"savePanel isValidFilename: filename: %@", filename);
return YES;
}
- (BOOL)panelid)sender shouldShowFilenameNSString *)filename {
NSLog(@"savePanel shouldShowFilename: filename: %@", filename);
return YES;
}
- (NSString *)panelid)sender userEnteredFilenameNSString *)filename confirmedBOOL)okFlag {
NSLog(@"savePanel filename: %@", filename);
return filename;
}
- (void)panelid)sender willExpandBOOL)expanding {
}
when I build/run the app nothing gets logged by the savePanel delegate when I save a document. I set the savePanel delegate by overriding the NSDocument saveDocument: method.
-(void)saveDocumentid)sender {
id savePanel=[NSSavePanel savePanel];
[savePanel setDelegate:windowController];
NSLog(@"saveDocument: savePanelDelegate: %@ savePanel: %@", [[savePanel delegate] description], [savePanel description]);
[super saveDocument:sender];
}
- (NSData *)dataRepresentationOfTypeNSString *)aType {
NSLog(@"dataRep: savePanelDelegate: %@", [[[NSSavePanel savePanel] delegate] description]);
return docData;
}
the following gets logged when I run and save a document:
2002-12-19 09:56:54.675 DocApp?[4901] saveDocument: savePanelDelegate: (MyWindowController: 0x19800c0) savePanel: (NSSavePanel: 0x1a14550)
2002-12-19 09:56:59.606 DocApp?[4901] dataRep: savePanelDelegate: (null)
(for those of you really paying attention I had to modify the object descriptions in these logs so that I could get the text to show up in this post - object descriptions are placed between less than greater than characters not parenthesis);
If you noticed, the savePanel delegate was successfully changed to the window controller (MyWindowController?), but the savePanel delegate is set back to null by the time the document is asked to return the data that needs to be saved.
the application state is:
window delegate = window controller
NSApp delegate = document controller
any ideas what I'm doing wrong?