2
// AlertDialogBackend.cs
5
// Thomas Ziegler <ziegler.thomas@web.de>
7
// Copyright (c) 2012 Thomas Ziegler
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.Collections.Generic;
33
namespace Xwt.WPFBackend
35
public class AlertDialogBackend : IAlertDialogBackend
37
MessageBoxResult dialogResult;
38
MessageBoxButton buttons;
40
MessageBoxOptions options;
41
MessageBoxResult defaultResult;
43
public AlertDialogBackend()
45
this.buttons = MessageBoxButton.OKCancel;
46
this.icon = MessageBoxImage.None;
47
this.options = MessageBoxOptions.None;
48
this.defaultResult = MessageBoxResult.Cancel;
51
public Command Run (WindowFrame transientFor, MessageDescription message)
53
this.icon = GetIcon (message.Icon);
54
this.buttons = ConvertButtons (message.Buttons);
55
if (message.SecondaryText == null)
56
message.SecondaryText = String.Empty;
58
message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
59
message.SecondaryText = String.Empty;
62
var wb = (WindowFrameBackend)WidgetRegistry.GetBackend (transientFor);
64
this.dialogResult = MessageBox.Show (wb.Window, message.Text,message.SecondaryText,
65
this.buttons, this.icon, this.defaultResult, this.options);
67
this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons,
68
this.icon, this.defaultResult, this.options);
71
return ConvertResultToCommand (this.dialogResult);
74
public bool ApplyToAll
80
MessageBoxImage GetIcon (string iconText)
83
case StockIcons.Error:
84
return MessageBoxImage.Error;
85
case StockIcons.Warning:
86
return MessageBoxImage.Warning;
87
case StockIcons.Information:
88
return MessageBoxImage.Information;
89
case StockIcons.Question:
90
return MessageBoxImage.Question;
92
return MessageBoxImage.None;
96
Command ConvertResultToCommand (MessageBoxResult dialogResult)
98
switch (dialogResult) {
99
case MessageBoxResult.None:
101
case MessageBoxResult.Cancel:
102
return Command.Cancel;
103
case MessageBoxResult.No:
105
case MessageBoxResult.Yes:
107
case MessageBoxResult.OK:
110
return Command.Cancel;
114
MessageBoxButton ConvertButtons (IList<Command> buttons)
116
MessageBoxButton result;
118
switch (buttons.Count){
120
if (buttons.Contains(Command.Ok)) {
121
result = MessageBoxButton.OK;
123
throw new NotImplementedException ();
127
if (buttons.Contains (Command.Ok) && buttons.Contains (Command.Cancel)) {
128
result = MessageBoxButton.OKCancel;
129
} else if (buttons.Contains (Command.Yes) && buttons.Contains (Command.No)) {
130
result = MessageBoxButton.YesNo;
132
throw new NotImplementedException ();
136
if (buttons.Contains (Command.Yes) && buttons.Contains (Command.No) && buttons.Contains (Command.Cancel)) {
137
result = MessageBoxButton.YesNoCancel;
139
throw new NotImplementedException ();
143
throw new NotImplementedException ();
149
public void Dispose ()
b'\\ No newline at end of file'