private async Task StartInitializationAsync() { if (Interlocked.CompareExchange(ref _initialized, 1, 0) == 0) { await JoinableTaskFactory.RunAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = await _asyncServiceProvider.GetDTEAsync(); _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.BeforeClosing += SolutionEvents_BeforeClosing; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; _vsSolution = await _asyncServiceProvider.GetServiceAsync <SVsSolution, IVsSolution>(); Assumes.Present(_vsSolution); Advise(_vsSolution); }); // Signal the background job runner solution is loaded // Needed when OnAfterBackgroundSolutionLoadComplete fires before // Advise has been called. if (!_solutionLoadedEvent.IsSet && await IsSolutionFullyLoadedAsync()) { _solutionLoadedEvent.Set(); } } }
protected override void Initialize() { base.Initialize(); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); Instance = this; var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel)); VsWorkspace = componentModel.GetService <VisualStudioWorkspace>(); // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != menuCommandService) { new Menus.Cleanup.ActionCustomCodeCleanup(menuCommandService).SetupCommands(); } // Hook up event handlers events = App.DTE.Events; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; docEvents.DocumentSaved += DocumentEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await base.InitializeAsync(cancellationToken, progress); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); Instance = this; var componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)); VsWorkspace = componentModel.GetService <VisualStudioWorkspace>(); // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != menuCommandService) { new ActionCustomCodeCleanup(menuCommandService).SetupCommands(); } // Hook up event handlers events = App.DTE.Events; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; docEvents.DocumentSaved += DocumentEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; }
public OutputConsoleLogger( IAsyncServiceProvider asyncServiceProvider, IOutputConsoleProvider consoleProvider, Lazy <ErrorListTableDataSource> errorListDataSource) { if (asyncServiceProvider == null) { throw new ArgumentNullException(nameof(asyncServiceProvider)); } if (consoleProvider == null) { throw new ArgumentNullException(nameof(consoleProvider)); } ErrorListTableDataSource = errorListDataSource; NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = await asyncServiceProvider.GetDTEAsync(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += (_, __) => { ErrorListTableDataSource.Value.ClearNuGetEntries(); }; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.AfterClosing += () => { ErrorListTableDataSource.Value.ClearNuGetEntries(); }; OutputConsole = consoleProvider.CreatePackageManagerConsole(); }); }
/// <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> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); EnvDTE80.DTE2 dte2 = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; Microsoft.Assumes.Present(dte2); _events = dte2.Events.SolutionEvents; _events.AfterClosing += delegate { DirectivesCache.Clear(); }; _dte = await GetServiceAsync(typeof(SDTE)) as EnvDTE.DTE; Microsoft.Assumes.Present(_dte); _dteEvents = _dte.Events; _documentEvents = _dteEvents.DocumentEvents; _documentEvents.DocumentSaved += OnDocumentSaved; IVsSolution solution = await GetServiceAsync(typeof(IVsSolution)) as IVsSolution; _projects = GetProjects(solution); await ParseVueTemplate.InitializeAsync(this); }
/// <summary> /// Initialize level /// </summary> protected void init() { #if DEBUG Log.Warn("Used [Debug version]"); #else if (vsSBE.Version.branchName.ToLower() != "releases") { Log.Warn("Used [Unofficial release]"); } #endif if (Environment.Events != null) { slnEvents = Environment.Events.SolutionEvents; } Environment.CoreCmdSender = this; attachCommandEvents(); Log._.Received -= onLogReceived; Log._.Received += onLogReceived; //TODO: extract all below into new methods. It's valuable for CoreCommand etc. //+ do not forget about ClientLibrary, Provider, etc. this.Bootloader = new Bootloader(Environment, uvariable); this.Bootloader.register(); Action = new Actions.Connection( new Actions.Command(Environment, new Script(Bootloader), new MSBuild.Parser(Environment, uvariable)) ); }
private async Task InitializeAsync() { if (Interlocked.CompareExchange(ref _initialized, 1, 0) == 0) { await _joinableFactory.RunAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = _serviceProvider.GetDTE(); _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.BeforeClosing += SolutionEvents_BeforeClosing; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; _vsSolution = _serviceProvider.GetService <SVsSolution, IVsSolution>(); Assumes.Present(_vsSolution); #if VS15 // these properties are specific to VS15 since they are use to attach to solution events // which is further used to start bg job runner to schedule auto restore Advise(_vsSolution); #endif }); // Signal the background job runner solution is loaded // Needed when OnAfterBackgroundSolutionLoadComplete fires before // Advise has been called. if (!_solutionLoadedEvent.IsSet && await IsSolutionFullyLoadedAsync()) { _solutionLoadedEvent.Set(); } } }
public static void Initialize(EasyBuildManagerPackage package, EnvDTE.DTE dte) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTEWrapper.package = package; EnvDTEWrapper.dte = dte; solutionEvents = dte.Events.SolutionEvents; }
public Solution(ITracer tracer, IVsServiceProvider serviceProvider) { Contract.Requires(tracer != null); Contract.Requires(serviceProvider != null); _deferredUpdateThrottle = new DispatcherThrottle(DispatcherPriority.ContextIdle, Update); _tracer = tracer; _serviceProvider = serviceProvider; _specificProjectConfigurations = Projects.ObservableSelectMany(prj => prj.SpecificProjectConfigurations); _solutionContexts = SolutionConfigurations.ObservableSelectMany(cfg => cfg.Contexts); _defaultProjectConfigurations = Projects.ObservableSelect(prj => prj.DefaultProjectConfiguration); _projectConfigurations = new ObservableCompositeCollection <ProjectConfiguration>(_defaultProjectConfigurations, _specificProjectConfigurations); _solutionEvents = Dte?.Events?.SolutionEvents; if (_solutionEvents != null) { _solutionEvents.Opened += Solution_Changed; _solutionEvents.AfterClosing += Solution_Changed; _solutionEvents.ProjectAdded += _ => Solution_Changed(); _solutionEvents.ProjectRemoved += _ => Solution_Changed(); _solutionEvents.ProjectRenamed += (_, __) => Solution_Changed(); } Update(); }
public Solution([NotNull] ITracer tracer, [NotNull] IVsServiceProvider serviceProvider, [NotNull] PerformanceTracer performanceTracer) { Tracer = tracer; _serviceProvider = serviceProvider; _performanceTracer = performanceTracer; SpecificProjectConfigurations = Projects.ObservableSelectMany(prj => prj.SpecificProjectConfigurations); ProjectConfigurations = Projects.ObservableSelectMany(prj => prj.ProjectConfigurations); var solutionEvents = Dte?.Events?.SolutionEvents; if (solutionEvents != null) { solutionEvents.Opened += () => OnSolutionChanged("Solution opened"); solutionEvents.AfterClosing += () => OnSolutionChanged("Solution after closing"); solutionEvents.ProjectAdded += _ => OnSolutionChanged("Project added"); solutionEvents.ProjectRemoved += _ => OnSolutionChanged("Project removed"); solutionEvents.ProjectRenamed += (_, __) => OnSolutionChanged("Project renamed"); } _solutionEvents = solutionEvents; Update(0); CommandManager.RequerySuggested += (_, __) => Projects.ForEach(proj => proj?.InvalidateState()); }
public OutputConsoleLogger( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IOutputConsoleProvider consoleProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (consoleProvider == null) { throw new ArgumentNullException(nameof(consoleProvider)); } NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); ErrorListProvider = new ErrorListProvider(serviceProvider); _dte = serviceProvider.GetDTE(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += (_, __) => { ErrorListProvider.Tasks.Clear(); }; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.AfterClosing += () => { ErrorListProvider.Tasks.Clear(); }; OutputConsole = consoleProvider.CreatePackageManagerConsole(); }); }
public Solution([NotNull] ITracer tracer, [NotNull] IVsServiceProvider serviceProvider, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(tracer != null); Contract.Requires(serviceProvider != null); Contract.Requires(performanceTracer != null); _deferredUpdateThrottle = new DispatcherThrottle(DispatcherPriority.ApplicationIdle, Update); _tracer = tracer; _serviceProvider = serviceProvider; _performanceTracer = performanceTracer; _specificProjectConfigurations = _projects.ObservableSelectMany(prj => prj.SpecificProjectConfigurations); _projectConfigurations = _projects.ObservableSelectMany(prj => prj.ProjectConfigurations); _solutionEvents = Dte?.Events?.SolutionEvents; if (_solutionEvents != null) { _solutionEvents.Opened += () => Solution_Changed("Solution opened"); _solutionEvents.AfterClosing += () => Solution_Changed("Solution after closing"); _solutionEvents.ProjectAdded += _ => Solution_Changed("Project added"); _solutionEvents.ProjectRemoved += _ => Solution_Changed("Project removed"); _solutionEvents.ProjectRenamed += (_, __) => Solution_Changed("Project renamed"); } Update(); }
public void populateDefaultVSComObjects() { VisualStudio_2010.Package = this; VisualStudio_2010.ErrorListProvider = new ErrorListProvider(this); VisualStudio_2010.IVsUIShell = this.getService <IVsUIShell>(); VisualStudio_2010.DTE2 = this.getService <EnvDTE.DTE, EnvDTE80.DTE2>(); VisualStudio_2010.OleMenuCommandService = this.getService <OleMenuCommandService>(); Events = VisualStudio_2010.DTE2.Events; BuildEvents = Events.BuildEvents; CommandEvents = Events.CommandEvents; DebuggerEvents = Events.DebuggerEvents; DocumentEvents = Events.DocumentEvents; DTEEvents = Events.DTEEvents; FindEvents = Events.FindEvents; MiscFilesEvents = Events.MiscFilesEvents; OutputWindowEvents = Events.OutputWindowEvents; SelectionEvents = Events.SelectionEvents; SolutionEvents = Events.SolutionEvents; SolutionItemsEvents = Events.SolutionItemsEvents; TaskListEvents = Events.TaskListEvents; TextEditorEvents = Events.TextEditorEvents; WindowEvents = Events.WindowEvents; BuildEvents.OnBuildBegin += (scope, action) => VisualStudio_2010.On_BuildBegin.invoke(); BuildEvents.OnBuildDone += (scope, action) => VisualStudio_2010.On_BuildDone.invoke(); BuildEvents.OnBuildProjConfigDone += (Project, ProjectConfig, Platform, SolutionConfig, Success) => { //@"On OnBuildProjConfigDone: project: {0} , ProjectConfig: {1} , Platform: {2}, SolutionConfig: {3} , Success: {4}".debug(Project,ProjectConfig, Platform, SolutionConfig,Success); if (Success) { VisualStudio_2010.On_ProjectBuild_OK.invoke(Project); } else { VisualStudio_2010.On_ProjectBuild_Failed.invoke(Project); } }; SolutionEvents.Opened += () => VisualStudio_2010.On_SolutionOpened.invoke(); DocumentEvents.DocumentOpened += (document) => VisualStudio_2010.on_DocumentOpened.invoke(document); DocumentEvents.DocumentClosing += (document) => VisualStudio_2010.on_DocumentClosing.invoke(document); DocumentEvents.DocumentSaved += (document) => VisualStudio_2010.on_DocumentSaved.invoke(document); DocumentEvents.DocumentOpening += (documentPath, readOnly) => VisualStudio_2010.on_DocumentOpening.invoke(documentPath, readOnly); TextEditorEvents.LineChanged += (startPoint, endPoint, hInt) => VisualStudio_2010.on_LineChanged.invoke(startPoint, endPoint); WindowEvents.WindowActivated += (windowGotFocus, windowLostFocus) => { if (windowGotFocus.Document.notNull()) { VisualStudio_2010.on_ActiveDocumentChange.invoke(windowGotFocus.Document); } }; }
public override void OnToolWindowCreated() { var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; SolutionEvents = dte.Events.SolutionEvents; SolutionEvents.BeforeClosing += SolutionEvents_BeforeClosing; base.OnToolWindowCreated(); }
async Task IVisualStudioShell.SubscribeToAfterClosingAsync(Action afterClosing) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = await _dte.GetValueAsync(); _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.AfterClosing += () => afterClosing(); }
protected override void Initialize() { base.Initialize(); referenceHelper = new ReferenceHelper(this.AskUserToProceed); var envDTE = GetService(typeof (EnvDTE.DTE)) as EnvDTE80.DTE2; solutionEvents = envDTE.Events.SolutionEvents; solutionEvents.ProjectAdded += referenceHelper.SolutionEvents_ProjectAdded; solutionEvents.ProjectRemoved += referenceHelper.SolutionEvents_ProjectRemoved; }
private void ConnectEvents() { var events = (EnvDTE80.Events2)Dte.Events; _solutionEvents = events.SolutionEvents; _solutionEvents.Opened += SolutionEvents_Opened; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; _documentEvents = events.DocumentEvents; _documentEvents.DocumentOpened += DocumentEvents_DocumentOpened; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; }
/// <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> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // replace dte from next line with your dte package // dte = Utilities.Utility.GetEnvDTE(this); events = dte.Events; solutionEvents = events.SolutionEvents; solutionEvents.Opened += SolutionEvents_Opened; solutionEvents.AfterClosing += SolutionEvents_AfterClosing; }
/// <summary> /// Initializes a new instance of the <see cref="GitHostWindow"/> class. /// </summary> public GitHostWindow() : base(null) { // save references in order to make event registrations are not GCed _dte2 = (DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)); _events = _dte2.Events; _events2 = _events.SolutionEvents; _events2.Opened += SolutionEvents_Opened; _events3 = _events.WindowEvents; _events3.WindowActivated += _events3_WindowActivated; this.Caption = "Git Integrated Window"; // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. this.Content = _githost = new GitConsoleExtension.GitHostWindowControl(); }
protected override bool TryInitialize() { ThreadHelper.ThrowIfNotOnUIThread(); var dte = AcuminatorVSPackage.Instance.GetService <EnvDTE.DTE>(); //Store reference to DTE SolutionEvents and WindowEvents to prevent them from being GC-ed if (dte?.Events != null) { _solutionEvents = dte.Events.SolutionEvents; _windowEvents = dte.Events.WindowEvents; _documentEvents = dte.Events.DocumentEvents; _visibilityEvents = (dte.Events as EnvDTE80.Events2)?.WindowVisibilityEvents; } else { return(false); } return(_solutionEvents != null && _windowEvents != null && _documentEvents != null && _visibilityEvents != null); }
private void SubscripeToEvents() { var events = MasterObjekt.Events; buildEvents = events.BuildEvents; commandEvents = events.CommandEvents; documentEvents = events.DocumentEvents; solutionEvents = events.SolutionEvents; buildEvents.OnBuildBegin += new EnvDTE._dispBuildEvents_OnBuildBeginEventHandler(BuildEvents_OnBuildBegin); buildEvents.OnBuildDone += new EnvDTE._dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); commandEvents.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(CommandEvents_AfterExecute); documentEvents.DocumentSaved += new EnvDTE._dispDocumentEvents_DocumentSavedEventHandler(DocumentEvents_DocumentSaved); solutionEvents.Opened += new EnvDTE._dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.ProjectAdded += new EnvDTE._dispSolutionEvents_ProjectAddedEventHandler(SolutionEvents_ProjectAdded); solutionEvents.ProjectRemoved += new EnvDTE._dispSolutionEvents_ProjectRemovedEventHandler(SolutionEvents_ProjectRemoved); solutionEvents.ProjectRenamed += new EnvDTE._dispSolutionEvents_ProjectRenamedEventHandler(SolutionEvents_ProjectRenamed); solutionEvents.Renamed += new EnvDTE._dispSolutionEvents_RenamedEventHandler(SolutionEvents_Renamed); solutionEvents.AfterClosing += new EnvDTE._dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing); }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await base.InitializeAsync(cancellationToken, progress); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); Instance = this; var componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)); // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; var cmdidWebFileToggleId = new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, 0x101); var cmdidAttacherId = new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidAttacher); var otherMenu = menuCommandService.FindCommand(cmdidWebFileToggleId); if (otherMenu != null) { } if (null != menuCommandService) { var menuCommand = new OleMenuCommand(CallAttacher, cmdidAttacherId); menuCommand.BeforeQueryStatus += MenuCommand_BeforeQueryStatus; menuCommandService.AddCommand(menuCommand); } SetCommandBindings(); // Hook up event handlers events = App.DTE.Events; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; docEvents.DocumentSaved += DocumentEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; }
private void ConnectEvents() { var events = (EnvDTE80.Events2)Dte.Events; _solutionEvents = events.SolutionEvents; _solutionEvents.Opened += Solution_Opened; _solutionEvents.AfterClosing += Solution_AfterClosing; _solutionEvents.ProjectAdded += Solution_ContentChanged; _solutionEvents.ProjectRemoved += Solution_ContentChanged; _solutionEvents.ProjectRenamed += (item, newName) => Solution_ContentChanged(item); _projectItemsEvents = events.ProjectItemsEvents; _projectItemsEvents.ItemAdded += Solution_ContentChanged; _projectItemsEvents.ItemRemoved += Solution_ContentChanged; _projectItemsEvents.ItemRenamed += (item, newName) => Solution_ContentChanged(item); _solutionItemsEvents = events.SolutionItemsEvents; _solutionItemsEvents.ItemAdded += Solution_ContentChanged; _solutionItemsEvents.ItemRemoved += Solution_ContentChanged; _solutionItemsEvents.ItemRenamed += (item, newName) => Solution_ContentChanged(item); _miscFilesEvents = events.MiscFilesEvents; _miscFilesEvents.ItemAdded += Solution_ContentChanged; _miscFilesEvents.ItemRemoved += Solution_ContentChanged; _miscFilesEvents.ItemRenamed += (item, newName) => Solution_ContentChanged(item); _projectsEvents = events.ProjectsEvents; _projectsEvents.ItemAdded += Solution_ContentChanged; _projectsEvents.ItemRemoved += Solution_ContentChanged; _projectsEvents.ItemRenamed += (item, newName) => Solution_ContentChanged(item); _documentEvents = events.DocumentEvents; _documentEvents.DocumentOpened += DocumentEvents_DocumentOpened; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; if (Dte.Solution != null) { Solution_Opened(); } }
/// <summary> /// Initialize level /// </summary> protected void init() { #if VSSDK_15_AND_NEW Log.Info($"SDK15 & {vsSBE.Version.S_INFO}"); #else Log.Info($"SDK10 & {vsSBE.Version.S_INFO}"); #endif #if DEBUG Log.Warn($"Debug version"); #endif Log.Info($"Solution: {Environment.SolutionFile}"); loader = Bootloader.Init(Environment); if (Environment.Events != null) { slnEvents = Environment.Events.SolutionEvents; } Environment.CoreCmdSender = this; attachCommandEvents(); Log._.Received -= onLogReceived; Log._.Received += onLogReceived; //TODO: extract all below into new methods. It's valuable for CoreCommand etc. //+ do not forget about ClientLibrary, Provider, etc. Action = new Actions.Binder ( new Actions.Command ( Environment, loader.Soba, loader.Soba.EvMSBuild ), loader.Soba, buildState ); }
protected override void Initialize() { base.Initialize(); InitializeTaskProvider(); AddMenuCommands(); var dte = (EnvDTE.DTE)GetGlobalService(typeof(EnvDTE.DTE)); solutionEvents = dte.Events.SolutionEvents; windowEvents = dte.Events.WindowEvents; solutionEvents.Opened += RefreshTasksAsync; solutionEvents.AfterClosing += () => taskProvider.Tasks.Clear(); PackageOptions.Applied += (s, e) => OnPackageOptionsApplied(); if (Options.RequestOnStartup) { RefreshTasksAsync(); } }
/// <summary> /// Initialize level /// </summary> protected void init() { #if DEBUG Log.Warn("Used [Debug version]"); #else //if(vsSBE.Version.branchName.ToLower() != "releases") { // Log.Warn("Used [Unofficial release]"); //} #endif loader = Bootloader.Init(Environment); if (Environment.Events != null) { slnEvents = Environment.Events.SolutionEvents; } Environment.CoreCmdSender = this; attachCommandEvents(); Log._.Received -= onLogReceived; Log._.Received += onLogReceived; //TODO: extract all below into new methods. It's valuable for CoreCommand etc. //+ do not forget about ClientLibrary, Provider, etc. Action = new Actions.Binder ( new Actions.Command ( Environment, loader.Soba, loader.Soba.EvMSBuild ), loader.Soba ); }
protected override void Initialize() { base.Initialize(); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); Instance = this; var componentModel = (IComponentModel)GetService(typeof(SComponentModel)); // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != menuCommandService) { // var mainMenu = new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidMainMenu); // var founded = menuCommandService.FindCommand(mainMenu); // if (founded == null) // { // var menuCommand2 = new OleMenuCommand(null, mainMenu); // menuCommandService.AddCommand(menuCommand2); // menuCommand2.BeforeQueryStatus += MenuCommand2_BeforeQueryStatus; // } // Set up menu items new Menus.Typescript(menuCommandService).SetupCommands(); new Menus.RunBatchFiles(menuCommandService).SetupCommands(); new Menus.OpenRelatedFileF7(menuCommandService).SetupCommands(); } // Hook up event handlers events = App.DTE.Events; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; docEvents.DocumentSaved += DocumentEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; }
public Solution(EnvDTE.Solution nativeSolution) { ThreadHelper.ThrowIfNotOnUIThread(); this.NativeSolution = nativeSolution; if (!IsReady) { return; } this.solutionEvents = nativeSolution.DTE.Events.SolutionEvents; this.FilePath = nativeSolution.FullName; ReloadProjects(); this.solutionEvents.ProjectAdded += p => ReloadProjects(); this.solutionEvents.ProjectRemoved += p => ReloadProjects(); this.solutionEvents.ProjectRenamed += (p, n) => ReloadProjects(); sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager3; if (sbm != null) { sbm.AdviseUpdateSolutionEvents3(this, out updateSolutionEventsCookie); } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, false)) await tidyLogWriter.WriteLineAsync("Initialization has begun..."); await base.InitializeAsync(cancellationToken, progress); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Base has initialized"); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Switched to main thread"); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("App initialized"); Instance = this; var componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true); if (componentModel != null) { VsWorkspace = componentModel.GetService <VisualStudioWorkspace>(); } using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) { if (componentModel == null) { await tidyLogWriter.WriteLineAsync("component Model is null"); } else { await tidyLogWriter.WriteLineAsync("component has value"); } } // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(true) as OleMenuCommandService; if (null != menuCommandService) { new ActionCustomCodeCleanup(menuCommandService).SetupCommands(); } using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) { if (menuCommandService == null) { await tidyLogWriter.WriteLineAsync("menu Command Service is null"); } else { await tidyLogWriter.WriteLineAsync("menu Command Service has value"); } } // Hook up event handlers events = App.Dte.Events; buildEvent = events.BuildEvents; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; buildEvent.OnBuildBegin += BuildEvent_OnBuildBegin; docEvents.DocumentSaved += DocEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Initialization has finished..."); }
public void AddEvents() { _events = (EnvDTE80.Events2)dte.Events; _events.SolutionItemsEvents.ItemAdded += new EnvDTE._dispProjectItemsEvents_ItemAddedEventHandler(_events_ItemAdded); _docEvents = (EnvDTE.DocumentEvents)_events.get_DocumentEvents(null); _docEvents.DocumentSaved += new EnvDTE._dispDocumentEvents_DocumentSavedEventHandler(_docEvents_DocumentSaved); _slnEvents = (EnvDTE.SolutionEvents)_events.SolutionEvents; _slnEvents.Opened += new EnvDTE._dispSolutionEvents_OpenedEventHandler(_slnEvents_SolutionOpened); _slnEvents.ProjectAdded += new EnvDTE._dispSolutionEvents_ProjectAddedEventHandler(_slnEvents_ProjectAdded); _slnEvents.ProjectRemoved += new EnvDTE._dispSolutionEvents_ProjectRemovedEventHandler(_slnEvents_ProjectRemoved); _slnEvents.BeforeClosing += new EnvDTE._dispSolutionEvents_BeforeClosingEventHandler(_slnEvents_BeforeClosing); }
protected override void Initialize() { base.Initialize(); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); Instance = this; var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel)); VsWorkspace = componentModel.GetService <VisualStudioWorkspace>(); // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != menuCommandService) { menuCommandService.AddCommand(new MenuCommand(CallAttacher, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidAttacher))); menuCommandService.AddCommand(new MenuCommand(CallWebFileToggle, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidWebFileToggle))); menuCommandService.AddCommand(new MenuCommand(CallFixtureFileToggle, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidFixtureFileToggle))); menuCommandService.AddCommand(new MenuCommand(CallFileFinder, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidFileFinder))); menuCommandService.AddCommand(new MenuCommand(CallMemberFinder, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidMemberFinder))); menuCommandService.AddCommand(new MenuCommand(CallCssFinder, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidCSSFinder))); menuCommandService.AddCommand(new MenuCommand(CallGotoNextFoundItem, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidGotoNextFoundItem))); menuCommandService.AddCommand(new MenuCommand(CallGotoPreviousFoundItem, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidGotoPreviousFoundItem))); // Set up menu items new Menus.OpenInMSharp.OpenInMSharpCodeWindow(menuCommandService).SetupCommands(); new Menus.OpenInMSharp.OpenInMSharpSolutionExplorer(menuCommandService).SetupCommands(); new Menus.Typescript(menuCommandService).SetupCommands(); new Menus.RunBatchFiles(menuCommandService).SetupCommands(); new Menus.Cleanup.ActionCustomCodeCleanup(menuCommandService).SetupCommands(); } SetCommandBindings(); // Hook up event handlers events = App.DTE.Events; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; docEvents.DocumentSaved += DocumentEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; }
private void SubscripeToEvents() { var events = GetDTE2().Events; buildEvents = events.BuildEvents; commandEvents = events.CommandEvents; documentEvents = events.DocumentEvents; solutionEvents = events.SolutionEvents; buildEvents.OnBuildDone += new EnvDTE._dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); commandEvents.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(CommandEvents_AfterExecute); documentEvents.DocumentSaved += new EnvDTE._dispDocumentEvents_DocumentSavedEventHandler(DocumentEvents_DocumentSaved); solutionEvents.Opened += new EnvDTE._dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.ProjectAdded += new EnvDTE._dispSolutionEvents_ProjectAddedEventHandler(SolutionEvents_ProjectAdded); solutionEvents.ProjectRemoved += new EnvDTE._dispSolutionEvents_ProjectRemovedEventHandler(SolutionEvents_ProjectRemoved); solutionEvents.ProjectRenamed += new EnvDTE._dispSolutionEvents_ProjectRenamedEventHandler(SolutionEvents_ProjectRenamed); solutionEvents.Renamed += new EnvDTE._dispSolutionEvents_RenamedEventHandler(SolutionEvents_Renamed); solutionEvents.AfterClosing += new EnvDTE._dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing); }
/// <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() { Contract.Ensures(initialized); Debug.WriteLine("Entering Initialize() of: {0}", this); Debug.WriteLine("Default selected settings file: " + Settings.Default.SelectedSettingsFile); base.Initialize(); AddOptionKey(SettingsOptionKey); ReadSettingsDirectory(); if (settingsDirectory != null) { var events = Dte.Events; Contract.Assume(events != null); // A reference to solutionEvents must be stored in a field so that event handlers aren't collected by the GC. solutionEvents = events.SolutionEvents; dteEvents = events.DTEEvents; Contract.Assume(solutionEvents != null); Contract.Assume(dteEvents != null); solutionEvents.Opened += SolutionOpened; solutionEvents.Renamed += SolutionRenamed; solutionEvents.BeforeClosing += SolutionClosing; dteEvents.OnBeginShutdown += BeginShutdown; settingFilesWatcher.Path = settingsDirectory.LocalPath; settingFilesWatcher.EnableRaisingEvents = true; lock (gate) { LoadSettingsFiles(); if (selectedSettingsFile == null) { var defaultFile = Settings.Default.SelectedSettingsFile; if (string.IsNullOrWhiteSpace(defaultFile) || !File.Exists(defaultFile) || !settingsDirectory.IsBaseOf(new Uri(defaultFile, UriKind.Absolute))) { if (File.Exists(originalSettingsFile.LocalPath)) { Debug.WriteLine("Importing original settings file: " + originalSettingsFile.LocalPath); ImportSettings(originalSettingsFile.LocalPath); } else { Debug.WriteLine("Exporting original settings file: " + originalSettingsFile.LocalPath); ExportCurrentSettings(originalSettingsFile.LocalPath); } } else { Debug.WriteLine("Default settings file found: " + defaultFile); selectedSettingsFile = settingsFiles.FindByFullName(defaultFile); } } } } var menus = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (menus != null) { foreach (var command in InitializeCommands()) { menus.AddCommand(command); } } InitializePriorityCommands(); InitializeToolBar(); Contract.Assert(settingsDirectory == null || settingsDirectory.IsAbsoluteUri); Contract.Assert(settingsDirectory == null || settingsDirectory.IsFile); Contract.Assert(autoSettingsFile == null || autoSettingsFile.IsAbsoluteUri); Contract.Assert(autoSettingsFile == null || autoSettingsFile.IsFile); Contract.Assert(oldAutoSettingsFile == null || oldAutoSettingsFile.IsAbsoluteUri); Contract.Assert(oldAutoSettingsFile == null || oldAutoSettingsFile.IsFile); Contract.Assert(originalSettingsFile == null || originalSettingsFile.IsAbsoluteUri); Contract.Assert(originalSettingsFile == null || originalSettingsFile.IsFile); initialized = true; }
public Solution(ITracer tracer, IVsServiceProvider serviceProvider) { Contract.Requires(tracer != null); Contract.Requires(serviceProvider != null); _deferredUpdateThrottle = new DispatcherThrottle(DispatcherPriority.ContextIdle, Update); _tracer = tracer; _serviceProvider = serviceProvider; _specificProjectConfigurations = Projects.ObservableSelectMany(prj => prj.SpecificProjectConfigurations); _solutionContexts = SolutionConfigurations.ObservableSelectMany(cfg => cfg.Contexts); _defaultProjectConfigurations = Projects.ObservableSelect(prj => prj.DefaultProjectConfiguration); _projectConfigurations = new ObservableCompositeCollection<ProjectConfiguration>(_defaultProjectConfigurations, _specificProjectConfigurations); _solutionEvents = Dte?.Events?.SolutionEvents; if (_solutionEvents != null) { _solutionEvents.Opened += Solution_Changed; _solutionEvents.AfterClosing += Solution_Changed; _solutionEvents.ProjectAdded += _ => Solution_Changed(); _solutionEvents.ProjectRemoved += _ => Solution_Changed(); _solutionEvents.ProjectRenamed += (_, __) => Solution_Changed(); } Update(); }