You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.8KB

  1. using Microsoft.VisualStudio.Shell;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Threading;
  5. using Task = System.Threading.Tasks.Task;
  6. namespace CommandFileContextMenu
  7. {
  8. /// <summary>
  9. /// This is the class that implements the package exposed by this assembly.
  10. /// </summary>
  11. /// <remarks>
  12. /// <para>
  13. /// The minimum requirement for a class to be considered a valid package for Visual Studio
  14. /// is to implement the IVsPackage interface and register itself with the shell.
  15. /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
  16. /// to do it: it derives from the Package class that provides the implementation of the
  17. /// IVsPackage interface and uses the registration attributes defined in the framework to
  18. /// register itself and its components with the shell. These attributes tell the pkgdef creation
  19. /// utility what data to put into .pkgdef file.
  20. /// </para>
  21. /// <para>
  22. /// To get loaded into VS, the package must be referred by &lt;Asset Type="Microsoft.VisualStudio.VsPackage" ...&gt; in .vsixmanifest file.
  23. /// </para>
  24. /// </remarks>
  25. [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
  26. [Guid(CommandFileContextMenuPackage.PackageGuidString)]
  27. [ProvideMenuResource("Menus.ctmenu", 1)]
  28. public sealed class CommandFileContextMenuPackage : AsyncPackage
  29. {
  30. /// <summary>
  31. /// CommandFileContextMenuPackage GUID string.
  32. /// </summary>
  33. public const string PackageGuidString = "e25b9b6b-6817-40c3-9d6e-7ced8a18f108";
  34. #region Package Members
  35. /// <summary>
  36. /// Initialization of the package; this method is called right after the package is sited, so this is the place
  37. /// where you can put all the initialization code that rely on services provided by VisualStudio.
  38. /// </summary>
  39. /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
  40. /// <param name="progress">A provider for progress updates.</param>
  41. /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
  42. protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
  43. {
  44. // When initialized asynchronously, the current thread may be a background thread at this point.
  45. // Do any initialization that requires the UI thread after switching to the UI thread.
  46. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
  47. Command1.Initialize(this);
  48. }
  49. #endregion
  50. }
  51. }