Is there a way to suggest a file name for the initial save dialog (of an untitled document) to use for a document in the nsdocument framework?
In OSX 10.8 you can add this method
- (NSString *)defaultDraftName
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nsdocument_Class/Reference/Reference.html
In Mac OS X v10.7 and later:
- (void)setDisplayName:(NSString *)displayNameOrNil
v10.6, override in your NSDocument subclass:
- (BOOL)prepareSavePanel:(NSSavePanel *)savePanel
{
if( [savePanel.nameFieldStringValue isEqualToString:@"Untitled"] )
[savePanel setNameFieldStringValue:@"hello"];
return [super prepareSavePanel:savePanel];
}
In fact the default implementation is empty and returns YES so could just do that.
Not sure about testing for "Untitled" though, won't work if they have already saved as "Untitled" and want to keep that name, and maybe it won't localise, so maybe set a flag in
- (id)initWithType:(NSString *)type error:(NSError **)error
or is there already one?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With