/// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary> //public Connect() //{ //} /// <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 = (AddIn)addInInst; // Only execute the startup code if the connection mode is a startup mode //if( connectMode == ext_ConnectMode.ext_cm_UISetup ) { if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { //Initializing Context Context.ApplicationObject = applicationObject; Context.AddInInstance = addInInstance; //Initializing EventSinks SolutionEventSink solutionEventSink = new SolutionEventSink(); addinEventSink = new AddinEventSink(); //Initializing Controller controller = new UIController(); controller.Sinks.Add(solutionEventSink); controller.Sinks.Add(addinEventSink); controller.Init(solutionEventSink, addinEventSink); addinEventSink.OnStartup(applicationObject); if (Context.ApplicationObject.Solution.IsOpen) { solutionEventSink.OnOpenSolution(); } } }
/// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary> //public Connect() //{ //} /// <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 = (AddIn) addInInst; // Only execute the startup code if the connection mode is a startup mode //if( connectMode == ext_ConnectMode.ext_cm_UISetup ) { if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { //Initializing Context Context.ApplicationObject = applicationObject; Context.AddInInstance = addInInstance; //Initializing EventSinks SolutionEventSink solutionEventSink = new SolutionEventSink(); addinEventSink = new AddinEventSink(); //Initializing Controller controller = new UIController(); controller.Sinks.Add(solutionEventSink); controller.Sinks.Add(addinEventSink); controller.Init(solutionEventSink, addinEventSink); addinEventSink.OnStartup(applicationObject); if (Context.ApplicationObject.Solution.IsOpen){ solutionEventSink.OnOpenSolution(); } } }
/// <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())); // base.Initialize(); // // // Add our command handlers for menu (commands must exist in the .vsct file) // OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; // if ( null != mcs ) // { // // Create the command for the menu item. // CommandID menuCommandID = new CommandID(GuidList.guidJiraEditorLinksCmdSet, (int)PkgCmdIDList.cmdidMyCommand); // MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID ); // mcs.AddCommand( menuItem ); // } JiraLinkMarkerTypeProvider markerTypeProvider = new JiraLinkMarkerTypeProvider(); ((IServiceContainer)this).AddService(markerTypeProvider.GetType(), markerTypeProvider, true); base.Initialize(); // Now it's time to initialize our copies of the marker IDs. We need them to be // able to create marker instances. JiraLinkMarkerTypeProvider.InitializeMarkerIds(this); // Advise event sinks. We need to know when a solution is opened and closed // (SolutionEventSink), when a document is opened and closed (TextManagerEventSink), // and when a document is saved (RunningDocTableEventSink). SolutionEventSink solutionEventSink = new SolutionEventSink(); TextManagerEventSink textManagerEventSink = new TextManagerEventSink(); RunningDocTableEventSink runningDocTableEventSink = new RunningDocTableEventSink(); IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(solutionEventSink, out solutionEventCookie)); IConnectionPointContainer textManager = (IConnectionPointContainer)GetService(typeof(SVsTextManager)); Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID; textManager.FindConnectionPoint(ref interfaceGuid, out tmConnectionPoint); tmConnectionPoint.Advise(textManagerEventSink, out tmConnectionCookie); IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable)); ErrorHandler.ThrowOnFailure(rdt.AdviseRunningDocTableEvents(runningDocTableEventSink, out rdtEventCookie)); // Since we register custom text markers we have to ensure the font and color // cache is up-to-date. ValidateFontAndColorCacheManagerIsUpToDate(); }
protected override void Initialize() { PlvsLogger.log("plvsPackage.Initialize() - enter"); base.Initialize(); if (InCommandLineMode) { return; } installCrashHandler(); ProxyListener.Instance.init(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // toggle tool window command CommandID menuCommandId = new CommandID(GuidList.guidplvsCmdSet, (int)PkgCmdIDList.cmdidToggleToolWindow); OleMenuCommand menuItem = new OleMenuCommand(toggleToolWindowMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += toggleToolWindow_BeforeQueryStatus; mcs.AddCommand(menuItem); // find issue command menuCommandId = new CommandID(GuidList.guidplvsCmdSet, (int)PkgCmdIDList.cmdidFindIssue); menuItem = new OleMenuCommand(findIssueMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += toolWindowCommand_BeforeQueryStatus; mcs.AddCommand(menuItem); // create issue command menuCommandId = new CommandID(GuidList.guidplvsCmdSet, (int)PkgCmdIDList.cmdidCreateIssue); menuItem = new OleMenuCommand(createIssueMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += toolWindowCommand_BeforeQueryStatus; mcs.AddCommand(menuItem); // project properties command menuCommandId = new CommandID(GuidList.guidplvsCmdSet, (int)PkgCmdIDList.cmdidProjectProperties); menuItem = new OleMenuCommand(projectPropertiesMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += toolWindowCommand_BeforeQueryStatus; mcs.AddCommand(menuItem); // global properties command menuCommandId = new CommandID(GuidList.guidplvsCmdSet, (int)PkgCmdIDList.cmdidGlobalProperties); menuItem = new OleMenuCommand(globalPropertiesMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += toolWindowCommand_BeforeQueryStatus; mcs.AddCommand(menuItem); } SolutionEventSink solutionEventSink = new SolutionEventSink(this, createAtlassianWindow, createIssueDetailsWindow, createBuildDetailsWindow); IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(solutionEventSink, out solutionEventCookie)); #if !VS2010 JiraLinkMarkerTypeProvider markerTypeProvider = new JiraLinkMarkerTypeProvider(); ((IServiceContainer)this).AddService(markerTypeProvider.GetType(), markerTypeProvider, true); // Now it's time to initialize our copies of the marker IDs. We need them to be // able to create marker instances. JiraLinkMarkerTypeProvider.InitializeMarkerIds(this); RunningDocTableEventSink runningDocTableEventSink = new RunningDocTableEventSink(); TextManagerEventSink textManagerEventSink = new TextManagerEventSink(); IConnectionPointContainer textManager = (IConnectionPointContainer)GetService(typeof(SVsTextManager)); Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID; try { textManager.FindConnectionPoint(ref interfaceGuid, out tmConnectionPoint); tmConnectionPoint.Advise(textManagerEventSink, out tmConnectionCookie); // ReSharper disable EmptyGeneralCatchClause } catch {} // ReSharper restore EmptyGeneralCatchClause IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable)); ErrorHandler.ThrowOnFailure(rdt.AdviseRunningDocTableEvents(runningDocTableEventSink, out rdtEventCookie)); // Since we register custom text markers we have to ensure the font and color // cache is up-to-date. ValidateFontAndColorCacheManagerIsUpToDate(); #endif ((IServiceContainer)this).AddService(typeof(AnkhSvnJiraConnector), new ServiceCreatorCallback(CreateAnkhSvnConnector), true); }
public SolutionNotifier(ISolutionProvider solutionProvider) { var solution = solutionProvider.Provide(); var solutionEventStream = Observable.Create <SolutionEventInfo>(observer => { uint unregisterToken = VSConstants.VSCOOKIE_NIL; var solutionEventSink = new SolutionEventSink(observer); // TODO check result and manage failure solution.AdviseSolutionEvents(solutionEventSink, out unregisterToken); Action disposeAction = () => { solution.UnadviseSolutionEvents(unregisterToken); }; return(disposeAction); }) .Publish() // this will be subscribed multiple times: avoid re-subscription side-effect .RefCount(); { var hotSolutionOpenedStream = solutionEventStream .Where(eventInfo => eventInfo.Reason == SolutionEventReason.SolutionOpened) .Select(_ => new SolutionInfo() { Solution = solution }) .Replay(0); hotSolutionOpenedStream.Connect().DisposeWith(disposables); SolutionOpenedStream = hotSolutionOpenedStream; } { var hotSolutionClosingStream = solutionEventStream .Where(eventInfo => eventInfo.Reason == SolutionEventReason.SolutionClosing) .Select(_ => Unit.Default) .Replay(0); hotSolutionClosingStream.Connect().DisposeWith(disposables); SolutionClosingStream = hotSolutionClosingStream; } { var hotProjectAddedStream = solutionEventStream .Where(eventInfo => eventInfo.Reason == SolutionEventReason.ProjectAdded) .Select(eventInfo => new ProjectInfo() { Hierarchy = eventInfo.ProjectHierarchy }) .Replay(0); hotProjectAddedStream.Connect().DisposeWith(disposables); ProjectAddedStream = hotProjectAddedStream; } { var hotProjectRemovingtream = solutionEventStream .Where(eventInfo => eventInfo.Reason == SolutionEventReason.ProjectRemoving) .Select(eventInfo => new ProjectInfo() { Hierarchy = eventInfo.ProjectHierarchy }) .Replay(0); hotProjectRemovingtream.Connect().DisposeWith(disposables); ProjectRemovingtream = hotProjectRemovingtream; } }