| < Free Open Study > |
|
Many times you will make changes to a component and then, before you save the changes, determine that you would like to reload the component from its original state in order to cancel the changes. It may be that the changes are too numerous or complex, in the case of a form, and you just want to restore the module, class, or form without having to unload and reload the project. The following macro command will do that for you. Make sure the component that you want to reload is the active window. When the window prompts you to save the changes, click the No button.
Sub ReloadComponent() Dim projs As System.Array Dim proj As Project Dim sln As String = DTE.Solution.Item(1).Name Dim pn As String Dim s As String Dim s2 As String = DTE.ActiveDocument.FullName Dim awn As String = DTE.ActiveDocument.Name projs = DTE.ActiveSolutionProjects() proj = CType(projs.GetValue(0), EnvDTE.Project) pn = proj.Name s = sln & "\" & pn & "\" & awn DTE.Windows.Item(Constants. vsWindowKindSolutionExplorer).Activate() DTE.ActiveWindow.Object.GetItem(s) .Select(vsUISelectionType. vsUISelectionTypeSelect) DTE.ExecuteCommand("Project.ExcludeFromProjaect") System.Windows.Forms.Application.DoEvents() DTE.Windows.Item(Constants. vsWindowKindSolutionExplorer).Activate() System.Windows.Forms.Application.DoEvents() DTE.ItemOperations.AddExistingItem(s2) DTE.Windows.Item(Constants. vsWindowKindSolutionExplorer).Activate() DTE.ActiveWindow.Object.GetItem(s). Select(vsUISelectionType. vsUISelectionTypeSelect) DTE.ActiveWindow.Object.DoDefaultAction() End Sub
| < Free Open Study > |
|