GtkFileChooserNativeWin32: Add some option flags
authorLuca Bacci <luca.bacci982@gmail.com>
Fri, 7 Oct 2022 17:06:09 +0000 (19:06 +0200)
committerLuca Bacci <luca.bacci982@gmail.com>
Fri, 7 Oct 2022 17:06:09 +0000 (19:06 +0200)
Avoid changing the current directory.
Also avoid creating a sample file to test if the target file
can be created.

References:

* "Why does the common file dialog change the current directory?"
 -> https://devblogs.microsoft.com/oldnewthing/20101112-00/?p=12293

* "Why does the common file save dialog create a temporary file and then delete it?"
 -> https://devblogs.microsoft.com/oldnewthing/20140429-00/?p=1123

gtk/gtkfilechoosernativewin32.c

index 1f449c96f6fffe831d12e601bb62040699e4242e..97150e650d4420ee1e081d5a544d51a227e2f6ba 100644 (file)
@@ -21,8 +21,8 @@
 
 /* Vista or newer */
 #define _WIN32_WINNT 0x0600
-#define WINVER _WIN32_WINNT
-#define NTDDI_VERSION NTDDI_VISTA
+#include <sdkddkver.h>
+
 #define COBJMACROS
 
 #include "gtkfilechoosernativeprivate.h"
@@ -469,7 +469,7 @@ filechooser_win32_thread (gpointer _data)
   HRESULT hr;
   IFileDialog *pfd = NULL;
   IFileDialog2 *pfd2 = NULL;
-  DWORD flags;
+  DWORD flags = 0;
   DWORD cookie;
   guint j, n_items;
 
@@ -491,7 +491,10 @@ filechooser_win32_thread (gpointer _data)
   if (FAILED (hr))
     g_error ("Can't get FileDialog options: %s", g_win32_error_message (hr));
 
-  flags |= FOS_FORCEFILESYSTEM;
+  flags |= FOS_FORCEFILESYSTEM |
+           FOS_OVERWRITEPROMPT |
+           FOS_NOTESTFILECREATE |
+           FOS_NOCHANGEDIR;
 
   if (data->folder)
     flags |= FOS_PICKFOLDERS;
@@ -502,8 +505,6 @@ filechooser_win32_thread (gpointer _data)
   if (data->select_multiple)
     flags |= FOS_ALLOWMULTISELECT;
 
-  flags |= FOS_OVERWRITEPROMPT;
-
   hr = IFileDialog_SetOptions (pfd, flags);
   if (FAILED (hr))
     g_error ("Can't set FileDialog options: %s", g_win32_error_message (hr));