--- hatari/src/gui-sdl/dlgFloppy.c 2019/04/09 08:47:28 1.1 +++ hatari/src/gui-sdl/dlgFloppy.c 2019/04/09 08:48:54 1.1.1.2 @@ -60,14 +60,29 @@ static SGOBJ floppydlg[] = }; +#define DLGMOUNT_A 2 +#define DLGMOUNT_B 3 +#define DLGMOUNT_CANCEL 4 + +/* The "Alert"-dialog: */ +static SGOBJ alertdlg[] = +{ + { SGBOX, 0, 0, 0,0, 40,6, NULL }, + { SGTEXT, 0, 0, 3,1, 30,1, "Insert last created disk to?" }, + { SGBUTTON, 0, 0, 3,4, 10,1, "Drive A:" }, + { SGBUTTON, 0, 0, 15,4, 10,1, "Drive B:" }, + { SGBUTTON, SG_CANCEL, 0, 27,4, 10,1, "Cancel" }, + { -1, 0, 0, 0,0, 0,0, NULL } +}; + + /** * Let user browse given disk, insert disk if one selected. - * return false if no disk selected, otherwise return true. */ -static bool DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid) +static void DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid) { char *selname, *zip_path; - const char *tmpname; + const char *tmpname, *realname; assert(drive >= 0 && drive < MAX_FLOPPYDRIVES); if (ConfigureParams.DiskImage.szDiskFileName[drive][0]) @@ -76,54 +91,77 @@ static bool DlgDisk_BrowseDisk(char *dlg tmpname = ConfigureParams.DiskImage.szDiskImageDirectory; selname = SDLGui_FileSelect(tmpname, &zip_path, false); - if (selname) + if (!selname) + return; + + if (File_Exists(selname)) { - if (File_Exists(selname)) - { - const char *realname; - realname = Floppy_SetDiskFileName(drive, selname, zip_path); - /* TODO: error dialog when this fails */ - if (realname) - { - File_ShrinkName(dlgname, realname, floppydlg[diskid].w); - } - } - else - { - Floppy_SetDiskFileNameNone(drive); - dlgname[0] = '\0'; - } - if (zip_path) - free(zip_path); - free(selname); - return true; + realname = Floppy_SetDiskFileName(drive, selname, zip_path); + if (realname) + File_ShrinkName(dlgname, realname, floppydlg[diskid].w); + } + else + { + Floppy_SetDiskFileNameNone(drive); + dlgname[0] = '\0'; } - return false; + if (zip_path) + free(zip_path); + free(selname); } /** * Let user browse given directory, set directory if one selected. - * return false if none selected, otherwise return true. */ -static bool DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen) +static void DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen) { char *str, *selname; selname = SDLGui_FileSelect(confname, NULL, false); - if (selname) - { - strcpy(confname, selname); - free(selname); + if (!selname) + return; + + strcpy(confname, selname); + free(selname); + + str = strrchr(confname, PATHSEP); + if (str != NULL) + str[1] = 0; + File_CleanFileName(confname); + File_ShrinkName(dlgname, confname, maxlen); +} + + +/** + * Ask whether new disk should be inserted to A: or B: and if yes, insert. + */ +static void DlgFloppy_QueryInsert(char *namea, int ida, char *nameb, int idb, const char *path) +{ + const char *realname; + int diskid, dlgid; + char *dlgname; - str = strrchr(confname, PATHSEP); - if (str != NULL) - str[1] = 0; - File_CleanFileName(confname); - File_ShrinkName(dlgname, confname, maxlen); - return true; + SDLGui_CenterDlg(alertdlg); + switch (SDLGui_DoDialog(alertdlg, NULL)) + { + case DLGMOUNT_A: + dlgname = namea; + dlgid = ida; + diskid = 0; + break; + case DLGMOUNT_B: + dlgname = nameb; + dlgid = idb; + diskid = 1; + break; + default: + return; } - return false; + + realname = Floppy_SetDiskFileName(diskid, path, NULL); + if (realname) + File_ShrinkName(dlgname, realname, floppydlg[dlgid].w); } @@ -133,6 +171,7 @@ static bool DlgDisk_BrowseDir(char *dlgn void DlgFloppy_Main(void) { int but, i; + char *newdisk; char dlgname[MAX_FLOPPYDRIVES][64], dlgdiskdir[64]; SDLGui_CenterDlg(floppydlg); @@ -205,7 +244,14 @@ void DlgFloppy_Main(void) floppydlg[FLOPPYDLG_IMGDIR].w); break; case FLOPPYDLG_CREATEIMG: - DlgNewDisk_Main(); + newdisk = DlgNewDisk_Main(); + if (newdisk) + { + DlgFloppy_QueryInsert(dlgname[0], FLOPPYDLG_DISKA, + dlgname[1], FLOPPYDLG_DISKB, + newdisk); + free(newdisk); + } break; } }