forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageBox.cs
More file actions
189 lines (165 loc) · 6.65 KB
/
MessageBox.cs
File metadata and controls
189 lines (165 loc) · 6.65 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
using System;
using System.Application.Services;
using System.Application.Settings;
using System.Application.UI.ViewModels;
using System.Collections.Generic;
using System.Properties;
using System.Text;
using System.Threading.Tasks;
namespace System.Application
{
/// <summary>
/// 显示消息框
/// </summary>
public static partial class MessageBox
{
/// <summary>
/// 指定显示在消息框上的按钮。 用作 <see cref="MessageBox"/>.Show... 方法的参数
/// </summary>
public enum Button
{
OK = 0,
OKCancel = 1,
[Obsolete("non-standard api")]
YesNo = 4,
[Obsolete("non-standard api")]
YesNoCancel = 3,
[Obsolete("non-standard api")]
OkAbort = 1000,
[Obsolete("non-standard api")]
YesNoAbort = 1001,
}
/// <summary>
/// 指定消息框所显示的图标
/// </summary>
public enum Image
{
Asterisk = 64,
Error = 16,
Exclamation = 48,
Hand = 16,
Information = 64,
None = 0,
[Obsolete("The question mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the question mark symbol with a help information symbol. Therefore, do not use this question mark symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.")]
Question = 32,
Stop = 16,
Warning = 48,
[Obsolete("non-standard api")]
Battery = 1000,
[Obsolete("non-standard api")]
Database,
[Obsolete("non-standard api")]
Folder,
[Obsolete("non-standard api")]
Forbidden,
[Obsolete("non-standard api")]
Plus,
[Obsolete("non-standard api")]
Setting,
[Obsolete("non-standard api")]
SpeakerLess,
[Obsolete("non-standard api")]
SpeakerMore,
[Obsolete("non-standard api")]
Stop2,
[Obsolete("non-standard api")]
Stopwatch,
[Obsolete("non-standard api")]
Wifi,
}
/// <summary>
/// 指定弹框是否可选不再显示。 用作 <see cref="MessageBox"/>.Show... 方法的参数。
/// </summary>
public enum DontPromptType
{
Undefined = 0,
/// <summary>
/// 解锁成就提示
/// </summary>
UnLockAchievement = 1,
/// <summary>
/// 捐助提示
/// </summary>
Donate = 2,
ResetHostsFile,
SaveEditAppInfo,
AndroidCertificateTrustTip,
}
/// <summary>
/// 指定用户单击的消息框按钮。 由 <see cref="MessageBox"/>.Show... 方法返回。
/// </summary>
public enum Result
{
Cancel = 2,
None = 0,
OK = 1,
[Obsolete("non-standard api")]
Yes = 6,
[Obsolete("non-standard api")]
No = 7,
[Obsolete("non-standard api")]
Abort = 1000,
}
const string default_caption = ThisAssembly.AssemblyTrademark;
const Button default_button = Button.OK;
static readonly IMessageBoxService? mbcs = IMessageBoxService.Instance;
public const Button OKCancel = Button.OKCancel;
/// <inheritdoc cref="IMessageBoxService.ShowAsync(string, string, Button, Image)"/>
public static async Task<Result> ShowAsync(
string messageBoxText, string caption = default_caption, Button button = default_button, Image icon = default, DontPromptType rememberChooseKey = default)
{
if (mbcs != null)
{
return await mbcs.ShowAsync(messageBoxText, caption, button, icon);
}
var isDoNotShow = rememberChooseKey != DontPromptType.Undefined;
if (isDoNotShow &&
UISettings.DoNotShowMessageBoxs.Value?.Contains(rememberChooseKey) == true)
{
return Result.OK;
}
var viewModel = new MessageBoxWindowViewModel
{
Content = messageBoxText,
IsCancelcBtn = button == OKCancel,
IsShowRememberChoose = isDoNotShow,
};
var r = await IWindowManager.Instance.ShowDialog(
CustomWindow.MessageBox, viewModel, caption, ResizeMode.NoResize);
if (r && viewModel.RememberChoose && isDoNotShow)
{
if (UISettings.DoNotShowMessageBoxs.Value == null)
{
UISettings.DoNotShowMessageBoxs.Value = new() { rememberChooseKey };
}
else
{
if (UISettings.DoNotShowMessageBoxs.Value.Contains(rememberChooseKey) == false)
{
UISettings.DoNotShowMessageBoxs.Value.Add(rememberChooseKey);
}
}
UISettings.DoNotShowMessageBoxs.RaiseValueChanged();
}
return r ? Result.OK : Result.Cancel;
}
/// <inheritdoc cref="IMessageBoxService.ShowAsync(string, string, Button, Image)"/>
public static async void Show(string messageBoxText, string caption = default_caption, Button button = default_button, Image icon = default, DontPromptType rememberChooseKey = default)
{
await ShowAsync(messageBoxText, caption, button, icon, rememberChooseKey);
}
///// <inheritdoc cref="IMessageBoxService.ShowAsync(string, string, Button, Image)"/>
//public static Task<Result> ShowAsync(Exception exception, string caption = default_caption, Button button = default_button, Image icon = default)
//{
// var messageBoxText = exception.GetAllMessage();
// return ShowAsync(messageBoxText, caption, button, icon);
//}
/// <inheritdoc cref="IMessageBoxService.ShowAsync(string, string, Button, Image)"/>
public static void Show(Exception exception, string caption = default_caption, Button button = default_button, Image icon = default)
{
var messageBoxText = exception.GetAllMessage();
Show(messageBoxText, caption, button, icon);
}
public static bool IsOK(this Result r) => r == Result.OK;
}
}