github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/visualstudio/dockerappvsix/CommandSettings.cs (about)

     1  using System;
     2  using System.ComponentModel.Design;
     3  using System.Globalization;
     4  using System.Threading;
     5  using System.Threading.Tasks;
     6  using Microsoft.VisualStudio.Shell;
     7  using Microsoft.VisualStudio.Shell.Interop;
     8  using Task = System.Threading.Tasks.Task;
     9  using Microsoft.VisualStudio.PlatformUI;
    10  using System.Windows.Controls;
    11  using EnvDTE;
    12  
    13  namespace dockerappvsix
    14  {
    15      
    16  
    17      internal sealed class CommandSettings
    18      {
    19  
    20          public const int CommandId = 4130;
    21  
    22  
    23          public static readonly Guid CommandSet = new Guid("0113e9de-ef33-4d36-9c72-75012c5afd35");
    24  
    25  
    26          private readonly AsyncPackage _package;
    27          
    28          private CommandSettings(AsyncPackage package, OleMenuCommandService commandService)
    29          {
    30              _package = package ?? throw new ArgumentNullException(nameof(package));
    31              commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
    32  
    33              var menuCommandID = new CommandID(CommandSet, CommandId);
    34              var menuItem = new MenuCommand(this.ExecuteAsync, menuCommandID);
    35              commandService.AddCommand(menuItem);
    36          }
    37          
    38          public static CommandSettings Instance
    39          {
    40              get;
    41              private set;
    42          }
    43          
    44          private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
    45          {
    46              get
    47              {
    48                  return this._package;
    49              }
    50          }
    51  
    52          public static async Task InitializeAsync(AsyncPackage package)
    53          {
    54              // Verify the current thread is the UI thread - the call to AddCommand in CommandSettings's constructor requires
    55              // the UI thread.
    56              ThreadHelper.ThrowIfNotOnUIThread();
    57  
    58              OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
    59              Instance = new CommandSettings(package, commandService);
    60          }
    61          
    62          private async void ExecuteAsync(object sender, EventArgs e)
    63          {
    64              ThreadHelper.ThrowIfNotOnUIThread();
    65              DTE dte = await this._package.GetServiceAsync(typeof(DTE)) as DTE;
    66              Globals g = dte.Solution.Globals;
    67              SettingsDialog sd = new SettingsDialog();
    68              sd.Settings.LoadFromSolution(g);
    69              if (sd.ShowDialog() ?? false) {
    70                  sd.Settings.Save(g);
    71              }
    72          }
    73      }
    74  }