--- hatari/src/gui-osx/CreateFloppyController.m 2019/04/09 08:48:37 1.1.1.2 +++ hatari/src/gui-osx/CreateFloppyController.m 2019/04/09 08:55:21 1.1.1.6 @@ -1,8 +1,8 @@ /* Hatari - CreateFloppyController.m - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. Create floppy image window controller implementation file @@ -19,59 +19,48 @@ @implementation CreateFloppyController +char szPath[FILENAME_MAX] ; + - (IBAction)createFloppyImage:(id)sender { - BOOL cRet; - - // Create a SavePanel - NSSavePanel *savePanel = [NSSavePanel savePanel]; + BOOL cRet; + int ret, cTracks, cSectors, cSides ; + NSString *defaultDir ; + NSString *newCnf ; - // Set its allowed file types - NSArray* allowedFileTypes = [NSArray arrayWithObjects: @"st", @"msa", @"dim", @"gz", nil]; - [savePanel setAllowedFileTypes:allowedFileTypes]; - // Get the default images directory - NSString* defaultDir = [NSString stringWithCString:ConfigureParams.DiskImage.szDiskImageDirectory encoding:NSASCIIStringEncoding]; + defaultDir = [NSString stringWithCString:ConfigureParams.DiskImage.szDiskImageDirectory encoding:NSASCIIStringEncoding]; // Run the SavePanel, then check if the user clicked OK - if ( NSOKButton == [savePanel runModalForDirectory:defaultDir file:nil] ) + newCnf = [NSApp hsavefile:YES defoDir:defaultDir defoFile:nil types:[NSArray arrayWithObjects: allF, nil] ] ; + if ([newCnf length] != 0) { - // Get the path to the chosen file - NSString *path = [savePanel filename]; - - // Make a non-const C string out of it - const char* constSzPath = [path cStringUsingEncoding:NSASCIIStringEncoding]; - size_t cbPath = strlen(constSzPath) + 1; - char szPath[cbPath]; - strncpy(szPath, constSzPath, cbPath); - + [newCnf getCString:szPath maxLength:FILENAME_MAX-1 encoding:NSASCIIStringEncoding] ; // Get the tracks, sectors and sides values - int cTracks = [[tracks selectedCell] tag]; - int cSectors = [[sectors selectedCell] tag]; - int cSides = [[sides selectedCell] tag]; - + cTracks = [[tracks selectedCell] tag]; + cSectors = [[sectors selectedCell] tag]; + cSides = [[sides selectedCell] tag]; + // Create the image cRet=CreateBlankImage_CreateFile(szPath, cTracks, cSectors, cSides); if(cRet==TRUE) - { - int ret = NSRunAlertPanel(@"Hatari", @"Insert newly created disk in", @"Ignore", @"A:", @"B:"); - if (ret != NSAlertDefaultReturn) - { - printf("%d\n",ret); - if(ret==-1) ret=1; //0=>Drive 0, -1=>Drive 1 - - Floppy_SetDiskFileName(ret, szPath, NULL); - Floppy_InsertDiskIntoDrive(ret); - } - } - - } + { ret = [NSApp myAlerte:NSInformationalAlertStyle Txt:nil firstB:localize(@"Ignore") alternateB:@" A: " + otherB:@" B: " informativeTxt:@""] ; + if (ret == NSAlertDefaultReturn) + return ; + + printf("%d\n",ret); + ret = ret == NSAlertAlternateReturn ? 0 : 1 ; + Floppy_SetDiskFileName(ret, szPath, NULL); + Floppy_InsertDiskIntoDrive(ret); + } ; + } ; } - (void)awakeFromNib { // Fill the "Tracks" dropdown - [tracks removeAllItems]; + [tracks removeAllItems]; int i; for (i = 40; i <= 85; i++) { @@ -87,7 +76,9 @@ - (IBAction)runModal:(id)sender { - [[ModalWrapper alloc] runModal:window]; + ModalWrapper *mw=[[ModalWrapper alloc] init]; + [mw runModal:window]; + [mw release]; }