How do I override -windowTitleForDocumentDisplayName?

360 views Asked by At

In the Mac Developer Reference for windowTitleForDocumentDisplayName, here, it suggests that a window controller can override this method,

to customize the window title. For example, a CAD application could append β€œ-Top” or β€œ-Side,” depending on the view displayed by the window.

But I can't find any example code showing exactly how to do this. When I override this method in my custom window controller class, it doesn't seem to get called, when I create a new instance of my window controller class. I've been searching the web for a couple of days to find information about this method, but there is hardly any info out there. Much of it is really old - my other question is one of the only recent pages linked to by Google.

Help please!

2

There are 2 answers

0
Daniel Trebbien On

This method appears to be called only when the NSWindowController's document is actually set to an NSDocument instance.

0
Ron Reuter On

in your NSWindowController subclass:

- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
{
    NSString *newName = [NSString stringWithFormat:@"%@ Test", displayName];

    return newName;
}

NOTE: this is called from NSDocumentController's openUntitledDocumentAndDisplay: method, so the input displayName will be some variant of "Untitled".