~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.WPF/Xwt.WPFBackend/AlertDialogBackend.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// AlertDialogBackend.cs
 
3
//  
 
4
// Author:
 
5
//       Thomas Ziegler <ziegler.thomas@web.de>
 
6
// 
 
7
// Copyright (c) 2012 Thomas Ziegler
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using System.Collections.Generic;
 
28
using System.Windows;
 
29
 
 
30
using Xwt.Backends;
 
31
using Xwt.Engine;
 
32
 
 
33
namespace Xwt.WPFBackend
 
34
{
 
35
        public class AlertDialogBackend : IAlertDialogBackend
 
36
        {
 
37
                MessageBoxResult dialogResult;
 
38
                MessageBoxButton buttons;
 
39
                MessageBoxImage icon;
 
40
                MessageBoxOptions options;
 
41
                MessageBoxResult defaultResult;
 
42
 
 
43
                public AlertDialogBackend()
 
44
                {
 
45
                        this.buttons = MessageBoxButton.OKCancel;
 
46
                        this.icon = MessageBoxImage.None;
 
47
                        this.options = MessageBoxOptions.None;
 
48
                        this.defaultResult = MessageBoxResult.Cancel;
 
49
                }
 
50
 
 
51
                public Command Run (WindowFrame transientFor, MessageDescription message)
 
52
                {
 
53
                        this.icon = GetIcon (message.Icon);
 
54
                        this.buttons = ConvertButtons (message.Buttons);
 
55
                        if (message.SecondaryText == null)
 
56
                                message.SecondaryText = String.Empty;
 
57
                        else {
 
58
                                message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
 
59
                                message.SecondaryText = String.Empty;
 
60
                        }
 
61
 
 
62
                        var wb = (WindowFrameBackend)WidgetRegistry.GetBackend (transientFor);
 
63
                        if (wb != null) {
 
64
                                this.dialogResult = MessageBox.Show (wb.Window, message.Text,message.SecondaryText,
 
65
                                                                                                        this.buttons, this.icon, this.defaultResult, this.options);
 
66
                        } else {
 
67
                                this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons, 
 
68
                                                                                                        this.icon, this.defaultResult, this.options);
 
69
                        }
 
70
 
 
71
                        return ConvertResultToCommand (this.dialogResult);
 
72
                }
 
73
 
 
74
                public bool ApplyToAll
 
75
                {
 
76
                        get;
 
77
                        set;
 
78
                }
 
79
 
 
80
                MessageBoxImage GetIcon (string iconText)
 
81
                {
 
82
                        switch (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;
 
91
                        default:
 
92
                                return MessageBoxImage.None;
 
93
                        }
 
94
                }
 
95
 
 
96
                Command ConvertResultToCommand (MessageBoxResult dialogResult)
 
97
                {
 
98
                        switch (dialogResult) {
 
99
                        case MessageBoxResult.None:
 
100
                                return Command.No;
 
101
                        case MessageBoxResult.Cancel:
 
102
                                return Command.Cancel;
 
103
                        case MessageBoxResult.No:
 
104
                                return Command.No;
 
105
                        case MessageBoxResult.Yes:
 
106
                                return Command.Yes;
 
107
                        case MessageBoxResult.OK:
 
108
                                return Command.Ok;
 
109
                        default:
 
110
                                return Command.Cancel;
 
111
                        }
 
112
                }
 
113
 
 
114
                MessageBoxButton ConvertButtons (IList<Command> buttons)
 
115
                {
 
116
                        MessageBoxButton result;
 
117
 
 
118
                        switch (buttons.Count){
 
119
                        case 1:
 
120
                                if (buttons.Contains(Command.Ok)) {
 
121
                                        result = MessageBoxButton.OK;
 
122
                                } else {
 
123
                                        throw new NotImplementedException ();
 
124
                                }
 
125
                                break;
 
126
                        case 2:
 
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;
 
131
                                } else {
 
132
                                        throw new NotImplementedException ();
 
133
                                }
 
134
                                break;
 
135
                        case 3:
 
136
                                if (buttons.Contains (Command.Yes) && buttons.Contains (Command.No) && buttons.Contains (Command.Cancel)) {
 
137
                                        result = MessageBoxButton.YesNoCancel;
 
138
                                } else {
 
139
                                        throw new NotImplementedException ();
 
140
                                }
 
141
                                break;
 
142
                        default:
 
143
                                throw new NotImplementedException ();
 
144
                        }
 
145
 
 
146
                        return result;
 
147
                }
 
148
 
 
149
                public void Dispose ()
 
150
                {
 
151
                }
 
152
        }
 
153
}
 
 
b'\\ No newline at end of file'