summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/getOpenFile.n6
-rw-r--r--library/tkfbox.tcl8
-rw-r--r--win/tkWinDialog.c60
3 files changed, 36 insertions, 38 deletions
diff --git a/doc/getOpenFile.n b/doc/getOpenFile.n
index 0296bfa..7ebae67 100644
--- a/doc/getOpenFile.n
+++ b/doc/getOpenFile.n
@@ -35,6 +35,12 @@ whether the existing file should be overwritten or not.
The following \fIoption\-value\fR pairs are possible as command line
arguments to these two commands:
.TP
+\fB\-confirmoverwrite\fR \fIboolean\fR
+Configures how the Save dialog reacts when the selected file already
+exists, and saving would overwrite it. A true value requests a
+confirmation dialog be presented to the user. A false value requests
+that the overwrite take place without confirmation. Default value is true.
+.TP
\fB\-defaultextension\fR \fIextension\fR
.
Specifies a string that will be appended to the filename if the user
diff --git a/library/tkfbox.tcl b/library/tkfbox.tcl
index 4cdcaf3..6354300 100644
--- a/library/tkfbox.tcl
+++ b/library/tkfbox.tcl
@@ -266,6 +266,12 @@ proc ::tk::dialog::file::Config {dataName type argList} {
lappend specs {-multiple "" "" "0"}
}
+ # The "-confirmoverwrite" option is only 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)]} {
@@ -1121,7 +1127,7 @@ proc ::tk::dialog::file::Done {w {selectFilePath ""}} {
set Priv(selectFile) $data(selectFile)
set Priv(selectPath) $data(selectPath)
- if {($data(type) eq "save") && [file exists $selectFilePath]} {
+ 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]]
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index 4dc8d9e..9ed5875 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -576,6 +576,7 @@ GetFileName(
OFNData ofnData;
int cdlgerr;
int filterIndex = 0, result = TCL_ERROR, winCode, oldMode, i, multi = 0;
+ int inValue, confirmOverwrite = 1;
const char *extension = NULL, *title = NULL;
Tk_Window tkwin = clientData;
HWND hWnd;
@@ -587,16 +588,20 @@ GetFileName(
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
static const char *const saveOptionStrings[] = {
"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
- "-parent", "-title", "-typevariable", NULL
+ "-parent", "-title", "-typevariable",
+ "-confirmoverwrite",
+ NULL
};
static const char *const openOptionStrings[] = {
"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
- "-multiple", "-parent", "-title", "-typevariable", NULL
+ "-parent", "-title", "-typevariable",
+ "-multiple",
+ NULL
};
- const char *const *optionStrings;
enum options {
- FILE_DEFAULT, FILE_TYPES, FILE_INITDIR, FILE_INITFILE,
- FILE_MULTIPLE, FILE_PARENT, FILE_TITLE, FILE_TYPEVARIABLE
+ FILE_DEFAULT, FILE_TYPES, FILE_INITDIR, FILE_INITFILE,
+ FILE_PARENT, FILE_TITLE, FILE_TYPEVARIABLE,
+ FILE_MULTIPLE_OR_CONFIRMOW
};
file[0] = '\0';
@@ -604,16 +609,6 @@ GetFileName(
Tcl_DStringInit(&utfFilterString);
Tcl_DStringInit(&utfDirString);
- /*
- * Parse the arguments.
- */
-
- if (open) {
- optionStrings = openOptionStrings;
- } else {
- optionStrings = saveOptionStrings;
- }
-
for (i = 1; i < objc; i += 2) {
int index;
const char *string;
@@ -622,26 +617,12 @@ GetFileName(
optionPtr = objv[i];
valuePtr = objv[i + 1];
- if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings,
+ if (Tcl_GetIndexFromObj(interp, optionPtr,
+ open ? openOptionStrings : saveOptionStrings,
"option", 0, &index) != TCL_OK) {
goto end;
}
- /*
- * We want to maximize code sharing between the open and save file
- * dialog implementations; in particular, the switch statement below.
- * We use different sets of option strings from the GetIndexFromObj
- * call above, but a single enumeration for both. The save file dialog
- * doesn't support -multiple, but it falls in the middle of the
- * enumeration. Ultimately, this means that when the index found by
- * GetIndexFromObj is >= FILE_MULTIPLE, when doing a save file dialog,
- * we have to increment the index, so that it matches the open file
- * dialog enumeration.
- */
-
- if (!open && index >= FILE_MULTIPLE) {
- index++;
- }
if (i + 1 == objc) {
string = Tcl_GetString(optionPtr);
Tcl_AppendResult(interp, "value for \"", string, "\" missing",
@@ -676,11 +657,6 @@ GetFileName(
sizeof(file), NULL, NULL, NULL);
Tcl_DStringFree(&ds);
break;
- case FILE_MULTIPLE:
- if (Tcl_GetBooleanFromObj(interp, valuePtr, &multi) != TCL_OK) {
- return TCL_ERROR;
- }
- break;
case FILE_PARENT:
tkwin = Tk_NameToWindow(interp, string, tkwin);
if (tkwin == NULL) {
@@ -695,6 +671,16 @@ GetFileName(
initialTypeObj = Tcl_ObjGetVar2(interp, typeVariableObj, NULL,
TCL_GLOBAL_ONLY);
break;
+ case FILE_MULTIPLE_OR_CONFIRMOW:
+ if (Tcl_GetBooleanFromObj(interp, valuePtr, &inValue) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (open) {
+ multi = inValue;
+ } else {
+ confirmOverwrite = inValue;
+ }
+ break;
}
}
@@ -723,7 +709,7 @@ GetFileName(
if (open != 0) {
ofn.Flags |= OFN_FILEMUSTEXIST;
- } else {
+ } else if (confirmOverwrite) {
ofn.Flags |= OFN_OVERWRITEPROMPT;
}
if (tsdPtr->debugFlag != 0) {