/// <summary> /// This method can be overriden by the derived class to execute any code that needs to run /// after the IVsWindowFrame is created. If the toolwindow has a toolbar with a combobox, it /// should make sure its command handler are set by the time they return from this method. /// This is called when someone set the Frame property. /// </summary> public override void OnToolWindowCreated() { base.OnToolWindowCreated(); // Register for events to this window. ((IVsWindowFrame)Frame).SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, this); // Package is not available at constructor time. if (Package != null) { // Get an instance of the code model manager. _codeModelManager = CodeModelManager.GetInstance(Package); _codeModelManager.CodeModelBuilt += OnCodeModelBuilt; // Pass the package over to the view model. _viewModel.Package = Package; // Attempt to initialize the Document, may have been set before Spade was created. if (Document == null) { Document = Package.ActiveDocument; } var spadeContent = Content as FrameworkElement; if (spadeContent != null) { spadeContent.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => Package.ThemeManager.ApplyTheme())); } } }
/// <summary> /// Initializes a new instance of the <see cref="CodeReorganizationManager" /> class. /// </summary> /// <param name="package">The hosting package.</param> private CodeReorganizationManager(CodeMaidPackage package) { _package = package; _codeModelManager = CodeModelManager.GetInstance(_package); _codeReorganizationAvailabilityLogic = CodeReorganizationAvailabilityLogic.GetInstance(_package); _generateRegionLogic = GenerateRegionLogic.GetInstance(_package); _insertBlankLinePaddingLogic = InsertBlankLinePaddingLogic.GetInstance(_package); _removeRegionLogic = RemoveRegionLogic.GetInstance(_package); }
/// <summary> /// Initializes a new instance of the <see cref="CodeReorderManager" /> class. /// </summary> /// <param name="package">The hosting package.</param> private CodeReorderManager(CodeMaidPackage package) { _package = package; _codeModelManager = CodeModelManager.GetInstance(_package); _undoTransactionHelper = new UndoTransactionHelper(_package, "CodeMaid Reorganize"); _generateRegionLogic = GenerateRegionLogic.GetInstance(_package); _insertBlankLinePaddingLogic = InsertBlankLinePaddingLogic.GetInstance(_package); _removeRegionLogic = RemoveRegionLogic.GetInstance(_package); }
/// <summary> /// This method can be overriden by the derived class to execute any code that needs to run /// after the IVsWindowFrame is created. If the toolwindow has a toolbar with a combobox, it /// should make sure its command handler are set by the time they return from this method. /// This is called when someone set the Frame property. /// </summary> public override void OnToolWindowCreated() { base.OnToolWindowCreated(); // Register for events to this window. ((IVsWindowFrame)Frame).SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, this); // Package is not available at constructor time. if (Package != null) { // Get an instance of the code model manager. _codeModelManager = CodeModelManager.GetInstance(Package); Package.JoinableTaskFactory.RunAsync(async() => await Package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, on => { if (on) { _codeModelManager.CodeModelBuilt += OnCodeModelBuilt; // Register for changes to settings. Settings.Default.SettingsLoaded += OnSettingsLoaded; Settings.Default.SettingsSaving += OnSettingsSaving; } else { _codeModelManager.CodeModelBuilt -= OnCodeModelBuilt; Settings.Default.SettingsLoaded -= OnSettingsLoaded; Settings.Default.SettingsSaving -= OnSettingsSaving; } return(Task.CompletedTask); })); // Pass the package over to the view model. _viewModel.Package = Package; // Attempt to initialize the Document, may have been set before Spade was created. if (Document == null) { Document = Package.ActiveDocument; } if (Content is FrameworkElement spadeContent) { _viewModel.Dispatcher = spadeContent.Dispatcher; spadeContent.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(Package.ThemeManager.ApplyTheme)); } } }
/// <summary> /// Register the package event listeners. /// </summary> /// <remarks> /// This must occur after the DTE service is available since many of the events are based /// off of the DTE object. /// </remarks> private void RegisterNonShellEventListeners() { // Create event listeners and register for events. var menuCommandService = MenuCommandService; if (menuCommandService != null) { var buildProgressToolWindowCommand = _commands.OfType <BuildProgressToolWindowCommand>().First(); var cleanupActiveCodeCommand = _commands.OfType <CleanupActiveCodeCommand>().First(); var collapseAllSolutionExplorerCommand = _commands.OfType <CollapseAllSolutionExplorerCommand>().First(); var spadeToolWindowCommand = _commands.OfType <SpadeToolWindowCommand>().First(); var codeModelManager = CodeModelManager.GetInstance(this); var settingsContextHelper = SettingsContextHelper.GetInstance(this); BuildProgressEventListener = new BuildProgressEventListener(this); BuildProgressEventListener.BuildBegin += buildProgressToolWindowCommand.OnBuildBegin; BuildProgressEventListener.BuildProjConfigBegin += buildProgressToolWindowCommand.OnBuildProjConfigBegin; BuildProgressEventListener.BuildProjConfigDone += buildProgressToolWindowCommand.OnBuildProjConfigDone; BuildProgressEventListener.BuildDone += buildProgressToolWindowCommand.OnBuildDone; DocumentEventListener = new DocumentEventListener(this); DocumentEventListener.OnDocumentClosing += codeModelManager.OnDocumentClosing; RunningDocumentTableEventListener = new RunningDocumentTableEventListener(this); RunningDocumentTableEventListener.BeforeSave += cleanupActiveCodeCommand.OnBeforeDocumentSave; RunningDocumentTableEventListener.AfterSave += spadeToolWindowCommand.OnAfterDocumentSave; SolutionEventListener = new SolutionEventListener(this); SolutionEventListener.OnSolutionOpened += collapseAllSolutionExplorerCommand.OnSolutionOpened; SolutionEventListener.OnSolutionOpened += settingsContextHelper.OnSolutionOpened; SolutionEventListener.OnSolutionClosed += settingsContextHelper.OnSolutionClosed; SolutionEventListener.OnSolutionClosed += OnSolutionClosedShowStartPage; // Check if a solution has already been opened before CodeMaid was initialized. if (IDE.Solution != null && IDE.Solution.IsOpen) { collapseAllSolutionExplorerCommand.OnSolutionOpened(); } TextEditorEventListener = new TextEditorEventListener(this); TextEditorEventListener.OnLineChanged += codeModelManager.OnDocumentChanged; WindowEventListener = new WindowEventListener(this); WindowEventListener.OnWindowChange += spadeToolWindowCommand.OnWindowChange; } }
/// <summary> /// Initializes a new instance of the <see cref="CodeCleanupManager" /> class. /// </summary> /// <param name="package">The hosting package.</param> private CodeCleanupManager(CodeMaidPackage package) { _package = package; _codeModelManager = CodeModelManager.GetInstance(_package); _codeReorderManager = CodeReorderManager.GetInstance(_package); _undoTransactionHelper = new UndoTransactionHelper(_package, "CodeMaid Cleanup"); _codeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(_package); _commentFormatLogic = CommentFormatLogic.GetInstance(_package); _insertBlankLinePaddingLogic = InsertBlankLinePaddingLogic.GetInstance(_package); _insertExplicitAccessModifierLogic = InsertExplicitAccessModifierLogic.GetInstance(); _insertWhitespaceLogic = InsertWhitespaceLogic.GetInstance(_package); _removeRegionLogic = RemoveRegionLogic.GetInstance(_package); _removeWhitespaceLogic = RemoveWhitespaceLogic.GetInstance(_package); _updateLogic = UpdateLogic.GetInstance(_package); _usingStatementCleanupLogic = UsingStatementCleanupLogic.GetInstance(_package); }
/// <summary> /// Initializes a new instance of the <see cref="CodeCleanupManager" /> class. /// </summary> /// <param name="package">The hosting package.</param> private CodeCleanupManager(CodeMaidPackage package) { _package = package; _codeModelManager = CodeModelManager.GetInstance(_package); _codeReorganizationManager = CodeReorganizationManager.GetInstance(_package); _commandHelper = CommandHelper.GetInstance(_package); _codeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(_package); _commentFormatLogic = CommentFormatLogic.GetInstance(_package); _insertBlankLinePaddingLogic = InsertBlankLinePaddingLogic.GetInstance(_package); _insertExplicitAccessModifierLogic = InsertExplicitAccessModifierLogic.GetInstance(); _insertWhitespaceLogic = InsertWhitespaceLogic.GetInstance(_package); _fileHeaderLogic = FileHeaderLogic.GetInstance(_package); _removeRegionLogic = RemoveRegionLogic.GetInstance(_package); _removeWhitespaceLogic = RemoveWhitespaceLogic.GetInstance(_package); _updateLogic = UpdateLogic.GetInstance(_package); _usingStatementCleanupLogic = UsingStatementCleanupLogic.GetInstance(_package); }
/// <summary> /// Register the package event listeners. /// </summary> /// <remarks> /// Every event listener registers VS events by itself. /// </remarks> private async Task RegisterEventListenersAsync() { var codeModelManager = CodeModelManager.GetInstance(this); var settingsContextHelper = SettingsContextHelper.GetInstance(this); VSColorTheme.ThemeChanged += _ => ThemeManager.ApplyTheme(); await BuildProgressEventListener.InitializeAsync(this); BuildProgressEventListener.Instance.BuildBegin += BuildProgressToolWindowCommand.Instance.OnBuildBegin; BuildProgressEventListener.Instance.BuildProjConfigBegin += BuildProgressToolWindowCommand.Instance.OnBuildProjConfigBegin; BuildProgressEventListener.Instance.BuildProjConfigDone += BuildProgressToolWindowCommand.Instance.OnBuildProjConfigDone; BuildProgressEventListener.Instance.BuildDone += BuildProgressToolWindowCommand.Instance.OnBuildDone; await DocumentEventListener.InitializeAsync(this); DocumentEventListener.Instance.OnDocumentClosing += codeModelManager.OnDocumentClosing; await RunningDocumentTableEventListener.InitializeAsync(this); await SettingsMonitor.WatchAsync(s => s.Feature_SettingCleanupOnSave, on => { if (on) { RunningDocumentTableEventListener.Instance.BeforeSave += CleanupActiveCodeCommand.Instance.OnBeforeDocumentSave; } else { RunningDocumentTableEventListener.Instance.BeforeSave -= CleanupActiveCodeCommand.Instance.OnBeforeDocumentSave; } return(Task.CompletedTask); }); await SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, on => { if (on) { RunningDocumentTableEventListener.Instance.AfterSave += SpadeToolWindowCommand.Instance.OnAfterDocumentSave; } else { RunningDocumentTableEventListener.Instance.AfterSave -= SpadeToolWindowCommand.Instance.OnAfterDocumentSave; } return(Task.CompletedTask); }); await SolutionEventListener.InitializeAsync(this); await SettingsMonitor.WatchAsync(s => s.Feature_CollapseAllSolutionExplorer, on => { if (on) { SolutionEventListener.Instance.OnSolutionOpened += CollapseAllSolutionExplorerCommand.Instance.OnSolutionOpened; } else { SolutionEventListener.Instance.OnSolutionOpened -= CollapseAllSolutionExplorerCommand.Instance.OnSolutionOpened; } return(Task.CompletedTask); }); SolutionEventListener.Instance.OnSolutionOpened += settingsContextHelper.OnSolutionOpened; SolutionEventListener.Instance.OnSolutionClosed += settingsContextHelper.OnSolutionClosed; SolutionEventListener.Instance.OnSolutionClosed += OnSolutionClosedShowStartPage; await TextEditorEventListener.InitializeAsync(this); TextEditorEventListener.Instance.OnLineChanged += codeModelManager.OnDocumentChanged; await WindowEventListener.InitializeAsync(this); WindowEventListener.Instance.OnWindowChange += SpadeToolWindowCommand.Instance.OnWindowChange; // Check if a solution has already been opened before CodeMaid was initialized. if (IDE.Solution?.IsOpen == true) { SolutionEventListener.Instance.FireSolutionOpenedEvent(); } }