objective c - NSSavePanel Changing File Name Extensions With AccessoryView -
i have nssavepanel accessoryview let user select graphic format can save image (nsimage) file. far, have following. (i'm skipping lines make short.)
- (void)exportfile { nsstring *filename; if (formatindex1 == 0) { // default selection user in preferences filename = @"untitled.bmp"; } else if (formatindex1 == 1) { filename = @"untitled.gif"; } ... [panel setallowedfiletypes:[[nsarray alloc] initwithobjects:@"bmp",@"gif",@"jpg",@"jp2",@"png",nil]]; [panel setallowsotherfiletypes:no]; [panel setextensionhidden:no]; [panel setcancreatedirectories:yes]; [panel setnamefieldstringvalue:filename]; [panel setaccessoryview:accessoryview1]; [formatmenu1 setaction:@selector(dropmenuchange:)]; // formatmenu1 nspopupbutton [formatmenu1 settarget:self]; [panel beginsheetmodalforwindow:window completionhandler:^(nsinteger result) { if (result == nsfilehandlingpanelokbutton) { // getting panel url } }]; } -(void)dropmenuchange:(nspopupbutton *)sender { nssavepanel *savepanel = (nssavepanel *)[sender window]; [savepanel setnamefieldstringvalue:@"..."]; }
i'm not 100% sure i'm doing right. want achieve want append right extension current file name whenever user selects file format on accessoryview's nspopupbutton. there magical way of doing that? or have set current file name right extension setnamefieldstringvalue programmatically myself?
thank help.
you have set current file name right extension using setnamefieldstringvalue
-(void)dropmenuchange:(nspopupbutton *)sender { nssavepanel *savepanel = (nssavepanel *)[sender window]; nsstring *namefieldstring = [savepanel namefieldstringvalue]; nsstring *namefieldstringwithext = [nsstring stringwithformat:@"%@.%@",[savepanel namefieldstringvalue], popupvalue]; [savepanel setnamefieldstringvalue:namefieldstringwithext]; }
Comments
Post a Comment