AddonComponentButton.cs
1 using System;
2 using System.ComponentModel.Design;
3 using System.Globalization;
4 using Microsoft.VisualStudio.Shell;
5 using Microsoft.VisualStudio.Shell.Interop;
6 using EnvDTE80;
7 using EnvDTE;
8 
9 namespace sage.addons.components
10 {
14  internal sealed class AddonComponentButton
15  {
19  public const int CommandId = 0x0100;
20 
24  public static readonly Guid CommandSet = new Guid("fbd92ea9-29f2-411c-8088-b0b2189e19d5");
25 
29  private readonly Package package;
30 
36  private AddonComponentButton(Package package)
37  {
38  if (package == null)
39  {
40  throw new ArgumentNullException("package");
41  }
42 
43  this.package = package;
44 
45  OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
46  if (commandService != null)
47  {
48  var menuCommandID = new CommandID(CommandSet, CommandId);
49  var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
50  commandService.AddCommand(menuItem);
51  }
52  }
53 
57  public static AddonComponentButton Instance
58  {
59  get;
60  private set;
61  }
62 
66  private IServiceProvider ServiceProvider
67  {
68  get
69  {
70  return this.package;
71  }
72  }
73 
78  public static void Initialize(Package package)
79  {
80  Instance = new AddonComponentButton(package);
81  }
82 
90  private void MenuItemCallback(object sender, EventArgs e)
91  {
92  Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
93 
94  DTE2 dte = (DTE2)Instance.ServiceProvider.GetService(typeof(DTE));
95 
96  // Creamos la instancia y le pasamos las propiedades
97  AddonsExecute addonsExecute = new AddonsExecute();
98  addonsExecute.Execute(dte, "Manteniment");
99  }
100  }
101 }
Funciones y métodos para crear los componentes
void Execute(DTE2 dte, string commandName)
Executes the assistant