I've written a small app that, from a preferences panel, uses a "Choose" button to open a save panel that's used to select the name of the file to which the app will log periodic data. That is, the preferences panel launches via this code:

// -------------------------------------------------------- showPreferencesPanel
- (IBAction)showPreferencesPanel: (id)sender
{
        SettingsDialog *settingsMgr;

        settingsMgr = [[SettingsDialog alloc] init];
        [settingsMgr showSettingsPanel:self];
}


and from within the code for the settingsMgr, a button push invokes this code to get the file name:


//-------------------------------------------------------- pushChooseButton ----
- (IBAction)pushChooseButton:(id)sender
{
        // get pathname
        // break into components
        // if pathname is a file
        // drop last one, make path from it
        
        NSSavePanel *save = [NSSavePanel savePanel];
[save setAllowedFileTypes:[[NSArray alloc] initWithObjects:@"log", @"txt", nil]];
        [save setAllowsOtherFileTypes:YES];
        [save setRequiredFileType:@"log"];
[save setMessage:@"Pick the file to which log messages will be appended.\nFiles with the .log file type will open in console by default."];
        [save setNameFieldLabel:@"Log To:"];
        [save setPrompt:@"Choose"];
        [save setDelegate:self];
        [save setTitle:@"Log"];
        
NSString *sFile = [textLogPath stringValue];; // stringByStandardizingPath;
        NSString *sFileWithoutLast = [sFile stringByDeletingLastPathComponent];
NSString *sFileOnly = [sFile substringFromIndex:[sFileWithoutLast length]+1]; //NSLog(@"\nsFile: %...@\nwithout last:%...@\nlast: %@", sFile, sFileWithoutLast, sFileOnly );
        
int result = [save runModalForDirectory:sFileWithoutLast file:sFileOnly];
        if (result == NSOKButton){
                NSString *selectedFile = [[save filename] 
stringByStandardizingPath];
                [textLogPath setStringValue:selectedFile];
        }
}

This latter code works properly so long as the file that will be the target of the append -- the target of the save panel -- does not exist. In that event, the runModal comes back and I can extract the name. If the file *does* exist, however, then a panel comes up that asks if it's ok to replace the file, and if I agree to replace, not only the choose panel closes, so does my settings panel - I'm dumped all the way back to the app that invoked showPreferencePane.

I looked at the methods being fired, and nothing much interesting comes up. I see

panel:directoryDidChange:
panel:userEnteredFilename:confirmed:
panel:isValidFilename:

and by then the windows are all closed. Any ideas on why the panel closes around me?

(Side note: anyone who wants to critique my code for splitting a file name off a path, please let her rip!)

Thanks

Barry Press

















_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to