Tk Source Code

View Ticket
Login
Ticket UUID: 2045553
Title: tk_getSaveFile -defaultextension disagrees with its man page
Type: Bug Version: obsolete: 8.6a1
Submitter: fvogel Created on: 2008-08-10 20:04:03
Subsystem: 37. [tk_get*File] Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2015-10-08 12:38:40
Resolution: None Closed By: nobody
    Closed on:
Description:
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
User Comments: danckaert added on 2015-10-08 12:38:40:
This bug surfaced again while discussing http://core.tcl.tk/tk/tktview?name=47af31bd3a

I think that it is a useful feature to add the extension of the currently selected filetype. I always use the file-dialogs it this way (thus, with -defaultextension {} on Windows).

But it would indeed be more reasonable to have the following behaviour on all platforms:
- with -defaultextension "", do not add an extension.
- without -defaultextension, add the the extension of the currently selected filetype.

fvogelnew1 added on 2011-10-31 19:14:56:
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?
Thanks.

fvogelnew1 added on 2008-11-30 05:32:54:
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

fvogelnew1 added on 2008-08-11 03:16:37:
Logged In: YES 
user_id=1245417
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