Proposed unnamed save name NSDocument

Is there a way to suggest a file name for the initial save dialog (an untitled document) for use in a document in an nsdocument structure?

+4
source share
2 answers

On Mac OS X v10.7 and later:

- (void)setDisplayName:(NSString *)displayNameOrNil 

v10.6, override in the 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 it can just do it.

Iโ€™m not sure that testing for โ€œUntitledโ€ will not work if they have already been saved as โ€œUntitledโ€ and want to keep this name, and maybe it will not be localized, so maybe set the flag to

 - (id)initWithType:(NSString *)type error:(NSError **)error 

or is there already one?

+2
source

Source: https://habr.com/ru/post/1399947/


All Articles