github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/visualstudio/dockerappvsix/CommandSelectApp.cs (about) 1 using System; 2 using System.ComponentModel.Design; 3 using System.Globalization; 4 using System.IO; 5 using System.Threading; 6 using System.Threading.Tasks; 7 using System.Windows.Forms; 8 using EnvDTE; 9 using Microsoft.VisualStudio.Shell; 10 using Microsoft.VisualStudio.Shell.Interop; 11 using Task = System.Threading.Tasks.Task; 12 13 namespace dockerappvsix 14 { 15 internal sealed class CommandSelectApp 16 { 17 public const int CommandId = 4129; 18 19 public static readonly Guid CommandSet = new Guid("0113e9de-ef33-4d36-9c72-75012c5afd35"); 20 21 private readonly AsyncPackage _package; 22 23 private CommandSelectApp(AsyncPackage package, OleMenuCommandService commandService) 24 { 25 _package = package ?? throw new ArgumentNullException(nameof(package)); 26 commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); 27 28 var menuCommandID = new CommandID(CommandSet, CommandId); 29 var menuItem = new MenuCommand(this.ExecuteAsync, menuCommandID); 30 commandService.AddCommand(menuItem); 31 } 32 33 public static CommandSelectApp Instance 34 { 35 get; 36 private set; 37 } 38 39 private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider 40 { 41 get 42 { 43 return this._package; 44 } 45 } 46 47 public static async Task InitializeAsync(AsyncPackage package) 48 { 49 // Verify the current thread is the UI thread - the call to AddCommand in CommandSelectApp's constructor requires 50 // the UI thread. 51 ThreadHelper.ThrowIfNotOnUIThread(); 52 53 OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; 54 Instance = new CommandSelectApp(package, commandService); 55 } 56 57 private async void ExecuteAsync(object sender, EventArgs e) 58 { 59 ThreadHelper.ThrowIfNotOnUIThread(); 60 DTE dte = await this._package.GetServiceAsync(typeof(DTE)) as DTE; 61 Globals g = dte.Solution.Globals; 62 string message; 63 OpenFileDialog file = new OpenFileDialog(); 64 file.Title = "Select Docker Application file or metadata file"; 65 if (file.ShowDialog() == DialogResult.OK) 66 { 67 string app = file.FileName; 68 string f = Path.GetFileName(app); 69 if (f == "docker-compose.yml" || f == "settings.yml" || f == "metadata.yml") 70 app = Path.GetDirectoryName(app); 71 message = "Docker Application set to " + app; 72 g["dockerapp_applocation"] = app; 73 } 74 else 75 { 76 message = "Docker Application unset"; 77 g["dockerapp_applocation"] = ""; 78 } 79 g.set_VariablePersists("dockerapp_applocation", true); 80 string title = "Docker Application selection"; 81 82 // Show a message box to prove we were here 83 VsShellUtilities.ShowMessageBox( 84 this._package, 85 message, 86 title, 87 OLEMSGICON.OLEMSGICON_INFO, 88 OLEMSGBUTTON.OLEMSGBUTTON_OK, 89 OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 90 } 91 } 92 }