#2483 tk_getSaveFile -defaultextension disagrees with its man page

obsolete: 8.6a1
Jeffrey Hobbs
Francois VOGEL

The man page for -defaultextension in tk_getSaveFile states that:

-defaultextension extension
Specifies a string that will be appended to the filename if the user enters a filename without an extension. The default value is the empty string, which means no extension will be appended to the filename in any case. This option is ignored on Mac OS X, which does not require extensions to filenames, and the UNIX implementation guesses reasonable values for this from the -filetypes option when this is not supplied.

So, if I read this correctly, *on Windows* using -defaultextension "" or without this option should provide the same result: a file with no extension (when the user does not force the extension in the filename it enters).

However, on Win XP with 8.6a0 I get (I only type myfile in the dialog using the keyboard, with no extension):

tk_getSaveFile -defaultextension "" -filetypes {{"xyz type" "*.xyz"}}
---> myfile.xyz
tk_getSaveFile -filetypes {{"xyz type" "*.xyz"}}
---> myfile

The latter should spit myfile.txt and not only myfile. On Windows, this is therefore a bug.

On Linux, I get myfile.xyz for both commands, which is consistent with the man page.

Can't test on Mac, sorry.



  • Francois VOGEL
    Francois VOGEL

    Logged In: YES
    Originator: YES

    Re-reading my report, I realize the end of my post is quite confusing/wrong. Apologies for that. I try again:

    1. On Windows, giving -defaultextension "" or not giving this option at all should result in the same thing: no extension added. This is not the case. When -defaultextension "" is given, then an extension from -filetypes is appended. First bug.

    2. On Linux, giving -defaultextension "" or not giving this option at all should not append any extension. This is not the case. Both -defaultextension "" and not giving the option append an extension from -filetypes. When -defaultextension is not supplied, I can agree with this. However, when -defaultextension "" is given, this should not happen. Second bug.


  • Francois VOGEL
    Francois VOGEL

    1. On Windows:

    Since the platform native dialog is used, I guess that the only way to "fix" this is to fix the help file.

    What do you think?

    2. On Linux:

    If I read correctly tkfbox.tcl, the problem boils down to the fact that giving -defaultextension "" or not giving this option at all currently results to the same internal situation because -defaultextension receives the empty string as default anyway (tkfbox.tcl:971).

    Hence, as soon as -filetypes {{"xyz type" "*.xyz"}} is given, $data(-defaultextension) receives .xyz
    Giving -defaultextension "" or not giving this option at all does not change anything.

    I have derived a (rather dirty) patch that lets tkfbox.tcl distinguish between these two cases so that:
    - giving the empty string to -defaultextension does not add an extension
    - not giving the -defaultextension option adds an extension from the filetypes list

    This would be consistent with the help file for Linux.

    However, does this make sense since according to problem 1 on Windows I think the help file must be fixed and not the source code?

    What do you think?


  • Francois VOGEL
    Francois VOGEL

    Even if not addressing this bug from the source code point of view, could anyone at least confirm my understanding that this really is a bug?