code_junkie

What is the easiest way to add a Visual Studio 2008 Context Menu Item?

Nov 11th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. Imports System
  2. Imports EnvDTE
  3. Imports EnvDTE80
  4. Imports EnvDTE90
  5. Imports System.Diagnostics
  6.  
  7. Public Module ContextMenu
  8.  
  9. Public Sub DoSomething()
  10. 'Few declarations'
  11. Dim SolutionExplorer As UIHierarchy
  12. Dim Item As UIHierarchyItem
  13. Dim SelectedItem As EnvDTE.ProjectItem
  14.  
  15. 'Getting the solution explorer'
  16. SolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
  17.  
  18. 'Iterating through all selected items'
  19. For Each Item In SolutionExplorer.SelectedItems
  20. 'Getting the item'
  21. SelectedItem = CType(Item.Object, EnvDTE.ProjectItem)
  22.  
  23. 'Do some stuff here'
  24. If SelectedItem.FileNames(1).EndsWith("txt") Then
  25. MsgBox("We got the text file!", , SelectedItem.FileNames(1))
  26. Else
  27. MsgBox("We got something else...", , SelectedItem.FileNames(1))
  28. End If
  29. Next
  30. End Sub
  31. End Module
Add Comment
Please, Sign In to add comment