0
votes

i am new in objective c , i want create alert over save panel to get confirm from user to overwrite exist file or not , like text editor when you save a file in a directory that have same file name alert show over save panel that ask to replace or cancel , when user select cancel alert disappear , when user select replace the alert disappear then save panel. not save panel disappear then alert show. please help

1
NSSavePanel has this functionality built-in...Andrew Madsen
There's no associated function. It's free. If you use NSSavePanel to let the user pick a location to save a file, it will automatically warn them and ask for confirmation if the path they select already exists. Really, just try it and you'll see...Andrew Madsen
thank you for answer , but in my app don't warn me , beside i want the alert show text in my language not in english there i should make alert by code not automatically, i did it but save panel disappear then alert will show . my problem is i want alert appear over save panelKosar

1 Answers

1
votes

This code is tested and works. It will warn you if the file already exists. The save panel and the file replacement alert will be appear in whatever language Mac OS X is set to use (see screenshot for Japanese example):

- (IBAction)saveTestFile:(id)sender 
{
    NSString *saveString = [NSString stringWithFormat:@"Hello World, it's %@!", [NSDate date]];
    NSSavePanel *savePanel = [NSSavePanel savePanel];
    if ([savePanel runModal] == NSFileHandlingPanelOKButton)
    {
        NSURL *saveURL = [savePanel URL];
        NSError *error = nil;
        if (![saveString writeToURL:saveURL atomically:YES encoding:NSASCIIStringEncoding error:&error])
        {
            NSLog(@"Unable to save file: %@", error);
        }
    }
}

Japanese Save Panelenter image description here