Beispiel #1
0
 void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn, bool isSingleLine)
 {
     if (startColumn > text.Length)
     {
         Debug.Fail("startColumn is invalid");
         startColumn = text.Length;
     }
     if (endColumn > text.Length)
     {
         Debug.Fail("endColumn is invalid");
         endColumn = text.Length;
     }
     output.Write("// ");
     output.BeginSpan(gray);
     if (isSingleLine)
     {
         output.Write(text.Substring(0, startColumn).TrimStart());
     }
     else
     {
         output.Write(text.Substring(0, startColumn));
     }
     output.EndSpan();
     output.Write(text.Substring(startColumn, endColumn - startColumn));
     output.BeginSpan(gray);
     output.Write(text.Substring(endColumn));
     output.EndSpan();
     output.WriteLine();
 }
        private void BeginSpan(HighlightingColor highlightingColor)
        {
            if (textOutput != null)
            {
                textOutput.BeginSpan(highlightingColor);
                return;
            }

            if (currentColorBegin > -1)
            {
                HighlightingModel.SetHighlighting(currentColorBegin, locatable.Length - currentColorBegin, currentColor);
            }
            colorStack.Push(currentColor);
            currentColor      = currentColor.Clone();
            currentColorBegin = locatable.Length;
            currentColor.MergeWith(highlightingColor);
            currentColor.Freeze();
        }
 public void Write(ISmartTextOutput textOutput)
 {
     textOutput.WriteLine();
     textOutput.Write("This is a test.");
     textOutput.WriteLine();
     textOutput.WriteLine();
     textOutput.BeginSpan(new HighlightingColor {
         Background = new SimpleHighlightingBrush(Colors.Black),
         FontStyle  = FontStyle.Italic,
         Foreground = new SimpleHighlightingBrush(Colors.Aquamarine)
     });
     textOutput.Write("DO NOT PRESS THIS BUTTON --> ");
     textOutput.AddButton(null, "Test!", (sender, args) => MessageBox.Show("Naughty Naughty!", "Naughty!", MessageBoxButton.OK, MessageBoxImage.Exclamation));
     textOutput.Write(" <--");
     textOutput.WriteLine();
     textOutput.EndSpan();
     textOutput.WriteLine();
 }
        public override void WriteKeyword(Role role, string keyword)
        {
            HighlightingColor color = null;

            switch (keyword)
            {
            case "namespace":
            case "using":
                if (role == UsingStatement.UsingKeywordRole)
                {
                    color = structureKeywordsColor;
                }
                else
                {
                    color = namespaceKeywordsColor;
                }
                break;

            case "this":
            case "base":
                color = thisKeywordColor;
                break;

            case "true":
            case "false":
                color = trueKeywordColor;
                break;

            case "public":
            case "internal":
            case "protected":
            case "private":
                color = visibilityKeywordsColor;
                break;

            case "if":
            case "else":
            case "switch":
            case "case":
            case "default":
            case "while":
            case "do":
            case "for":
            case "foreach":
            case "lock":
            case "global":
            case "await":
                color = structureKeywordsColor;
                break;

            case "where":
                if (nodeStack.PeekOrDefault() is QueryClause)
                {
                    color = queryKeywordsColor;
                }
                else
                {
                    color = structureKeywordsColor;
                }
                break;

            case "in":
                if (nodeStack.PeekOrDefault() is ForeachStatement)
                {
                    color = structureKeywordsColor;
                }
                else if (nodeStack.PeekOrDefault() is QueryClause)
                {
                    color = queryKeywordsColor;
                }
                else
                {
                    color = parameterModifierColor;
                }
                break;

            case "as":
            case "is":
            case "new":
            case "sizeof":
            case "typeof":
            case "nameof":
            case "stackalloc":
                color = typeKeywordsColor;
                break;

            case "try":
            case "throw":
            case "catch":
            case "finally":
                color = exceptionKeywordsColor;
                break;

            case "when":
                if (role == CatchClause.WhenKeywordRole)
                {
                    color = exceptionKeywordsColor;
                }
                break;

            case "get":
            case "set":
            case "add":
            case "remove":
                if (role == PropertyDeclaration.GetKeywordRole ||
                    role == PropertyDeclaration.SetKeywordRole ||
                    role == CustomEventDeclaration.AddKeywordRole ||
                    role == CustomEventDeclaration.RemoveKeywordRole)
                {
                    color = accessorKeywordsColor;
                }
                break;

            case "abstract":
            case "const":
            case "event":
            case "extern":
            case "override":
            case "readonly":
            case "sealed":
            case "static":
            case "virtual":
            case "volatile":
            case "async":
            case "partial":
                color = modifiersColor;
                break;

            case "checked":
            case "unchecked":
                color = checkedKeywordColor;
                break;

            case "fixed":
            case "unsafe":
                color = unsafeKeywordsColor;
                break;

            case "enum":
            case "struct":
                color = valueTypeKeywordsColor;
                break;

            case "class":
            case "interface":
            case "delegate":
                color = referenceTypeKeywordsColor;
                break;

            case "select":
            case "group":
            case "by":
            case "into":
            case "from":
            case "orderby":
            case "let":
            case "join":
            case "on":
            case "equals":
                if (nodeStack.PeekOrDefault() is QueryClause)
                {
                    color = queryKeywordsColor;
                }
                break;

            case "ascending":
            case "descending":
                if (nodeStack.PeekOrDefault() is QueryOrdering)
                {
                    color = queryKeywordsColor;
                }
                break;

            case "explicit":
            case "implicit":
            case "operator":
                color = operatorKeywordsColor;
                break;

            case "params":
            case "ref":
            case "out":
                color = parameterModifierColor;
                break;

            case "break":
            case "continue":
            case "goto":
            case "yield":
            case "return":
                color = gotoKeywordsColor;
                break;
            }
            if (nodeStack.PeekOrDefault() is AttributeSection)
            {
                color = attributeKeywordsColor;
            }
            if (color != null)
            {
                textOutput.BeginSpan(color);
            }
            base.WriteKeyword(role, keyword);
            if (color != null)
            {
                textOutput.EndSpan();
            }
        }