Yes, the easiest way is to create a custom macro to handle your task (in VB).
Adding a Macro
First of all, choose Tools> Macros> Macros IDE (Alt + F11). To make everything clear, add a new module, for example, "ContextMenu", and paste the following code into it:
Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module ContextMenu Public Sub DoSomething() 'Few declarations' Dim SolutionExplorer As UIHierarchy Dim Item As UIHierarchyItem Dim SelectedItem As EnvDTE.ProjectItem 'Getting the solution explorer' SolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object() 'Iterating through all selected items' For Each Item In SolutionExplorer.SelectedItems 'Getting the item' SelectedItem = CType(Item.Object, EnvDTE.ProjectItem) 'Do some stuff here' If SelectedItem.FileNames(1).EndsWith("txt") Then MsgBox("We got the text file!", , SelectedItem.FileNames(1)) Else MsgBox("We got something else...", , SelectedItem.FileNames(1)) End If Next End Sub End Module
Of course, you must set up a way to handle the selected file names. For now, it will show a popup for each file, otherwise if it is a txt file.
Setting the context menu
The second task is to add a custom macro to the context menu; go to: Tools> Settings
Mark the context menus from the list on the "Toolbars" tab (a new toolbar with all context menus should appear in the main window) and go to the "Commands" tab. Now, from the context menu bar, select "Project and Solution Context Menus"> Item and drag the macro onto it from the "Commands" tab. Change its name / icon / button in the right-click menu.
Now you are ready to check and use it. Your newly added macro should appear in the Item context menu. Have fun!
source share