Skip to content

Commit b2956c5

Browse files
authored
Добавлена передача родителя в диалоги выбора файлов и папок (#13)
1 parent 27ef7e7 commit b2956c5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/dosymep.WpfCore/SimpleServices/WpfOpenFileDialogService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ public bool ShowDialog(string directoryName) {
7777
FilterIndex = FilterIndex,
7878
Title = Title ?? string.Empty,
7979
Filter = Filter ?? string.Empty,
80-
InitialDirectory = directoryName
80+
InitialDirectory = directoryName,
8181
};
8282

83-
bool? result = dialog.ShowDialog();
84-
if(result==true) {
83+
bool? result = dialog.ShowDialog(GetAssociatedWindow());
84+
if(result == true) {
8585
File = new FileInfo(dialog.SafeFileName);
8686
Files = dialog.SafeFileNames.Select(item => new FileInfo(item)).ToArray();
8787
} else {
8888
File = null;
8989
Files = null;
9090
}
91-
91+
9292
return result == true;
9393
}
9494

src/dosymep.WpfCore/SimpleServices/WpfOpenFolderDialogService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Diagnostics;
12
using System.IO;
3+
using System.Windows;
24

35
using dosymep.SimpleServices;
46

@@ -76,7 +78,10 @@ public bool ShowDialog(string directoryName) {
7678
dialog.Title = Title ?? string.Empty;
7779
dialog.InitialDirectory = directoryName;
7880

79-
CommonFileDialogResult? result = dialog.ShowDialog();
81+
Window? associatedWindow = GetAssociatedWindow();
82+
CommonFileDialogResult? result = associatedWindow is not null
83+
? dialog.ShowDialog(associatedWindow)
84+
: dialog.ShowDialog(Process.GetCurrentProcess().MainWindowHandle);
8085

8186
if(result == CommonFileDialogResult.Ok) {
8287
Folder = new DirectoryInfo(dialog.FileName);

src/dosymep.WpfCore/SimpleServices/WpfSaveFileDialogService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public bool ShowDialog(string? directoryName, string? fileName) {
7676
FileName = fileName ?? DefaultFileName ?? string.Empty
7777
};
7878

79-
bool? result = dialog.ShowDialog();
79+
bool? result = dialog.ShowDialog(GetAssociatedWindow());
8080
if(result == true) {
8181
File = new FileInfo(dialog.SafeFileName);
8282
} else {

0 commit comments

Comments
 (0)