Пример #1
0
        private void solutionEvents_OpenedClosedAsync()
#endif
        {
            var dte2 = Utility.GetServiceFromPackage <DTE2, SDTE>(false);

            if (dte2 != null)
            {
                var solution = dte2.Solution;

                if (solution != null && !String.IsNullOrWhiteSpace(solution.FullName))
                {
                    // Only add this event after the solution is opened.  For solutions with subprojects, the
                    // ProjectAdded event fires before this one which makes it look like we're ready to start
                    // before everything is fully loaded.
                    solutionEvents.ProjectAdded -= solutionEvents_ProjectAdded;

                    List <string> names = new List <string>();

#if VS2017
                    if (LightweightSolutionApi.IsSolutionLoadDeferred)
                    {
                        names.AddRange(await LightweightSolutionApi.AllProjectsAsync());
                    }
                    else
#endif
                    foreach (Project p in solution.EnumerateProjects())
                    {
                        names.Add(p.FullName);
                    }

                    ucSpellCheck.UpdateProjects(names.OrderBy(n => Path.GetFileName(n)));

                    SpellingServiceFactory.LastSolutionName = solution.FullName;
                }
                else
                {
                    // Disconnect when closed (see above)
                    solutionEvents.ProjectAdded -= solutionEvents_ProjectAdded;

                    ucSpellCheck.UpdateProjects(null);
                    SpellingServiceFactory.LastSolutionName = null;
                }
            }
            else
            {
                ucSpellCheck.UpdateProjects(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Update the list of solutions/projects when a solution is opened or closed
        /// </summary>
        private void solutionEvents_OpenedClosed()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var dte2 = Utility.GetServiceFromPackage <DTE2, SDTE>(false);

            if (dte2 != null)
            {
                var solution = dte2.Solution;

                if (solution != null && !String.IsNullOrWhiteSpace(solution.FullName))
                {
                    // Only add this event after the solution is opened.  For solutions with subprojects, the
                    // ProjectAdded event fires before this one which makes it look like we're ready to start
                    // before everything is fully loaded.
                    solutionEvents.ProjectAdded -= solutionEvents_ProjectAdded;

                    List <string> names = new List <string>();

                    foreach (Project p in solution.EnumerateProjects())
                    {
                        names.Add(p.FullName);
                    }

                    ucSpellCheck.UpdateProjects(names.OrderBy(n => Path.GetFileName(n)));

                    SpellingServiceProxy.LastSolutionName = solution.FullName;
                }
                else
                {
                    // Disconnect when closed (see above)
                    solutionEvents.ProjectAdded -= solutionEvents_ProjectAdded;

                    ucSpellCheck.UpdateProjects(null);
                    SpellingServiceProxy.LastSolutionName = null;
                }
            }
            else
            {
                ucSpellCheck.UpdateProjects(null);
            }
        }