Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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