portable-file-dialogs icon indicating copy to clipboard operation
portable-file-dialogs copied to clipboard

Automatically add extension for save file

Open AlbertoFrancoDD opened this issue 5 years ago • 2 comments

Hi is there the chance to add the option to automatically add the extesion for the save file dialog? I have looked throught the API but I am not able to find if this is already implemented or not.

Alberto

AlbertoFrancoDD avatar Jul 29 '20 06:07 AlbertoFrancoDD

I'm sure you figured this out quickly, so I'm writing this just for posterity. The result of the file Save/Open dialogs are file paths. So, if you want to automatically add an extension to filenames, that's as simple as checking the end of the received filename for the extension, and append it, if it doesn't already have it.

gamagan avatar Mar 09 '23 10:03 gamagan

First of all, thanks @samhocevar for this library. Very useful.

As you said, it's straighforward to add the extension to the file name. However, there are two issues:

  1. We can't tell if the user chose not to add an extension on purpose or not.

  2. The file overwrite dialog. Let's say that a file test.dat already exists. Now if the user chooses test, the overwite warning dialog is not shown even though the file will actually get overwritten after we add the .dat extention.

  3. If multiple extentions are possible (e.g. there is more than one file exention filter). Because the extenion is not added to path, we have no idea which of the possilbe extentions to use.

I can look into this and do a pull request if you wish?

samangh avatar Mar 10 '23 12:03 samangh