Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MultiTaskDialogProgressMonitor.cs « MonoDevelop.Ide.ProgressMonitoring « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac66b89aef2731a0829f8e1fc8829c89020218af (plain)
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
// MultiTaskDialogProgressMonitor.cs: IProgressMonitor for displaying the 
//    progress of multiple tasks in a dialog. N.B. Much of this code for this 
//    dialog is adapted from MessageDialogProgressMonitor.cs
// 
// Author:
//   Michael Hutchinson <mhutchinson@novell.com>
// 
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;

using MonoDevelop.Core;
using MonoDevelop.Core.ProgressMonitoring;
using MonoDevelop.Ide.Gui.Dialogs;
using MonoDevelop.Ide.Gui;

namespace MonoDevelop.Ide.ProgressMonitoring
{
	
	
	public class MultiTaskDialogProgressMonitor : ProgressMonitor 
	{
		StringCollection errorsMessages = new StringCollection ();
		StringCollection warningMessages = new StringCollection ();
		Exception errorException;
		MultiTaskProgressDialog dialog;
		bool showDetails;
		
		public MultiTaskDialogProgressMonitor (): this (true)
		{
		}
		
		public MultiTaskDialogProgressMonitor (bool showProgress): this (showProgress, true, true)
		{
		}
		
		public MultiTaskDialogProgressMonitor (bool showProgress, bool allowCancel): this (showProgress, allowCancel, true)
		{
		}
		
		public MultiTaskDialogProgressMonitor (bool showProgress, bool allowCancel, bool showDetails)
			: this (showProgress, allowCancel, showDetails, null)
		{
		}
		
		public MultiTaskDialogProgressMonitor (bool showProgress, bool allowCancel, bool showDetails, IDictionary<string, string> taskLabelAliases)
		{
			if (showProgress) {
				var parent = MessageService.GetDefaultModalParent ();
				dialog = new MultiTaskProgressDialog (allowCancel, showDetails, taskLabelAliases) {
					DestroyWithParent = true,
					Modal = true,
					TransientFor = parent,
				};
				MessageService.PlaceDialog (dialog, parent);
				Mono.TextEditor.GtkWorkarounds.PresentWindowWithNotification (dialog);
				dialog.CancellationTokenSource = CancellationTokenSource;
				DispatchService.RunPendingEvents ();
				this.showDetails = showDetails;
			}
		}
		
		[AsyncDispatch]
		public void SetDialogTitle (string title)
		{
			if (dialog != null && !string.IsNullOrEmpty (title))
				dialog.Title = title;
		}
		
		[AsyncDispatch]
		public void SetOperationTitle (string title)
		{
			if (dialog != null && !string.IsNullOrEmpty (title))
				dialog.OperationTitle = title;
		}
		
		protected override void OnWriteLog (string text)
		{
			if (dialog != null) {
				dialog.WriteText (text);
				DispatchService.RunPendingEvents ();
			}
		}
		
		protected override void OnProgressChanged ()
		{
			if (dialog != null) {
				dialog.SetProgress (Progress);
				DispatchService.RunPendingEvents ();
			}
		}
		
		protected override void OnBeginTask (string name, int totalWork, int stepWork)
		{
			if (dialog != null) {
				dialog.BeginTask (name);
			}
			base.OnBeginTask (name, totalWork, stepWork);
		}

		protected override void OnEndTask (string name, int totalWork, int stepWork)
		{
			if (dialog != null) {
				dialog.EndTask ();
			}
			DispatchService.RunPendingEvents ();
			base.OnEndTask (name, totalWork, stepWork);
		}

		protected override void OnWarningReported (string message)
		{
			if (dialog != null) {
				dialog.WriteText (GettextCatalog.GetString ("WARNING: ") + message + "\n");
				DispatchService.RunPendingEvents ();
			}
			warningMessages.Add (message);
			base.OnWarningReported (message);
		}

		protected override void OnErrorReported (string message, Exception ex)
		{
			if (message == null && ex != null)
				message = ex.Message;
			else if (message != null && ex != null) {
				if (!message.EndsWith (".")) message += ".";
				message += " " + ex.Message;
			}

			errorsMessages.Add (message);
			if (ex != null) {
				LoggingService.LogError (ex.ToString ());
				errorException = ex;
			}

			if (dialog != null) {
				dialog.WriteText (GettextCatalog.GetString ("ERROR: ") + message + "\n");
				DispatchService.RunPendingEvents ();
			}
			base.OnErrorReported (message, ex);
		}
		
		protected override void OnCompleted ()
		{
			DispatchService.GuiDispatch (ShowDialogs);
			base.OnCompleted ();
		}
		
		void ShowDialogs ()
		{
			if (dialog != null) {
				dialog.AllDone ();
			}
			
			if (showDetails)
				return;
			
			if (errorsMessages.Count > 0) {
				string s = "";
				foreach (string m in errorsMessages)
					s += m + "\n";
				MessageService.ShowError (s, errorException);
			}
			
			if (warningMessages.Count > 0) {
				string s = "";
				foreach (string m in warningMessages)
					s += m + "\n";
				MessageService.ShowWarning (s);
			}
		}
	}
}