-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathOutputWindowWriter.cs
More file actions
76 lines (65 loc) · 2.35 KB
/
Copy pathOutputWindowWriter.cs
File metadata and controls
76 lines (65 loc) · 2.35 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace ServiceStackVS.Common
{
public class OutputWindowWriter
{
private readonly IVsOutputWindowPane outputWindowPane;
private const string outputWindowPaneGuid = "5e5ab647-6a69-44a8-a2db-6a324b7b7e6d";
public OutputWindowWriter(string outputWindowPaneGuid, string outputWindowPaneName)
{
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
var outputWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
if (outputWindow == null) throw new Exception("Unable to create an output pane.");
var paneGuid = new Guid(outputWindowPaneGuid);
outputWindow.GetPane(ref paneGuid, out outputWindowPane);
if (outputWindowPane == null)
{
outputWindow.CreatePane(ref paneGuid, outputWindowPaneName, 1, 0);
outputWindow.GetPane(ref paneGuid, out outputWindowPane);
}
}
public void Show()
{
outputWindowPane.Activate();
}
public void ShowOutputPane(DTE2 dte)
{
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
var outputWindow = dte?.Windows?.Item("{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}");
if (outputWindow != null)
{
outputWindow.Visible = true;
}
}
private static OutputWindowWriter serviceStackOutputWindowWriter;
public static OutputWindowWriter WriterWindow
{
get
{
return serviceStackOutputWindowWriter ??
(serviceStackOutputWindowWriter = new OutputWindowWriter(outputWindowPaneGuid, "ServiceStackVS"));
}
}
public void Write(string format)
{
if (outputWindowPane == null || format == null) return;
outputWindowPane.OutputString(format);
}
public void WriteLine(string format)
{
Write(format + Environment.NewLine);
}
public void Clear()
{
outputWindowPane.Clear();
}
}
}