Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggested save name of an untitled NSDocument

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?

like image 227
Duncan Avatar asked Mar 06 '12 07:03

Duncan


2 Answers

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

like image 200
Pixman Avatar answered Oct 15 '22 07:10

Pixman


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?

like image 3
Steve Rogers Avatar answered Oct 15 '22 09:10

Steve Rogers