From a330258fc1d11057954a3f1c9ca93f06c10784cd Mon Sep 17 00:00:00 2001 From: ashok Date: Fri, 9 Oct 2015 04:03:31 +0000 Subject: Bug [47af31bd3a] - tk_getSaveFile adds . as extension. Also added more tests for -filetypes and -defaultextension combinations. --- tests/winDialog.test | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++- win/tkWinDialog.c | 25 +++++++---- 2 files changed, 131 insertions(+), 9 deletions(-) diff --git a/tests/winDialog.test b/tests/winDialog.test index 6b8af59..80a025c 100644 --- a/tests/winDialog.test +++ b/tests/winDialog.test @@ -265,6 +265,7 @@ test winDialog-5.6 {GetFileName: valid option, but missing value} -constraints { } -body { tk_getOpenFile -initialdir bar -title } -returnCodes error -result {value for "-title" missing} + test winDialog-5.7 {GetFileName: extension begins with .} -constraints { nt testwinevent } -body { @@ -281,6 +282,116 @@ test winDialog-5.7 {GetFileName: extension begins with .} -constraints { } -cleanup { unset msg } -result bar.foo + +test winDialog-5.7.1 {GetFileName: extension {} } -constraints { + nt testwinevent +} -body { + start {set x [tk_getSaveFile -defaultextension {} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar + +test winDialog-5.7.2 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints { + nt testwinevent +} -body { + start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar + +test winDialog-5.7.3 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints { + nt testwinevent +} -body { + start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar.c} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar.c + +test winDialog-5.7.4 {GetFileName: extension {} } -constraints { + nt testwinevent +} -body { + # Although the docs do not explicitly mention, -filetypes seems to + # override -defaultextension + start {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {foo} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar.c + +test winDialog-5.7.5 {GetFileName: extension {} } -constraints { + nt testwinevent +} -body { + # Although the docs do not explicitly mention, -filetypes seems to + # override -defaultextension + start {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar.c + + +test winDialog-5.7.6 {GetFileName: All/extension } -constraints { + nt testwinevent +} -body { + # In 8.6.4 this combination resulted in bar.ext.ext which is bad + start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {ext} -title Save]} + set msg {} + then { + if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} { + Click cancel + } else { + Click ok + } + } + set x "[file tail $x]$msg" +} -cleanup { + unset msg +} -result bar.ext + + test winDialog-5.8 {GetFileName: extension doesn't begin with .} -constraints { nt testwinevent } -body { @@ -362,7 +473,7 @@ test winDialog-5.12.1 {tk_getSaveFile: initial directory: ~} -constraints { } -result [file normalize [file join ~ "5 12 1"]] test winDialog-5.12.2 {tk_getSaveFile: initial directory: ~user} -constraints { - nt testwinevent DISABLED + nt testwinevent } -body { # 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. @@ -377,7 +488,7 @@ test winDialog-5.12.2 {tk_getSaveFile: initial directory: ~user} -constraints { Click ok } return $x -} -result [file normalize [file join ~$::env(USERNAME) "5 12 2"]] +} -result [file normalize [file join $::env(USERPROFILE) "5 12 2"]] test winDialog-5.12.3 {tk_getSaveFile: initial directory: .} -constraints { nt testwinevent diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c index 0188296..d7f63fb 100644 --- a/win/tkWinDialog.c +++ b/win/tkWinDialog.c @@ -1102,7 +1102,7 @@ ParseOFNOptions( for (i = 1; i < objc; i += 2) { int index; const char *string; - Tcl_Obj *valuePtr = objv[i + 1]; + Tcl_Obj *valuePtr; if (Tcl_GetIndexFromObjStruct(interp, objv[i], options, sizeof(struct Options), "option", 0, &index) != TCL_OK) { @@ -1112,19 +1112,25 @@ ParseOFNOptions( */ if (strcmp(Tcl_GetString(objv[i]), "-xpstyle")) goto error_return; - if (Tcl_GetBooleanFromObj(interp, valuePtr, + if (i + 1 == objc) { + Tcl_SetResult(interp, "value for \"-xpstyle\" missing", TCL_STATIC); + Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL); + goto error_return; + } + if (Tcl_GetBooleanFromObj(interp, objv[i+1], &optsPtr->forceXPStyle) != TCL_OK) goto error_return; continue; } else if (i + 1 == objc) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "value for \"%s\" missing", options[index].name)); - Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL); - goto error_return; + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "value for \"%s\" missing", options[index].name)); + Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL); + goto error_return; } + valuePtr = objv[i + 1]; string = Tcl_GetString(valuePtr); switch (options[index].value) { case FILE_DEFAULT: @@ -1185,6 +1191,7 @@ error_return: /* interp should already hold error */ /* On error, we need to clean up anything we might have allocated */ CleanupOFNOptions(optsPtr); return TCL_ERROR; + } @@ -1322,7 +1329,11 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr, goto vamoose; if (filterPtr) { - flags |= FOS_STRICTFILETYPES; + /* + * Causes -filetypes {{All *}} -defaultextension ext to return + * foo.ext.ext when foo is typed into the entry box + * flags |= FOS_STRICTFILETYPES; + */ hr = fdlgIf->lpVtbl->SetFileTypes(fdlgIf, nfilters, filterPtr); if (FAILED(hr)) goto vamoose; -- cgit v0.12