source: trunk/tools/vslol/VsLol.cs @ 2354

Last change on this file since 2354 was 2123, checked in by sam, 8 years ago

vslol: add licensing information to important files.

File size: 5.3 KB
Line 
1//
2// Lol Engine - VsLol add-in for Visual Studio
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11using System;
12using System.ComponentModel.Design;
13using System.Diagnostics;
14using System.Globalization;
15using System.Runtime.InteropServices;
16using System.Security.Permissions;
17using System.Text;
18using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
19using Microsoft.VisualStudio.Shell;
20using Microsoft.VisualStudio.Shell.Interop;
21
22namespace lol
23{
24
25[PackageRegistration(UseManagedResourcesOnly = true)]
26
27/* LolFx syntax highlighting */
28[ProvideServiceAttribute(typeof(LolFxLanguageService),
29                         ServiceName = "LolFx Service")]
30[ProvideLanguageServiceAttribute(typeof(LolFxLanguageService),
31                                 "LolFx", 106 /* resource ID */,
32                                 CodeSense = true,
33                                 RequestStockColors = true,
34                                 EnableCommenting = true,
35                                 EnableAsyncCompletion = true)]
36[ProvideLanguageExtensionAttribute(typeof(LolFxLanguageService),
37                                   ".lolfx")]
38
39[ProvideMenuResource(1000, 1)]
40[Guid("f96f7ac5-16ac-4061-8b92-0a02bb455ae9")]
41[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
42[ComVisible(true)]
43
44/* Autoload package */
45[ProvideAutoLoad("f1536ef8-92ec-443c-9ed7-fdadf150da82")]
46
47public sealed class PluginPackage : Package
48{
49    public PluginPackage()
50    {
51        Trace.WriteLine(String.Format("Entering constructor for: {0}", this.ToString()));
52    }
53
54    [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
55    protected override void Initialize()
56    {
57        // Trace the beginning of this method and call the base implementation.
58        Trace.WriteLine(String.Format("Entering Initialize() of: {0}", this.ToString()));
59        base.Initialize();
60
61        Logger.Initialize(GetService(typeof(SVsOutputWindow)) as IVsOutputWindow);
62
63        /* Register the "Generate Compilers" context menu */
64        OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
65        if (null != mcs)
66        {
67            CommandID id = new CommandID(GuidsList.guidVsLolCmdSet,
68                                         VsLolIDList.cmdidGenerateCompilers);
69            OleMenuCommand command = new MenuGenerateCompilers(new ServiceProvider((IOleServiceProvider)this.GetService(typeof(IOleServiceProvider))), id);
70            mcs.AddCommand(command);
71        }
72
73        /* Register the LolFx language service */
74        IServiceContainer serviceContainer = this as IServiceContainer;
75        LolFxLanguageService lolfxserv = new LolFxLanguageService();
76        lolfxserv.SetSite(this);
77        serviceContainer.AddService(typeof(LolFxLanguageService),
78                                    lolfxserv, true);
79    }
80}
81
82internal static class Logger
83{
84    public static void Initialize(IVsOutputWindow window)
85    {
86        m_window = window;
87
88        OpenBuildPane();
89
90        if (m_pane == null)
91            Trace.WriteLine("Failed to get a reference to the Output window Build pane");
92    }
93
94    private static void OpenBuildPane()
95    {
96        /* Ensure the "Build" output pane exists */
97        if (m_window != null)
98        {
99            Guid guidBuild = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid;
100            m_window.CreatePane(guidBuild, "Build", 1, 0);
101
102            if (Microsoft.VisualStudio.ErrorHandler.Failed(m_window.GetPane(ref guidBuild, out m_pane)))
103                m_pane = null;
104        }
105
106        if (m_pane != null)
107            m_pane.Activate();
108    }
109
110    public static void Clear()
111    {
112        OpenBuildPane();
113
114        if (m_pane == null)
115        {
116            m_backlog = "";
117            return;
118        }
119
120        m_pane.Clear();
121    }
122
123    public static void Info(string s)
124    {
125        OpenBuildPane();
126
127        if (m_pane == null)
128        {
129            m_backlog += s;
130            return;
131        }
132
133        m_pane.OutputString(m_backlog);
134        m_backlog = "";
135        m_pane.OutputString(s);
136    }
137
138    private static IVsOutputWindow m_window = null;
139    private static IVsOutputWindowPane m_pane = null;
140    private static string m_backlog = "";
141}
142
143internal static class GuidsList
144{
145    // Now define the list of guids as public static members.
146    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
147    public static readonly Guid guidVsLolPkg = new Guid("{f96f7ac5-16ac-4061-8b92-0a02bb455ae9}");
148
149    public static readonly Guid guidVsLolCmdSet = new Guid("{ce508d12-530e-45d0-8b52-1e9ee3f8eaaf}");
150
151    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
152    public static readonly Guid guidGearBmp = new Guid("{560dba06-c26b-4731-8229-b816818e5992}");
153}
154
155internal static class VsLolIDList
156{
157    public const int cmdidGenerateCompilers = 0x2001;
158    public const int cmdidUnused1 = 0x2002;
159    public const int cmdidUnused2 = 0x2003;
160}
161
162} /* namespace lol */
Note: See TracBrowser for help on using the repository browser.