• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Exception-like behavior in save panel used for file choose
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Exception-like behavior in save panel used for file choose


  • Subject: Exception-like behavior in save panel used for file choose
  • From: Barry Press <email@hidden>
  • Date: Fri, 31 Jul 2009 00:04:43 -0600

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Exception-like behavior in save panel used for file choose
      • From: Quincey Morris <email@hidden>
    • Re: Exception-like behavior in save panel used for file choose
      • From: Steve Christensen <email@hidden>
  • Prev by Date: Re: NSMutableDictionary Poitners
  • Next by Date: Converting colors to CGFloat
  • Previous by thread: Problem in copying files to the system clipboard
  • Next by thread: Re: Exception-like behavior in save panel used for file choose
  • Index(es):
    • Date
    • Thread