From c4d8b6cea4442f6b28bbed3b2b264a8a55bcadbf Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 24 Jan 2025 13:21:37 +0000 Subject: [PATCH] [Settings]Fix ZoomIt page changing current directory --- .github/actions/spell-check/expect.txt | 1 + src/settings-ui/Settings.UI/Helpers/OpenFileName.cs | 6 ++++++ .../Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs | 1 + 3 files changed, 8 insertions(+) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 325b984c1cd3..9a0ba0dbe7eb 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -993,6 +993,7 @@ NNN NOACTIVATE NOAGGREGATION NOASYNC +NOCHANGEDIR NOCLIP NOCLOSEPROCESS NOCOALESCE diff --git a/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs b/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs index 3d7c1d8e902a..2a48deecef42 100644 --- a/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs +++ b/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs @@ -33,4 +33,10 @@ public class OpenFileName public IntPtr Hook = IntPtr.Zero; public string Template; } + + // https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea + public enum OpenFileNameFlags + { + OFN_NOCHANGEDIR = 0x00000008, + } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs index ab90af4ed3ac..b0e548353375 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs @@ -35,6 +35,7 @@ private static string PickFileDialog(string filter, string title, string initial openFileName.Title = title; openFileName.FilterIndex = initialFilter; openFileName.DefExt = null; + openFileName.Flags = (int)OpenFileNameFlags.OFN_NOCHANGEDIR; // OFN_NOCHANGEDIR flag is needed, because otherwise GetOpenFileName overwrites the process working directory. IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(App.GetSettingsWindow()); openFileName.Hwnd = windowHandle;