Skip to content

Commit

Permalink
Universal catchalls.
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Jun 22, 2024
1 parent 44f85f3 commit 980fa7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 7 additions & 0 deletions addons/native_dialog/android_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display, ALLEGRO_NATIVE_DIALOG
ALLEGRO_DEBUG("waiting for the file chooser");
ALLEGRO_USTR *mime_patterns = al_ustr_new("");
bool first = true;
bool any_catchalls = false;
for (size_t i = 0; i < _al_vector_size(&fd->fc_patterns); i++) {
_AL_PATTERNS_AND_DESC *patterns_and_desc = _al_vector_ref(&fd->fc_patterns, (int)i);
for (size_t j = 0; j < _al_vector_size(&patterns_and_desc->patterns_vec); j++) {
_AL_PATTERN *pattern = _al_vector_ref(&patterns_and_desc->patterns_vec, (int)j);
if (pattern->is_catchall) {
any_catchalls = true;
break;
}
if (pattern->is_mime)
{
if (!first)
Expand All @@ -105,6 +110,8 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display, ALLEGRO_NATIVE_DIALOG
}
}
}
if (any_catchalls)
al_ustr_truncate(mime_patterns, 0);
bool ret = open_file_chooser(fd->flags, al_cstr(mime_patterns), initial_path, &fd->fc_paths, &fd->fc_path_count);
al_ustr_free(mime_patterns);
ALLEGRO_DEBUG("done waiting for the file chooser");
Expand Down
8 changes: 7 additions & 1 deletion addons/native_dialog/osx_dialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ void _al_shutdown_native_dialog_addon(void)
{
NSMutableArray *filter_array = [[NSMutableArray alloc] init];

bool any_catchalls = false;
for (size_t i = 0; i < _al_vector_size(patterns); i++) {
_AL_PATTERNS_AND_DESC *patterns_and_desc = _al_vector_ref(patterns, (int)i);
for (size_t j = 0; j < _al_vector_size(&patterns_and_desc->patterns_vec); j++) {
_AL_PATTERN *pattern = _al_vector_ref(&patterns_and_desc->patterns_vec, (int)j);
if (pattern->is_catchall) {
continue;
any_catchalls = true;
break;
}
char *cstr = al_cstr_dup(al_ref_info(&pattern->info));
NSString *filter_text = [NSString stringWithUTF8String: cstr];
Expand Down Expand Up @@ -61,6 +63,10 @@ void _al_shutdown_native_dialog_addon(void)
}
}

if (any_catchalls) {
filter_array = [[NSMutableArray alloc] init];
}

return filter_array;
}

Expand Down
5 changes: 4 additions & 1 deletion addons/native_dialog/win_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ static ALLEGRO_USTR *create_filter_string(const _AL_VECTOR *patterns)
al_ustr_append_chr(filter, ';');
}
first = false;
al_ustr_append(filter, al_ref_info(&pattern->info));
if (pattern->is_catchall)
al_ustr_append_cstr(filter, "*.*");
else
al_ustr_append(filter, al_ref_info(&pattern->info));
}
}
al_ustr_append_chr(filter, '\0');
Expand Down
10 changes: 5 additions & 5 deletions examples/ex_native_filechooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static AsyncDialog *spawn_async_file_dialog(ALLEGRO_DISPLAY *display,
int flags = save ? ALLEGRO_FILECHOOSER_SAVE : ALLEGRO_FILECHOOSER_MULTIPLE;
const char* title = save ? "Save (no files will be changed)" : "Choose files";
data->file_dialog = al_create_native_file_dialog(
initial_path, title, NULL,
initial_path, title, "image/jpeg;*",
flags);
al_init_user_event_source(&data->event_source);
data->display = display;
Expand Down Expand Up @@ -200,13 +200,13 @@ int main(int argc, char **argv)
al_install_mouse();
touch = al_install_touch_input();
al_install_keyboard();

if (touch) {
al_set_mouse_emulation_mode(ALLEGRO_MOUSE_EMULATION_5_0_x);
}

message("Creating window...");

#ifdef ALLEGRO_IPHONE
al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
#endif
Expand Down Expand Up @@ -250,7 +250,7 @@ int main(int argc, char **argv)

while (1) {
float h = al_get_display_height(display);

ALLEGRO_EVENT event;
al_wait_for_event(queue, &event);

Expand All @@ -264,7 +264,7 @@ int main(int argc, char **argv)
break;
}
}

/* When a mouse button is pressed, and no native dialog is
* shown already, we show a new one.
*/
Expand Down

0 comments on commit 980fa7f

Please sign in to comment.