///////////////////////////////////////////////////////////////////////////// // Overriden Package Implementation #region Package Members /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initilaization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); //System.Diagnostics.Debugger.Break(); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = (IMenuCommandService)GetService(typeof(IMenuCommandService)); if (mcs != null) { // Create the command for the tool window var toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParser); var menuToolWin = new MenuCommand(JsParserMenuCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); // Create the command for the tool window toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParserFind); menuToolWin = new MenuCommand(JsParserMenuFindCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); } _jsParserService = new JsParserService(Settings.Default); var dte = (DTE)GetService(typeof(DTE)); Events events = dte.Events; _documentEvents = events.get_DocumentEvents(null); _solutionEvents = events.SolutionEvents; _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; if (VSVersionDetector.IsVs2012(dte.Version)) { //load .Net4.5 assembly dynamically because current project targeted as 4.0 for VS2010 compability var asm = Assembly.Load("JsParser.Package.2012"); var type = asm.GetType("JsParser.Package._2012.VS2012UIThemeProvider"); object serviceDelegate = new Func <Type, object>(GetService); _uiThemeProvider = (IUIThemeProvider)Activator.CreateInstance(type, serviceDelegate); } else { _uiThemeProvider = new VS2010UIThemeProvider(GetService); } _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () => { return(FindToolWindow <JsParserToolWindow>()); }); _uiThemeProvider.SubscribeToThemeChanged(() => { _jsParserToolWindowManager.NotifyColorChangeToToolWindow(); }); base.Initialize(); }
public JsParserToolWindowManager( JsParserService jsParserService, Func <IJsParserToolWindow> findWindowDelegate) { _jsParserService = jsParserService; _findWindowDelegate = findWindowDelegate; }
public JsParserToolWindowManager( JsParserService jsParserService, IUIThemeProvider uiThemeProvider, Func <IJsParserToolWindow> findWindowDelegate) { _jsParserService = jsParserService; _uiThemeProvider = uiThemeProvider; _findWindowDelegate = findWindowDelegate; }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); //System.Diagnostics.Debugger.Break(); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = (IMenuCommandService)GetService(typeof(IMenuCommandService)); if (mcs != null) { // Create the command for the tool window var toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParser); var menuToolWin = new MenuCommand(JsParserMenuCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); // Create the command for the tool window toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParserFind); menuToolWin = new MenuCommand(JsParserMenuFindCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); } _jsParserService = new JsParserService(Settings.Default); var dte = (DTE)GetService(typeof(DTE)); Events events = dte.Events; _documentEvents = events.get_DocumentEvents(null); _solutionEvents = events.SolutionEvents; _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, () => { return(FindToolWindow <JsParserToolWindow>()); }); base.Initialize(); }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (EnvDTE.AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object [] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName; try { //If you would like to move the command to a different menu, change the word "Tools" to the // English version of the menu. This code will take the culture, append on the name of the menu // then add the command to that menu. You can find a list of all the top-level menus in the file // CommandBar.resx. string resourceName; ResourceManager resourceManager = new ResourceManager("JsParser_AddIn.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID); if (cultureInfo.TwoLetterISOLanguageName == "zh") { System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent; resourceName = String.Concat(parentCultureInfo.Name, "Tools"); } else { resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"); } toolsMenuName = resourceManager.GetString(resourceName); } catch { //We tried to find a localized version of the word Tools, but one was not found. // Default to the en-US word, which may work for the current culture. toolsMenuName = "Tools"; } //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; //Find the Tools command bar on the MenuBar command bar: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, // just make sure you also update the QueryStatus/Exec method to include the new command names. try { //Add a command to the Commands collection: var comShow = commands.AddNamedCommand2(_addInInstance, "Show", "Javascript Parser", "Javascript Parser AddIn Show", true, 629, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a command to the Commands collection: var comFind = commands.AddNamedCommand2(_addInInstance, "Find", "Javascript Parser Find", "Javascript Parser AddIn 'Find' Feature", true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a control for the command to the tools menu: if (toolsPopup != null) { if (comShow != null) { comShow.AddControl(toolsPopup.CommandBar, 1); } if (comFind != null) { comFind.Bindings = "Text Editor::SHIFT+ALT+J"; comFind.AddControl(toolsPopup.CommandBar, 2); } } } catch (System.ArgumentException) { //If we are here, then the exception is probably because a command with that name // already exists. If so there is no need to recreate the command and we can // safely ignore the exception. } } //Subscribe to IDE events Events events = _applicationObject.Events; _documentEvents = events.get_DocumentEvents(null); _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; _uiThemeProvider = new DefaultUIThemeProvider(); _jsParserService = new JsParserService(Settings.Default); _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () => { return(EnsureWindowCreated()); }); }