[hatari-devel] SDL GUI file and directory selection |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: [hatari-devel] SDL GUI file and directory selection
- From: Andreas Grabher <andreas_g86@xxxxxxxxxx>
- Date: Sat, 15 Oct 2022 10:41:16 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1665823286; bh=vIwWzQTHzpx0Yog/PI90jM6aCNtvo1gQOlY3Ejl5Wzw=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=ecJCI/W0JP1rzuqO9UedA3JGn/r8H+bvD8Qu1VUfjRHbC4ZcBk8EFq+D1mrdauaUk g0mvTceQeKFVYYZ7mqdBjr9KyafE4FwSLYPrBk8wilEP6XfqQGZNqS4wy76+kP1dev 8cjM/WGA6LaILKi/AHkm2+PKXoLHoGPg9cM6BQ3D7TUqEkiJl1A9ae6hzCWYITAxFv 8UJWFySNpebQ4nOZllNRFOpNGhXmzAgZam+Iwp7K3VfF+tGIzXm6xxybhRRRiZite4 A0l/dt+GePqO1gzKpPAYO/ZzkFgHU07DTVy8Ca70mTFygDJ2GGocz2ohycx0JeANfz BKOsMNTeB+d9Q==
I just noticed some weird behavior from SDLGui_FileConfSelect() and new SdlGui_DirSelect():
It seems these functions also return true, if a non-existent file or directory is selected. That does not make very much sense. I suggest to change the functions like this (note that there are some minor differences regarding title and readonly from Previous):
bool SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, bool *readonly, bool bAllowNew)
{
char *selname;
selname = SDLGui_FileSelect("Choose a file", confname, NULL, readonly, bAllowNew);
if (selname)
{
if (!File_DoesFileNameEndWithSlash(selname) &&
(bAllowNew || File_Exists(selname)))
{
strncpy(confname, selname, FILENAME_MAX);
confname[FILENAME_MAX-1] = '\0';
File_ShrinkName(dlgname, selname, maxlen);
free(selname);
return true;
}
dlgname[0] = confname[0] = 0;
free(selname);
}
return false;
}
bool SDLGui_DirSelect(char *dlgname, char *confname, int maxlen)
{
char *selname;
selname = SDLGui_FileSelect("Choose a folder", confname, NULL, NULL, false);
if (selname)
{
File_MakeValidPathName(selname);
if (File_DirExists(selname))
{
strncpy(confname, selname, FILENAME_MAX);
File_ShrinkName(dlgname, selname, maxlen);
free(selname);
return true;
}
dlgname[0] = confname[0] = 0;
free(selname);
}
return false;
}
I also suggest to rename SdlGui_DirSelect() to SDLGui_DirSelect() for matching the naming scheme of the other functions.