frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
442 stars 43 forks source link

Bug in comwin_open_file disallows some files to be opened #107

Closed SamSandq closed 2 months ago

SamSandq commented 2 months ago

A subtle bug in the Mac version... in the call to open a file one may include file types, like in

    const char_t *type[] = {"sqlite", "db"};
    const char_t *file = comwin_open_file(app->window, type, 2, NULL);
    if (file != NULL) {

        bstd_printf("Chose: %s\n", file);

This does not work on the Mac in the example above because the file type sqliteand dbare not registered file types. However, they do exist and the files should be available for opening.

Correct the oversight by changed, in oscomwin.m, function i_set_ftypes:

change the line UTType *type = [UTType typeWithIdentifier:ext]; to UTType *type = [UTType typeWithFilenameExtension:ext];

This will allow any file with the indicated extensions to be opened, not only registered ones.

frang75 commented 2 months ago

Thanks @SamSandq for reporting!

Fixed in this commit: https://github.com/frang75/nappgui_src/commit/32acdb539adeed859986cb6472c34c29a4b0ebd0

Tested with Product demo app

static void i_OnImport(Ctrl *ctrl, Event *e)
{
    const char_t *type[] = { "dbp" };
    const char_t *file = comwin_open_file(ctrl->window, type, 1, NULL);
    ...
dbp_files