-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathDialogControllerExtensions.cs
More file actions
239 lines (222 loc) · 12.5 KB
/
Copy pathDialogControllerExtensions.cs
File metadata and controls
239 lines (222 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace BizHawk.Client.Common
{
public static class DialogControllerExtensions
{
public static void AddOnScreenMessage(
this IDialogParent dialogParent,
string message,
[LiteralExpected] int? duration = null)
=> dialogParent.DialogController.AddOnScreenMessage(message, duration);
public static void DoWithTempMute(this IDialogController dialogController, Action action)
{
dialogController.StopSound();
action();
dialogController.StartSound();
}
public static T DoWithTempMute<T>(this IDialogController dialogController, Func<T> action)
{
dialogController.StopSound();
var ret = action();
dialogController.StartSound();
return ret;
}
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
public static void ModalMessageBox(
this IDialogParent dialogParent,
string text,
string? caption = null,
EMsgBoxIcon? icon = null)
=> dialogParent.DialogController.ShowMessageBox(owner: dialogParent, text: text, caption: caption, icon: icon);
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
/// <returns><see langword="true"/> iff "Yes"/"OK" was chosen</returns>
public static bool ModalMessageBox2(
this IDialogParent dialogParent,
string text,
string? caption = null,
EMsgBoxIcon? icon = null,
bool useOKCancel = false)
=> dialogParent.DialogController.ShowMessageBox2(owner: dialogParent, text: text, caption: caption, icon: icon, useOKCancel: useOKCancel);
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
/// <returns><see langword="true"/> if "Yes" was chosen, <see langword="false"/> if "No" was chosen, or <see langword="null"/> if "Cancel" was chosen</returns>
public static bool? ModalMessageBox3(
this IDialogParent dialogParent,
string text,
string? caption = null,
EMsgBoxIcon? icon = null)
=> dialogParent.DialogController.ShowMessageBox3(owner: dialogParent, text: text, caption: caption, icon: icon);
/// <summary>Creates and shows a <c>System.Windows.Forms.OpenFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="discardCWDChange"><c>OpenFileDialog.RestoreDirectory</c> (isn't this useless when specifying <paramref name="initDir"/>? keeping it for backcompat)</param>
/// <param name="filter"><c>OpenFileDialog.Filter</c></param>
/// <param name="initDir"><c>OpenFileDialog.InitialDirectory</c>; initial browse location</param>
/// <param name="initFileName"><c>OpenFileDialog.FileName</c>; pre-selected file (overrides <paramref name="initDir"/>?)</param>
/// <returns>filename of selected file, or <see langword="null"/> iff cancelled</returns>
public static string? ShowFileOpenDialog(
this IDialogParent dialogParent,
string initDir,
bool discardCWDChange = false,
FilesystemFilterSet? filter = null,
string? initFileName = null)
=> dialogParent.ShowFileMultiOpenDialog(
discardCWDChange: discardCWDChange,
filterStr: filter?.ToString(),
initDir: initDir,
initFileName: initFileName)?[0];
/// <summary>Creates and shows a <c>System.Windows.Forms.OpenFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="filter"><c>OpenFileDialog.Filter</c></param>
/// <param name="filterIndex"><c>OpenFileDialog.FilterIndex</c>; initially selected entry in <paramref name="filter"/></param>
/// <param name="initDir"><c>OpenFileDialog.InitialDirectory</c>; initial browse location</param>
/// <param name="windowTitle"><c>OpenFileDialog.Title</c></param>
/// <returns>filename of selected file, or <see langword="null"/> iff cancelled</returns>
/// <remarks>only used from MainForm, but don't move it there</remarks>
public static string? ShowFileOpenDialog(
this IDialogParent dialogParent,
FilesystemFilterSet? filter,
ref int filterIndex,
string initDir,
string? windowTitle = null)
=> dialogParent.DialogController.ShowFileMultiOpenDialog(
dialogParent: dialogParent,
filterStr: filter?.ToString(),
filterIndex: ref filterIndex,
initDir: initDir,
windowTitle: windowTitle)?[0];
/// <summary>Creates and shows a <c>System.Windows.Forms.OpenFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="filterStr"><c>OpenFileDialog.Filter</c></param>
/// <param name="initDir"><c>OpenFileDialog.InitialDirectory</c>; initial browse location</param>
/// <param name="initFileName"><c>OpenFileDialog.FileName</c>; pre-selected file (overrides <paramref name="initDir"/>?)</param>
/// <returns>filename of selected file, or <see langword="null"/> iff cancelled</returns>
/// <remarks>only used from Lua, but don't move it there</remarks>
public static string? ShowFileOpenDialog(
this IDialogParent dialogParent,
string? filterStr,
string initDir,
string? initFileName = null)
=> dialogParent.ShowFileMultiOpenDialog(
filterStr: filterStr,
initDir: initDir,
initFileName: initFileName)?[0];
/// <summary>Creates and shows a <c>System.Windows.Forms.SaveFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="discardCWDChange"><c>SaveFileDialog.RestoreDirectory</c> (renamed for clarity without inverting value; isn't this useless when specifying <paramref name="initDir"/>? keeping it for backcompat)</param>
/// <param name="fileExt"><c>SaveFileDialog.DefaultExt</c>; used only when the user's chosen filename doesn't have an extension (omit leading '.')</param>
/// <param name="filter"><c>SaveFileDialog.Filter</c></param>
/// <param name="initDir"><c>SaveFileDialog.InitialDirectory</c>; initial browse location</param>
/// <param name="initFileName"><c>SaveFileDialog.FileName</c>; pre-selected file (overrides <paramref name="initDir"/>?)</param>
/// <param name="muteOverwriteWarning"><c>SaveFileDialog.OverwritePrompt</c> (renamed for clarity with inverted value)</param>
/// <returns>filename of selected destination, or <see langword="null"/> iff cancelled</returns>
public static string? ShowFileSaveDialog(
this IDialogParent dialogParent,
string initDir,
bool discardCWDChange = false,
string? fileExt = null,
FilesystemFilterSet? filter = null,
string? initFileName = null,
bool muteOverwriteWarning = false)
=> dialogParent.DialogController.ShowFileSaveDialog(
dialogParent: dialogParent,
discardCWDChange: discardCWDChange,
fileExt: fileExt,
filterStr: filter?.ToString(),
initDir: initDir,
initFileName: initFileName,
muteOverwriteWarning: muteOverwriteWarning);
/// <summary>Creates and shows a <c>System.Windows.Forms.FolderBrowserDialog</c> or equivalent</summary>
/// <param name="dialogParent">parent window</param>
/// <param name="initDir"><c>FolderBrowserDialog.SelectedPath</c>; pre-selected directory</param>
/// <param name="subtitle"><c>FolderBrowserDialog.Description</c></param>
/// <returns>filename of selected directory, or <see langword="null"/> iff cancelled</returns>
public static string? ShowFolderSelectDialog(
this IDialogParent dialogParent,
string? initDir = null,
string? subtitle = null)
=> dialogParent.DialogController.ShowFolderSelectDialog(
dialogParent: dialogParent,
initDir: initDir,
subtitle: subtitle);
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent without a parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
public static void ShowMessageBox(
this IDialogController dialogController,
string text,
string? caption = null,
EMsgBoxIcon? icon = null)
=> dialogController.ShowMessageBox(owner: null, text: text, caption: caption, icon: icon);
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent without a parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
/// <returns><see langword="true"/> iff "Yes"/"OK" was chosen</returns>
public static bool ShowMessageBox2(
this IDialogController dialogController,
string text,
string? caption = null,
EMsgBoxIcon? icon = null,
bool useOKCancel = false)
=> dialogController.ShowMessageBox2(owner: null, text: text, caption: caption, icon: icon, useOKCancel: useOKCancel);
/// <summary>
/// Creates and shows a <c>System.Windows.Forms.MessageBox</c> or equivalent without a parent, with the given <paramref name="text"/>,
/// and with the given <paramref name="caption"/> and <paramref name="icon"/> if they're specified.
/// </summary>
/// <returns><see langword="true"/> if "Yes" was chosen, <see langword="false"/> if "No" was chosen, or <see langword="null"/> if "Cancel" was chosen</returns>
public static bool? ShowMessageBox3(
this IDialogController dialogController,
string text,
string? caption = null,
EMsgBoxIcon? icon = null)
=> dialogController.ShowMessageBox3(owner: null, text: text, caption: caption, icon: icon);
/// <summary>Creates and shows a <c>System.Windows.Forms.OpenFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="discardCWDChange"><c>OpenFileDialog.RestoreDirectory</c> (renamed for clarity without inverting value; isn't this useless when specifying <paramref name="initDir"/>? keeping it for backcompat)</param>
/// <param name="filterStr"><c>OpenFileDialog.Filter</c> (call <c>ToString</c> on a <see cref="FilesystemFilter"/>/<see cref="FilesystemFilterSet"/>)</param>
/// <param name="initDir"><c>OpenFileDialog.InitialDirectory</c>; initial browse location</param>
/// <param name="initFileName"><c>OpenFileDialog.FileName</c>; pre-selected file (overrides <paramref name="initDir"/>?)</param>
/// <param name="maySelectMultiple"><c>OpenFileDialog.Multiselect</c></param>
/// <returns>filenames of selected files, or <see langword="null"/> iff cancelled</returns>
private static IReadOnlyList<string>? ShowFileMultiOpenDialog(
this IDialogParent dialogParent,
string? filterStr,
string initDir,
bool discardCWDChange = false,
string? initFileName = null,
bool maySelectMultiple = false)
{
var filterIndex = 1; // you'd think the default would be 0, but it's not
return dialogParent.DialogController.ShowFileMultiOpenDialog(
dialogParent: dialogParent,
discardCWDChange: discardCWDChange,
filterStr: filterStr,
filterIndex: ref filterIndex,
initDir: initDir,
initFileName: initFileName,
maySelectMultiple: maySelectMultiple);
}
/// <summary>Creates and shows a <c>System.Windows.Forms.OpenFileDialog</c> or equivalent with the receiver (<paramref name="dialogParent"/>) as its parent</summary>
/// <param name="discardCWDChange"><c>OpenFileDialog.RestoreDirectory</c> (isn't this useless when specifying <paramref name="initDir"/>? keeping it for backcompat)</param>
/// <param name="filter"><c>OpenFileDialog.Filter</c></param>
/// <param name="initDir"><c>OpenFileDialog.InitialDirectory</c>; initial browse location</param>
/// <returns>filenames of selected files, or <see langword="null"/> iff cancelled</returns>
public static IReadOnlyList<string>? ShowFileMultiOpenDialog(
this IDialogParent dialogParent,
string initDir,
bool discardCWDChange = false,
FilesystemFilterSet? filter = null)
=> dialogParent.ShowFileMultiOpenDialog(
discardCWDChange: discardCWDChange,
filterStr: filter?.ToString(),
initDir: initDir,
initFileName: null,
maySelectMultiple: true);
}
}