1
/***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 This code is licensed under the Visual Studio SDK license terms.
5 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
10 ***************************************************************************/
12 // VsPkg.cs : Implementation of RdtExplorer
15 using System
.Diagnostics
;
16 using System
.Globalization
;
17 using System
.Runtime
.InteropServices
;
18 using System
.ComponentModel
.Design
;
19 using Microsoft
.Win32
;
20 using Microsoft
.VisualStudio
.Shell
.Interop
;
21 using Microsoft
.VisualStudio
.OLE
.Interop
;
22 using Microsoft
.VisualStudio
.Shell
;
24 namespace MyCompany
.RdtEventExplorer
27 /// This is the class that implements the package exposed by this assembly.
29 /// The minimum requirement for a class to be considered a valid package for Visual Studio
30 /// is to implement the IVsPackage interface and register itself with the shell.
31 /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
32 /// to do it: it derives from the Package class that provides the implementation of the
33 /// IVsPackage interface and uses the registration attributes defined in the framework to
34 /// register itself and its components with the shell.
36 // This attribute tells the registration utility (regpkg.exe) that this class needs
37 // to be registered as package.
38 [PackageRegistration(UseManagedResourcesOnly
= true)]
39 // A Visual Studio component can be registered under different regitry roots; for instance
40 // when you debug your package you want to register it in the experimental instance. This
41 // attribute specifies the registry root to use if no one is provided to regpkg.exe with
44 // This attribute is used to register the informations needed to show the this package
45 // in the Help/About dialog of Visual Studio.
46 [InstalledProductRegistration("#100", "#102", "1.0", IconResourceID
= 400)]
48 // This attribute is needed to let the shell know that this package exposes some menus.
49 [ProvideMenuResource(1000, 1)]
50 // This attribute registers a tool window exposed by this package.
51 [ProvideToolWindow(typeof(RdtEventWindowPane
))]
52 // This attribute registers a Tools/Options grid dialog page to set display options.
53 [ProvideOptionPage(typeof(RdtEventOptionsDialog
), "RDT Event Explorer", "Explorer Options", 0, 0, true)]
54 [Guid(GuidsList
.guidRdtEventExplorerPkgString
)]
55 public sealed class RdtEventExplorerPkg
: Package
57 // Cache the Menu Command Service since we will use it multiple times
58 private OleMenuCommandService menuService
;
60 const int bitmapResourceID
= 300;
63 /// Default constructor of the package.
64 /// Inside this method you can place any initialization code that does not require
65 /// any Visual Studio service because at this point the package object is created but
66 /// not sited yet inside Visual Studio environment. The place to do all the other
67 /// initialization is the Initialize method.
69 public RdtEventExplorerPkg()
74 /// This function is called when the user clicks the menu item that shows the
75 /// tool window. See the Initialize method to see how the menu item is associated to
76 /// this function using the OleMenuCommandService service and the MenuCommand class.
78 private void ShowToolWindow(object sender
, EventArgs e
)
80 // Get the instance number 0 of this tool window. This window is single instance so this instance
81 // is actually the only one.
82 // The last flag is set to true so that if the tool window does not exists it will be created.
83 ToolWindowPane window
= this.FindToolWindow(typeof(RdtEventWindowPane
), 0, true);
84 if ((null == window
) || (null == window
.Frame
))
86 throw new COMException(Resources
.CanNotCreateWindow
);
88 IVsWindowFrame windowFrame
= (IVsWindowFrame
)window
.Frame
;
89 Microsoft
.VisualStudio
.ErrorHandler
.ThrowOnFailure(windowFrame
.Show());
92 /////////////////////////////////////////////////////////////////////////////
93 // Overriden Package Implementation
94 #region Package Members
97 /// Initialization of the package; this method is called right after the package is sited, so this is the place
98 /// where you can put all the initilaization code that rely on services provided by VisualStudio.
100 protected override void Initialize()
104 // Add our command handlers for menu (commands must exist in the .vsct file)
105 OleMenuCommandService mcs
= GetService(typeof(IMenuCommandService
)) as OleMenuCommandService
;
108 // Create the command for the tool window
109 CommandID toolwndCommandID
= new CommandID(GuidsList
.guidRdtEventExplorerCmdSet
, (int)PkgCmdIDList
.cmdidMyTool
);
110 MenuCommand menuToolWin
= new MenuCommand( new EventHandler(ShowToolWindow
), toolwndCommandID
);
111 mcs
.AddCommand( menuToolWin
);
114 //// Add a global service to provide a single set of options.
115 //((IServiceContainer)this).AddService(typeof(SMyOptionsService), this, true);
117 //// Now that we have the service, we can use it to initialize options.
118 //// At this point options is null, so we will initialize it from the registry.
119 //GetRdtEventOptions();
123 /// Define a command handler.
124 /// When the user press the button corresponding to the CommandID
125 /// the EventHandler will be called.
127 /// <param name="id">The CommandID (Guid/ID pair) as defined in the .vsct file</param>
128 /// <param name="handler">Method that should be called to implement the command</param>
129 /// <returns>The menu command. This can be used to set parameter such as the default visibility once the package is loaded</returns>
130 internal OleMenuCommand
DefineCommandHandler(EventHandler handler
, CommandID id
)
132 // if the package is zombied, we don't want to add commands
136 // Make sure we have the service
137 if (menuService
== null)
139 // Get the OleCommandService object provided by the MPF; this object is the one
140 // responsible for handling the collection of commands implemented by the package.
141 menuService
= GetService(typeof(IMenuCommandService
)) as OleMenuCommandService
;
143 OleMenuCommand command
= null;
144 if (null != menuService
)
146 // Add the command handler
147 command
= new OleMenuCommand(handler
, id
);
148 menuService
.AddCommand(command
);