Tk Source Code

Check-in [d7028f6d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Revise the proposed "-nocomplain" option to "-confirmoverwrite"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-382
Files: files | file ages | folders
SHA1: d7028f6da5780d2f87cd825e67b6ee6988089cf7
User & Date: dgp 2011-10-05 19:18:20
Context
2011-10-17
19:54
Fix up the implementation to account for shared options enumeration. check-in: de044a4c user: dgp tags: tip-382
2011-10-05
19:18
Revise the proposed "-nocomplain" option to "-confirmoverwrite" check-in: d7028f6d user: dgp tags: tip-382
2011-10-04
17:53
Contributed implementation patch for TIP 382. check-in: c8b22e32 user: dgp tags: tip-382
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/tkfbox.tcl.

982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
    if {$type eq "open"} {
	lappend specs {-multiple "" "" "0"}
    }

    # The "-nocomplain" option is only available for the "save" file dialog.
    #
    if {$type eq "save"} {
	lappend specs {-nocomplain "" "" "0"}
    }

    # 2: default values depending on the type of the dialog
    #
    if {![info exists data(selectPath)]} {
	# first time the dialog has been popped up
	set data(selectPath) [pwd]







|







982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
    if {$type eq "open"} {
	lappend specs {-multiple "" "" "0"}
    }

    # The "-nocomplain" option is only available for the "save" file dialog.
    #
    if {$type eq "save"} {
	lappend specs {-confirmoverwrite "" "" "1"}
    }

    # 2: default values depending on the type of the dialog
    #
    if {![info exists data(selectPath)]} {
	# first time the dialog has been popped up
	set data(selectPath) [pwd]
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
	} else {
	    set selectFilePath [JoinFile $data(selectPath) $data(selectFile)]
	}

	set Priv(selectFile) $data(selectFile)
	set Priv(selectPath) $data(selectPath)

	if {($data(type) eq "save") && !$data(-nocomplain) && [file exists $selectFilePath]} {
	    set reply [tk_messageBox -icon warning -type yesno -parent $w \
		    -message [mc "File \"%1\$s\" already exists.\nDo you want\
		    to overwrite it?" $selectFilePath]]
	    if {$reply eq "no"} {
		return
	    }
	}







|







1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
	} else {
	    set selectFilePath [JoinFile $data(selectPath) $data(selectFile)]
	}

	set Priv(selectFile) $data(selectFile)
	set Priv(selectPath) $data(selectPath)

	if {($data(type) eq "save") && $data(-confirmoverwrite) && [file exists $selectFilePath]} {
	    set reply [tk_messageBox -icon warning -type yesno -parent $w \
		    -message [mc "File \"%1\$s\" already exists.\nDo you want\
		    to overwrite it?" $selectFilePath]]
	    if {$reply eq "no"} {
		return
	    }
	}

Changes to win/tkWinDialog.c.

587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
    int open)			/* 1 to call GetOpenFileName(), 0 to call
				 * GetSaveFileName(). */
{
    OPENFILENAMEW ofn;
    WCHAR file[TK_MULTI_MAX_PATH];
    OFNData ofnData;
    int cdlgerr;
    int filterIndex = 0, result = TCL_ERROR, winCode, oldMode, i, multi = 0, noComplain = 0;

    char *extension = NULL, *title = NULL;
    Tk_Window tkwin = (Tk_Window) clientData;
    HWND hWnd;
    Tcl_Obj *filterObj = NULL, *initialTypeObj = NULL, *typeVariableObj = NULL;
    Tcl_DString utfFilterString, utfDirString, ds;
    Tcl_DString extString, filterString, dirString, titleString;
    Tcl_Encoding unicodeEncoding = TkWinGetUnicodeEncoding();
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    static CONST char *saveOptionStrings[] = {
	"-defaultextension", "-filetypes", "-initialdir", "-initialfile",

	"-parent", "-title", "-typevariable", "-nocomplain", NULL
    };
    static CONST char *openOptionStrings[] = {
	"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
	"-multiple", "-parent", "-title", "-typevariable", NULL
    };
    CONST char **optionStrings;

    enum options {
	FILE_DEFAULT,	FILE_TYPES,	FILE_INITDIR,	FILE_INITFILE,
	FILE_MULTIPLE,	FILE_PARENT,	FILE_TITLE,     FILE_TYPEVARIABLE,
	FILE_NOCOMPLAIN
    };

    file[0] = '\0';
    ZeroMemory(&ofnData, sizeof(OFNData));
    Tcl_DStringInit(&utfFilterString);
    Tcl_DStringInit(&utfDirString);








|
>










|
>
|








|
|
|







587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
    int open)			/* 1 to call GetOpenFileName(), 0 to call
				 * GetSaveFileName(). */
{
    OPENFILENAMEW ofn;
    WCHAR file[TK_MULTI_MAX_PATH];
    OFNData ofnData;
    int cdlgerr;
    int filterIndex = 0, result = TCL_ERROR, winCode, oldMode, i, multi = 0;
    int confirmOverwrite = 1;
    char *extension = NULL, *title = NULL;
    Tk_Window tkwin = (Tk_Window) clientData;
    HWND hWnd;
    Tcl_Obj *filterObj = NULL, *initialTypeObj = NULL, *typeVariableObj = NULL;
    Tcl_DString utfFilterString, utfDirString, ds;
    Tcl_DString extString, filterString, dirString, titleString;
    Tcl_Encoding unicodeEncoding = TkWinGetUnicodeEncoding();
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    static CONST char *saveOptionStrings[] = {
	"-confirmoverwrite", "-defaultextension", "-filetypes",
	"-initialdir", "-initialfile", "-parent", "-title",
	"-typevariable", "-nocomplain", NULL
    };
    static CONST char *openOptionStrings[] = {
	"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
	"-multiple", "-parent", "-title", "-typevariable", NULL
    };
    CONST char **optionStrings;

    enum options {
	FILE_CONFOW,	FILE_DEFAULT,	FILE_TYPES,	FILE_INITDIR,
	FILE_INITFILE,	FILE_MULTIPLE,	FILE_PARENT,	FILE_TITLE,
	FILE_TYPEVARIABLE
    };

    file[0] = '\0';
    ZeroMemory(&ofnData, sizeof(OFNData));
    Tcl_DStringInit(&utfFilterString);
    Tcl_DStringInit(&utfDirString);

709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
	    title = string;
	    break;
	case FILE_TYPEVARIABLE:
	    typeVariableObj = valuePtr;
	    initialTypeObj = Tcl_ObjGetVar2(interp, typeVariableObj, NULL,
		    TCL_GLOBAL_ONLY);
	    break;
	case FILE_NOCOMPLAIN:
	    if (Tcl_GetBooleanFromObj(interp, valuePtr, &noComplain) != TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	}
    }

    if (MakeFilter(interp, filterObj, &utfFilterString, initialTypeObj,







|
|







711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
	    title = string;
	    break;
	case FILE_TYPEVARIABLE:
	    typeVariableObj = valuePtr;
	    initialTypeObj = Tcl_ObjGetVar2(interp, typeVariableObj, NULL,
		    TCL_GLOBAL_ONLY);
	    break;
	case FILE_CONFOW:
	    if (Tcl_GetBooleanFromObj(interp, valuePtr, &confirmOverwrite) != TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	}
    }

    if (MakeFilter(interp, filterObj, &utfFilterString, initialTypeObj,
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR
	    | OFN_EXPLORER | OFN_ENABLEHOOK| OFN_ENABLESIZING;
    ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProcW;
    ofn.lCustData = (LPARAM) &ofnData;

    if (open != 0) {
	ofn.Flags |= OFN_FILEMUSTEXIST;
    } else if (noComplain == 0) {
	ofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if (tsdPtr->debugFlag != 0) {
	ofnData.interp = interp;
    }
    if (multi != 0) {
	ofn.Flags |= OFN_ALLOWMULTISELECT;







|







744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
    ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR
	    | OFN_EXPLORER | OFN_ENABLEHOOK| OFN_ENABLESIZING;
    ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProcW;
    ofn.lCustData = (LPARAM) &ofnData;

    if (open != 0) {
	ofn.Flags |= OFN_FILEMUSTEXIST;
    } else if (confirmOverwrite) {
	ofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if (tsdPtr->debugFlag != 0) {
	ofnData.interp = interp;
    }
    if (multi != 0) {
	ofn.Flags |= OFN_ALLOWMULTISELECT;