Duncan
Duncan

Reputation: 453

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?

Upvotes: 6

Views: 1533

Answers (2)

Rogers
Rogers

Reputation: 1973

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?

Upvotes: 3

Related Questions