Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » limiting filetypes in a save dialogue

This thread is locked; no one can reply to it. rss feed Print
limiting filetypes in a save dialogue
Mark Oates
Member #1,146
March 2001
avatar

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
Supreme Loser
January 1999
avatar

#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
Member #1,146
March 2001
avatar

uhhhh....

That's very not the answer.

(but funny)

Arthur Kalliokoski
Second in Command
February 2005
avatar

Well use your native OS file system with globbing then.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Mark Oates
Member #1,146
March 2001
avatar

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

SiegeLord
Member #7,827
October 2006
avatar

Does the patterns argument of the al_create_native_file_dialog do nothing?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Mark Oates
Member #1,146
March 2001
avatar

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
Member #7,719
August 2006
avatar

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.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

Trent Gamblin
Member #261
April 2000
avatar

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

Go to: