--- hatari/src/gui-osx/CreateFloppyController.m 2019/04/09 08:51:50 1.1.1.3 +++ hatari/src/gui-osx/CreateFloppyController.m 2019/04/09 08:56:37 1.1.1.7 @@ -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,64 +19,53 @@ @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:@[allF] ] ; + 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); + cRet=CreateBlankImage_CreateFile(szPath, cTracks, cSectors, cSides, NULL); 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 == NSAlertFirstButtonReturn) + return ; + + printf("%d\n",ret); + ret = ret == NSAlertSecondButtonReturn ? 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++) { [tracks addItemWithTitle:[NSString stringWithFormat:@"%d", i]]; - [[tracks lastItem] setTag:i]; + [tracks.lastItem setTag:i]; } // Select the default value of 80 tracks