* TreeView.cs: Don't draw the selected node when we lose
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThreadExceptionDialog.cs
1 //
2 // System.Windows.Forms.ThreadExceptionDialog.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Authors:
24 //              Marek Safar     marek.safar@seznam.cz
25 //
26 // Copyright (C) Novell Inc., 2004
27
28 // COMPLETE - BUT DISABLED TEXTBOX
29
30 using System;
31 using System.Text;
32 using System.Reflection;
33
34 namespace System.Windows.Forms
35 {
36         public class ThreadExceptionDialog: Form
37         {
38                 Exception e;
39                 bool details;
40
41                 private System.Windows.Forms.Button buttonIgnore;
42                 private System.Windows.Forms.Button buttonAbort;
43                 private System.Windows.Forms.Button buttonDetails;
44                 private System.Windows.Forms.Label labelException;
45                 private System.Windows.Forms.Label label1;
46                 private System.Windows.Forms.TextBox textBoxDetails;
47                 private System.Windows.Forms.Label helpText;
48
49                 private void InitializeComponent()
50                 {
51                         this.helpText = new System.Windows.Forms.Label();
52                         this.buttonAbort = new System.Windows.Forms.Button();
53                         this.buttonIgnore = new System.Windows.Forms.Button();
54                         this.buttonDetails = new System.Windows.Forms.Button();
55                         this.labelException = new System.Windows.Forms.Label();
56                         this.textBoxDetails = new System.Windows.Forms.TextBox();
57                         this.label1 = new System.Windows.Forms.Label();
58                         this.SuspendLayout();
59                         // 
60                         // helpText
61                         // 
62                         this.helpText.Location = new System.Drawing.Point(60, 8);
63                         this.helpText.Name = "helpText";
64                         this.helpText.Size = new System.Drawing.Size(356, 40);
65                         this.helpText.TabIndex = 0;
66                         this.helpText.Text = "An unhandled exception has occurred in you application. If you click Ignore the a" +
67                                 "pplication will ignore this error and attempt to continue. If you click Abort, t" +
68                                 "he application will quit immediately.";
69                         // 
70                         // buttonAbort
71                         // 
72                         this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
73                         this.buttonAbort.Location = new System.Drawing.Point(332, 112);
74                         this.buttonAbort.Name = "buttonAbort";
75                         this.buttonAbort.Size = new System.Drawing.Size(85, 23);
76                         this.buttonAbort.TabIndex = 4;
77                         this.buttonAbort.Text = "&Abort";
78                         this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
79                         // 
80                         // buttonIgnore
81                         // 
82                         this.buttonIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
83                         this.buttonIgnore.Location = new System.Drawing.Point(236, 112);
84                         this.buttonIgnore.Name = "buttonIgnore";
85                         this.buttonIgnore.Size = new System.Drawing.Size(85, 23);
86                         this.buttonIgnore.TabIndex = 3;
87                         this.buttonIgnore.Text = "&Ignore";
88                         // 
89                         // buttonDetails
90                         // 
91                         this.buttonDetails.Location = new System.Drawing.Point(140, 112);
92                         this.buttonDetails.Name = "buttonDetails";
93                         this.buttonDetails.Size = new System.Drawing.Size(85, 23);
94                         this.buttonDetails.TabIndex = 2;
95                         this.buttonDetails.Text = "Show &Details";
96                         this.buttonDetails.Click += new System.EventHandler(this.buttonDetails_Click);
97                         // 
98                         // labelException
99                         // 
100                         this.labelException.Location = new System.Drawing.Point(60, 64);
101                         this.labelException.Name = "labelException";
102                         this.labelException.Size = new System.Drawing.Size(356, 32);
103                         this.labelException.TabIndex = 1;
104                         // 
105                         // textBoxDetails
106                         // 
107                         this.textBoxDetails.Location = new System.Drawing.Point(8, 168);
108                         this.textBoxDetails.Multiline = true;
109                         this.textBoxDetails.Name = "textBoxDetails";
110                         this.textBoxDetails.ReadOnly = true;
111                         this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Both;
112                         this.textBoxDetails.Size = new System.Drawing.Size(408, 196);
113                         this.textBoxDetails.TabIndex = 5;
114                         this.textBoxDetails.TabStop = false;
115                         this.textBoxDetails.Text = "";
116                         this.textBoxDetails.WordWrap = false;
117                         // 
118                         // label1
119                         // 
120                         this.label1.Location = new System.Drawing.Point(8, 148);
121                         this.label1.Name = "label1";
122                         this.label1.Size = new System.Drawing.Size(100, 16);
123                         this.label1.TabIndex = 0;
124                         this.label1.Text = "Exception details";
125                         // 
126                         // ThreadExceptionDialog
127                         // 
128                         this.AcceptButton = this.buttonIgnore;
129                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
130                         this.CancelButton = this.buttonAbort;
131                         this.ClientSize = new System.Drawing.Size(428, 374);
132                         this.Controls.Add(this.label1);
133                         this.Controls.Add(this.textBoxDetails);
134                         this.Controls.Add(this.labelException);
135                         this.Controls.Add(this.buttonDetails);
136                         this.Controls.Add(this.buttonIgnore);
137                         this.Controls.Add(this.buttonAbort);
138                         this.Controls.Add(this.helpText);
139                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
140                         this.MaximizeBox = false;
141                         this.MinimizeBox = false;
142                         this.Name = "ThreadExceptionDialog";
143                         this.ShowInTaskbar = false;
144                         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
145                         this.TopMost = true;
146                         this.ResumeLayout(false);
147                 }
148         
149                 public ThreadExceptionDialog (Exception e)
150                 {
151                         this.e = e;
152                         InitializeComponent ();
153
154                         this.labelException.Text = e.Message;
155                         if (Form.ActiveForm != null)
156                                 this.Text = Form.ActiveForm.Text;
157                         else
158                                 this.Text = "Mono";
159                         this.buttonAbort.Enabled = Application.AllowQuit;
160                         RefreshDetails ();
161                         FillExceptionDetails ();
162                 }
163
164                 void buttonDetails_Click(object sender, System.EventArgs e)
165                 {
166                         details = !details;
167                         RefreshDetails ();
168                 }
169
170                 void FillExceptionDetails ()
171                 {
172                         StringBuilder sb = new StringBuilder ();
173                         sb.Append (e.ToString ());
174                         sb.Append (Environment.NewLine + Environment.NewLine);
175                         sb.Append ("Loaded assemblies:" + Environment.NewLine + Environment.NewLine);
176
177                         foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
178                                 AssemblyName an = a.GetName ();
179                                 sb.AppendFormat ("Name:\t{0}" + Environment.NewLine, an.Name);
180                                 sb.AppendFormat ("Version:\t{0}" + Environment.NewLine, an.Version);
181                                 sb.AppendFormat ("Location:\t{0}" + Environment.NewLine, an.CodeBase);
182                                 sb.Append (Environment.NewLine);
183                         }
184                         textBoxDetails.Text = sb.ToString ();
185                 }
186
187                 void RefreshDetails ()
188                 {
189                         if (details) {
190                                 buttonDetails.Text = "Hide &Details";
191                                 Height = 410;
192                                 return;
193                         }
194                         buttonDetails.Text = "Show &Details";
195                         Height = 180;
196                 }
197
198                 void buttonAbort_Click(object sender, System.EventArgs e)
199                 {
200                         Application.Exit ();
201                 }
202         }
203 }