Tk Source Code

View Ticket
Login
Ticket UUID: 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00
Title: tk_getSaveFile adds "." as extension
Type: Bug Version: 8.6.4
Submitter: danckaert Created on: 2015-08-05 09:38:07
Subsystem: 37. [tk_get*File] Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-22 17:22:36
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-09-25 08:19:19
Description:
Since 8.6.4, the following invocation:
  tk_getSaveFile -filetypes {{All *}} -defaultextension {}
will add "." as file extension when a filename is typed in the dialog.
E.g., when typing "foo", it will return "foo."
When typing "foo.c", it will return "foo.c."

Note that -defaultextension {} is commonly used to make the dialog's behaviour the same as on Linux, by adding the extension of the currently selected filetype. (See http://wiki.tcl.tk/1842, second paragraph under "Description").
User Comments: serhiy.storchaka added on 2026-09-25 08:19:19:

Fixed in 8.6.5 by [14153ed2]; tests winDialog-5.7.2 and 5.7.3 cover it and pass on Windows 11 with 8.6 and 9.1. Windows XP is no longer supported. Closing.


apnadkarni added on 2015-10-10 10:48:53:
Fixed the comment.

Not quite sure what to do about [2045553]. Change the docs to match behaviour? I can only check Windows. I find that man page a bit of a mess and am reluctant to take that on!

fvogel added on 2015-10-10 08:47:34:

Two more remarks:

1. Since you are here, could you perhaps check out [2045553] as well?

2. Shouldn't we remove the comment ("this test is currently disabled because...")in test winDialog-5.12.2?


fvogel added on 2015-10-10 08:40:21:
Correct, I did not. After pull/update the test passes. Thanks!

apnadkarni added on 2015-10-10 08:07:59:
Did you update Tcl (not just Tk) to the latest trunk tip before trying? The /users/Default seems to indicate a not up-to-date Tcl checkout

fvogel added on 2015-10-09 20:17:48:

fossil bisect blames [14153ed2], of course, since that commit removed the DISABLED tag for the newly failing test.


fvogel added on 2015-10-09 19:12:01:
A test fails for me now (on Vista):


==== winDialog-5.12.2 tk_getSaveFile: initial directory: ~user FAILED
==== Contents of test case:

    # Note: this test is currently disabled because of a bug in file normalize
    # for names of the form ~xxx that returns the wrong dir on Windows.
    # In particular (in Win8 at least) it returns /users/Default instead
    # of /users/USERNAME...

    unset -nocomplain x
    start {set x [tk_getSaveFile  -initialdir ~$::env(USERNAME)  -initialfile "5
 12 2" -title Foo]}
    then {
        Click ok
    }
    return $x

---- Result was:
C:/Users/Default/5 12 2
---- Result should have been (exact matching):
C:/Users/francois/5 12 2
==== winDialog-5.12.2 FAILED

apnadkarni added on 2015-10-09 04:06:54:
Fixed in [14153ed2]. Tested on Win8. Keeping Open pending testing on XP. I think behaviour is now consistent with older dialog versions (and thus not quite what is documented but that is logged as a separate bug as mentioned elsewhere on this ticket)

danckaert added on 2015-10-08 09:59:55:
See also http://core.tcl.tk/tk/tktview?name=2045553fff

I find it a useful feature to add the extension of the currently selected filtype. I always use the dialogs always in this way.

I would prefer to restore the old behaviour for the time being. If a better solution is found, it can be fixed in the other ticket.

apnadkarni added on 2015-10-08 07:17:34:
Addition of the trailing "." needs to be fixed.

On the second point - use of the -defaultextension {} - it is less clear. The wiki-referenced behaviour is not documented in the manpage and in fact the manpage states "The default value is the empty string, which means no extension will be appended to the filename in any case", not "add extension of selected file type". The manpage also documents -filetypes as only affecting what is displayed and does not mention anything about how it interacts with -defaultextension on Windows. What I can tell from the *old style* Windows dialogs is that if -filetypes is specified, the -defaultextension is ignored. For example,

tk_getSaveFile -filetypes {{Tcl .tcl}} -defaultextension {c}

will return foo.tcl if "foo" is typed in the entry box, not foo.c. The only time -defaultextension seems to have effect is if -filetypes is {All *}

Thus confused about what behaviour should be implemented - as documented in the manpage or as implemented in the old style dialogs