예제 #1
0
        private void DocumentEvents_DocumentOpened(EnvDTE.Document?document)
        {
            //using (PerformanceTracer.Start("DTE event: Document opened"))
            {
                if (!AffectsResourceFile(document))
                {
                    return;
                }

                ReloadSolution();
            }
        }
예제 #2
0
        public static EnvDTE.ProjectItem?GetProjectItem(this EnvDTE.Document? document)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                return(document?.ProjectItem);
            }
            catch
            {
                return(null);
            }
        }
예제 #3
0
        private void DocumentEvents_DocumentOpened(EnvDTE.Document?document)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            using (_performanceTracer?.Start("DTE event: Document opened"))
            {
                if (!AffectsResourceFile(document))
                {
                    return;
                }

                ReloadSolution();
            }
        }
예제 #4
0
        private static XDocument?TryGetContent(EnvDTE.Document?document)
        {
            try
            {
                var textDocument = document?.Object(@"TextDocument") as EnvDTE.TextDocument;
                var text         = textDocument?.CreateEditPoint().GetText(textDocument.EndPoint);

                return(text == null ? null : XDocument.Parse(text));
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #5
0
        private static bool AffectsResourceFile(EnvDTE.Document?document)
        {
            if (document == null)
            {
                return(false);
            }

            return(document.ProjectItem
                   .DescendantsAndSelf()
                   .Select(item => item.TryGetFileName())
                   .Where(fileName => fileName != null)
                   .Select(Path.GetExtension)
                   .Any(extension => ProjectFileExtensions.SupportedFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)));
        }
예제 #6
0
        private static bool AffectsResourceFile(EnvDTE.Document?document)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (document == null)
            {
                return(false);
            }

            return(document.GetProjectItem()
                   .DescendantsAndSelf()
                   .Select(item => item.TryGetFileName())
                   .ExceptNullItems()
                   .Select(Path.GetExtension)
                   .Any(ProjectFileExtensions.IsSupportedFileExtension));
        }
예제 #7
0
        private static bool TrySetContent(EnvDTE.Document?document, [NotNull] XDocument value)
        {
            try
            {
                var textDocument = (EnvDTE.TextDocument)document?.Object(@"TextDocument");
                if (textDocument == null)
                {
                    return(false);
                }

                var text = value.Declaration + Environment.NewLine + value;

                textDocument.CreateEditPoint().ReplaceText(textDocument.EndPoint, text, 0);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }