0

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];


}

}
Paul
  • 21
  • 1
  • Why are you implementing saving yourself? Normally, the document system handles saving for you. If you want to change how it does that, look into methods of the document controller, and see which ones are best for you to override. http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocumentController_Class/ – Peter Hosey Feb 23 '10 at 16:46

1 Answers1

0

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
  • 60,946
  • 14
  • 140
  • 135
  • 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 Feb 22 '10 at 22:10