private void ExtractSelectionAndIncludes(EnvDTE.Document document, TrialAndErrorRemovalOptionsPage settings,
                                                 out ITextBuffer textBuffer, out Formatter.IncludeLineInfo[] includeLinesArray)
        {
            // Parsing.
            document.Activate();
            var documentTextView = VSUtils.GetCurrentTextViewHost();

            textBuffer = documentTextView.TextView.TextBuffer;
            string documentText = documentTextView.TextView.TextSnapshot.GetText();
            IEnumerable <Formatter.IncludeLineInfo> includeLines = Formatter.IncludeLineInfo.ParseIncludes(documentText, Formatter.ParseOptions.IgnoreIncludesInPreprocessorConditionals | Formatter.ParseOptions.KeepOnlyValidIncludes);

            // Optionally skip top most include.
            if (settings.IgnoreFirstInclude)
            {
                includeLines = includeLines.Skip(1);
            }

            // Skip everything with preserve flag.
            includeLines = includeLines.Where(x => !x.ShouldBePreserved);

            // Apply filter ignore regex.
            {
                string   documentName    = Path.GetFileNameWithoutExtension(document.FullName);
                string[] ignoreRegexList = RegexUtils.FixupRegexes(settings.IgnoreList, documentName);
                includeLines = includeLines.Where(line => !ignoreRegexList.Any(regexPattern =>
                                                                               new System.Text.RegularExpressions.Regex(regexPattern).Match(line.IncludeContent).Success));
            }
            // Reverse order if necessary.
            if (settings.RemovalOrder == TrialAndErrorRemovalOptionsPage.IncludeRemovalOrder.BottomToTop)
            {
                includeLines = includeLines.Reverse();
            }

            includeLinesArray = includeLines.ToArray();
        }
示例#2
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            EnvDTE80.DTE2   oApplication = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE));
            EnvDTE.Document oActive      = oApplication.ActiveDocument;

            if (oActive != null)
            {
                string        szExt      = Path.GetExtension(oActive.FullName);
                TextSelection oSelection = ( TextSelection )oActive.Selection;

                Color2CodeMap oMap = OptionPage.Color2CodeList.Find(oItem => oItem.Extensions.ToLower( ).Split(';').Any(szString => szString.Equals(szExt.ToLower( ))));

                if (oMap != null)
                {
                    oSelection.Text = EvaluateTemplate(oMap.Template, (( SolidColorBrush )(( Button )sender).Background).Color);
                }

                oActive.Activate( );
            }
        }