limiting filetypes in a save dialogue
Mark Oates

Is is possible to limit the file extensions in an allegro ALLEGRO_FILECHOOSER_SAVE dialogue? Specifically, I want to limit the extensions to the bitmap types .png, .bmp, .jpg, etc. with descriptions if possible. Something like this:

{"name":"606200","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/6\/06b4a778d987329f3d702f1187cac5ae.png","w":489,"h":384,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/6\/06b4a778d987329f3d702f1187cac5ae"}606200

Matthew Leverton
#SelectExpand
1ALLEGRO_FS_ENTRY *folder = al_create_fs_entry("."); 2if (al_open_directory(folder)) 3{ 4 ALLEGRO_FS_ENTRY *file; 5 6 while (file = al_read_directory(folder)) 7 { 8 const char *filename = al_get_fs_entry_name(file); 9 ALLEGRO_PATH *path = al_create_path(filename); 10 const char *ext = al_get_path_extension(path); 11 if (strcmp(ext, "png") && strcmp(ext, "bmp")) 12 al_remove_fs_entry(file); 13 al_destroy_path(path); 14 } 15 16 al_close_directory(folder); 17} 18 19// show dialog

8-)

Mark Oates

uhhhh....

That's very not the answer.

(but funny)

Arthur Kalliokoski

Well use your native OS file system with globbing then.

Mark Oates

Maybe I phrased my question the wrong way. I'm trying to limit the extensions in which the user is allowed to save.

SiegeLord

Does the patterns argument of the al_create_native_file_dialog do nothing?

Mark Oates
SiegeLord said:

Does the patterns argument of the al_create_native_file_dialog do nothing?

Not in this case. It limits what I can view, but I can still save as any filetype.

{"name":"606201","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/2\/d254b2ad4a1bacbd986e45d62583fc28.png","w":949,"h":626,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/2\/d254b2ad4a1bacbd986e45d62583fc28"}606201

To be more specific, I'm letting the user use the native save dialog to export an image file, but I'm limited to the extensions that Allegro can save. I don't want the user to try and save an image file as "mypicture.txt".

someone972

I'm not sure there is a way to stop the user from typing in an extension that is not valid, at least not that I've seen. Most programs I've used let you type in any extension, and if it does not match the extension(s) it is looking for it appends the expected one onto it as though you only typed a file name (ex saving a Word document as document.txt will cause it to save as document.txt.doc).

EDIT: If that does not seem pleasing to you, you could always check the extension (if there is one), and if it is not one of the supported saving types notify the user.

Trent Gamblin

It's still nice to have a list of extensions. Then the user can pick one and it gets tacked on automatically.

Thread #610525. Printed from Allegro.cc