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

UnitTestMarker.cs « TextMarker « MonoDevelop.SourceEditor « MonoDevelop.SourceEditor2 « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49c242cde91e2efe00e8349efc370d7ec142dbbc (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
using System;
using MonoDevelop.Ide.Editor;
using Mono.TextEditor;
using MonoDevelop.Core;
using MonoDevelop.Components;
using MonoDevelop.SourceEditor.Wrappers;

namespace MonoDevelop.SourceEditor
{
	class UnitTestMarker : MarginMarker, IUnitTestMarker
	{
		IDocumentLine ITextLineMarker.Line {
			get {
				return new DocumentLineWrapper (LineSegment);
			}
		}

		readonly UnitTestMarkerHost host;
		readonly UnitTestLocation unitTest;
		readonly ExtensibleTextEditor textEditor;

		UnitTestLocation IUnitTestMarker.UnitTest {
			get {
				return unitTest;
			}
		}

		void IUnitTestMarker.UpdateState ()
		{
			var line = LineSegment;
			if (line == null)
				return;
			textEditor.RedrawMarginLine (textEditor.ActionMargin, line.LineNumber); 
		}

		public UnitTestMarker (ExtensibleTextEditor textEditor, UnitTestMarkerHost host, UnitTestLocation unitTest)
		{
			if (textEditor == null)
				throw new ArgumentNullException ("textEditor");
			if (host == null)
				throw new ArgumentNullException ("host");
			this.textEditor = textEditor;
			this.host = host;
			this.unitTest = unitTest;
		}

		public override bool CanDrawForeground (Margin margin)
		{
			return margin is ActionMargin;
		}

		public override void InformMouseHover (Mono.TextEditor.MonoTextEditor editor, Margin margin, MarginMouseEventArgs args)
		{
			if (!(margin is ActionMargin))
				return;
			string toolTip;
			if (unitTest.IsFixture) {
				if (isFailed) {
					toolTip = GettextCatalog.GetString ("NUnit Fixture failed (click to run)");
					if (!string.IsNullOrEmpty (failMessage))
						toolTip += Environment.NewLine + failMessage.TrimEnd ();
				} else {
					toolTip = GettextCatalog.GetString ("NUnit Fixture (click to run)");
				}
			} else {
				if (isFailed) {
					toolTip = GettextCatalog.GetString ("NUnit Test failed (click to run)");
					if (!string.IsNullOrEmpty (failMessage))
						toolTip += Environment.NewLine + failMessage.TrimEnd ();
					foreach (var id in unitTest.TestCases) {
						if (host.IsFailure (unitTest.UnitTestIdentifier, id)) {
							var msg = host.GetMessage (unitTest.UnitTestIdentifier, id);
							if (!string.IsNullOrEmpty (msg)) {
								toolTip += Environment.NewLine + "Test" + id + ":";
								toolTip += Environment.NewLine + msg.TrimEnd ();
							}
						}
					}
				} else {
					toolTip = GettextCatalog.GetString ("NUnit Test (click to run)");
				}

			}
			editor.TooltipText = toolTip;
		}

//		static Menu menu;

		public override void InformMousePress (Mono.TextEditor.MonoTextEditor editor, Margin margin, MarginMouseEventArgs args)
		{
			if (!(margin is ActionMargin))
				return;
			host.PopupContextMenu (unitTest, (int)args.X, (int)args.Y);
			editor.TextArea.ResetMouseState (); 
		}

		bool isFailed;
		string failMessage;

		public override void DrawForeground (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
		{
			isFailed = false;
			bool searchCases = false;

			Xwt.Drawing.Image icon = host.GetStatusIcon (unitTest.UnitTestIdentifier);
			if (icon != null) {
				if (host.HasResult (unitTest.UnitTestIdentifier)) {
					searchCases = true;
				} else if (host.IsFailure (unitTest.UnitTestIdentifier)) {
					failMessage = host.GetMessage (unitTest.UnitTestIdentifier);
					isFailed = true;
				}
			} else {
				searchCases = true;
			}

			if (searchCases) {
				foreach (var caseId in unitTest.TestCases) {
					icon = host.GetStatusIcon (unitTest.UnitTestIdentifier, caseId);
					if (host.IsFailure (unitTest.UnitTestIdentifier, caseId)) {
						failMessage = host.GetMessage (unitTest.UnitTestIdentifier, caseId);
						isFailed = true;
						break;
					} 
				}
			}

			if (icon != null) {
				if (icon.Width > metrics.Width || icon.Height > metrics.Height)
					icon = icon.WithBoxSize (metrics.Width, metrics.Height);
				cr.DrawImage (editor, icon, Math.Truncate (metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate (metrics.Y + metrics.Height / 2 - icon.Height / 2));
			}
		}
	}
}