選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

89 行
2.4KB

  1. using System;
  2. using System.ComponentModel.Design;
  3. using System.Globalization;
  4. using Microsoft.VisualStudio.Shell;
  5. using Microsoft.VisualStudio.Shell.Interop;
  6. namespace CommandFileContextMenu
  7. {
  8. internal sealed class Command1
  9. {
  10. public const int CommandId = 0x0100;
  11. public static readonly Guid CommandSet = new Guid("b394839a-d886-44d2-94c9-ffeeb48d97d5");
  12. private readonly Package package;
  13. private Command1(Package package)
  14. {
  15. if (package == null)
  16. {
  17. throw new ArgumentNullException("package");
  18. }
  19. this.package = package;
  20. OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
  21. if (commandService != null)
  22. {
  23. var menuCommandID = new CommandID(CommandSet, CommandId);
  24. var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
  25. commandService.AddCommand(menuItem);
  26. }
  27. }
  28. public static Command1 Instance
  29. {
  30. get;
  31. private set;
  32. }
  33. private IServiceProvider ServiceProvider
  34. {
  35. get
  36. {
  37. return this.package;
  38. }
  39. }
  40. public static void Initialize(Package package)
  41. {
  42. Instance = new Command1(package);
  43. }
  44. private void MenuItemCallback(object sender, EventArgs e)
  45. {
  46. string message;
  47. string title = "Ajouter à SVN";
  48. EnvDTE.DTE dte;
  49. EnvDTE.SelectedItems selectedItems;
  50. EnvDTE.ProjectItem projectItem;
  51. dte = (EnvDTE.DTE)this.ServiceProvider.GetService(typeof(EnvDTE.DTE));
  52. selectedItems = dte.SelectedItems;
  53. if (selectedItems != null)
  54. {
  55. foreach (EnvDTE.SelectedItem selectedItem in selectedItems)
  56. {
  57. projectItem = selectedItem.ProjectItem as EnvDTE.ProjectItem;
  58. if (projectItem != null)
  59. {
  60. message = $"Called on {projectItem.Name}";
  61. // Show a message box to prove we were here
  62. VsShellUtilities.ShowMessageBox(
  63. this.ServiceProvider,
  64. message,
  65. title,
  66. OLEMSGICON.OLEMSGICON_INFO,
  67. OLEMSGBUTTON.OLEMSGBUTTON_OK,
  68. OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }