views:

114

answers:

2

Doc based, QTKit app. When saving, the new filename updates in the active window titleBar. I would also like to display the newly saved filename string in a textField, somewhere else on the opened doc. The code successfully saves the new doc. However the lastPathComponent string doesn't update. Please advise?

thanks,

Paul

- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
  NSURL *outputFileURL = [(NSURL *)contextInfo autorelease];    



if (returnCode == NSOKButton) {
    NSString *filename = [sheet filename];

    [[NSFileManager defaultManager] moveItemAtPath:[outputFileURL path] toPath:filename error:nil];

    NSString    *path = [filename lastPathComponent];
    [textField setStringValue:[path lastPathComponent]];

    [[NSWorkspace sharedWorkspace] openFile:filename];
} 


else {
    [[NSFileManager defaultManager] removeItemAtPath:[outputFileURL path] error:nil];


}

}
A: 

Since "filename" is apparently valid (because things are working and your window title updates), have you checked to make sure "textField" is actually connected in your XIB?

Joshua Nozzi
Going by your answer, I took another look. The line "[path lastPathComponent]" seems suspicious, since "path" is already the lastPathComponent of filename. Maybe just pass "path" to the text view. More descriptive variable names and OCD-like cleanliness helps avoid confusing things like that. :-)
Joshua Nozzi
A: 

Thanks, Josh.

It's been wired up all along. Still no luck ...

Paul.

paul
Don't add answers as comments. Add comments to answers. :-)
Joshua Nozzi