Exemplo n.º 1
0
        /// <summary>
        /// Initializes a singleton instance of this event listener.
        /// </summary>
        /// <param name="package">The hosting package.</param>
        /// <returns>A task.</returns>
        public static async Task InitializeAsync(CodeMaidPackage package)
        {
            Instance = new RunningDocumentTableEventListener(package);

            // This listener services multiple features, watching if any of them switched.
            await package.SettingsMonitor.WatchAsync <bool>(new[] {
                nameof(Settings.Default.Feature_SettingCleanupOnSave),
                nameof(Settings.Default.Feature_SpadeToolWindow)
            }, async values =>
            {
                await Instance.SwitchAsync(values.Any(v => v));
            });
        }
Exemplo n.º 2
0
        /// <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;
            }
        }
 public static void Intialize(CodeMaidPackage package)
 => Instance = new RunningDocumentTableEventListener(package);