Ejemplo n.º 1
0
        public FrameworkElement Context(BlockColoring coloring, TextRunProperties properties)
        {
            Genero4glCodeBlock         item  = this;
            Stack <Genero4glCodeBlock> stack = new Stack <Genero4glCodeBlock>();

            do
            {
                if (item.type == BlockType.Root)
                {
                    break;
                }
                if (item.type != BlockType.Unknown)
                {
                    stack.Push(item);
                }
                item = item.parent;
            }while (item.type != BlockType.Namespace);
            int           repeatCount = 0;
            StringBuilder builder     = new StringBuilder();

            while (stack.Count != 0)
            {
                item = stack.Pop();
                builder.Append(item.Statement(repeatCount));

                repeatCount += 2;
                if (stack.Count != 0)
                {
                    builder.Append('\r');
                    builder.Append(' ', repeatCount);
                }
            }
            return(new TextBlob(FormatStatements(builder.ToString(), coloring, properties)));
        }
Ejemplo n.º 2
0
        private static FormattedText FormatStatements(string tipText, BlockColoring coloring, Typeface typeface, double emSize)
        {
            FormattedText formattedText = new FormattedText(tipText,
                                                            CultureInfo.InvariantCulture,
                                                            FlowDirection.LeftToRight,
                                                            typeface,
                                                            emSize,
                                                            Brushes.Black);

            if (coloring != null)
            {
                string[] loopKeywords   = new string[] { "for", "while", "do", "foreach", "For", "While", "Do", "Loop", "Until", "End While" };
                string[] ifKeywords     = new string[] { "if", "else", "switch", "If", "Else", "ElseIf", "End If" };
                string[] methodKeywords = new string[] { "private", "public", "protected", "internal", "sealed", "static",
                                                         "new", "override",
                                                         "int", "double", "void", "bool",
                                                         "Sub", "Function", "Module", "Class", "Property", "Get", "Set",
                                                         "Private", "Public",
                                                         "End Sub", "End Function", "End Module", "End Class", "End Property", "End Get", "End Set" };

                SetColors(coloring.GetBrush(BlockType.Loop), loopKeywords, tipText, formattedText);
                SetColors(coloring.GetBrush(BlockType.Conditional), ifKeywords, tipText, formattedText);
                SetColors(coloring.GetBrush(BlockType.Method), methodKeywords, tipText, formattedText);
            }
            return(formattedText);
        }
Ejemplo n.º 3
0
        private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                //Hook up to the various events we need to keep the caret margin current.
                _scrollBar.Map.MappingChanged += OnMappingChanged;

                _coloring          = new BlockColoring(_formatMap, 1.0);
                _coloring.Changed += this.OnColoringChanged;

                _tagger = _factory.TagAggregatorFactoryService.CreateTagAggregator <IBlockTag>(_textView);
                _tagger.BatchedTagsChanged += OnTagsChanged;

                //Force the margin to be re-rendered since things might have changed while the margin was hidden.
                this.InvalidateVisual();
            }
            else
            {
                _scrollBar.Map.MappingChanged -= OnMappingChanged;

                _coloring.Changed -= this.OnColoringChanged;
                _coloring.Dispose();
                _coloring = null;

                _tagger.BatchedTagsChanged -= OnTagsChanged;
                _tagger.Dispose();
                _tagger = null;
            }
        }
Ejemplo n.º 4
0
        private static FormattedText FormatStatements(string tipText, BlockColoring coloring, TextRunProperties properties)
        {
            FormattedText formattedText = new FormattedText(tipText,
                                                            CultureInfo.InvariantCulture,
                                                            FlowDirection.LeftToRight,
                                                            properties.Typeface,
                                                            properties.FontRenderingEmSize,
                                                            properties.ForegroundBrush,
                                                            VisualTreeHelper.GetDpi(Application.Current.MainWindow).PixelsPerDip);

            if (coloring != null)
            {
                string[] loopKeywords   = new string[] { "for", "while", "do", "foreach", "For", "While", "Do", "Loop", "Until", "End While" };
                string[] ifKeywords     = new string[] { "if", "else", "switch", "If", "Else", "ElseIf", "End If" };
                string[] methodKeywords = new string[] { "private", "public", "protected", "internal", "sealed", "static",
                                                         "new", "override",
                                                         "int", "double", "void", "bool",
                                                         "Sub", "Function", "Module", "Class", "Property", "Get", "Set",
                                                         "Private", "Public",
                                                         "End Sub", "End Function", "End Module", "End Class", "End Property", "End Get", "End Set" };

                SetColors(coloring.GetToolTipBrush(BlockType.Loop), loopKeywords, tipText, formattedText);
                SetColors(coloring.GetToolTipBrush(BlockType.Conditional), ifKeywords, tipText, formattedText);
                SetColors(coloring.GetToolTipBrush(BlockType.Method), methodKeywords, tipText, formattedText);
            }
            return(formattedText);
        }
        private StructureAdornmentManager(IWpfTextView view, StructureAdornmentFactory factory)
        {
            this.view  = view;
            this.layer = view.GetAdornmentLayer("StructureAdornmentLayer");

            factory.LoadOption(view.Options, StructureAdornmentManager.ClassColorId.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.ConditionalColorId.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.LoopColorId.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.MethodColorId.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.UnknownColorId.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.EnabledOption.Name);
            factory.LoadOption(view.Options, StructureAdornmentManager.LineWidthId.Name);

            this.blockColoring = new BlockColoring(view.Options.GetOptionValue(StructureAdornmentManager.LineWidthId),
                                                   view.Options.GetOptionValue(StructureAdornmentManager.ClassColorId),
                                                   view.Options.GetOptionValue(StructureAdornmentManager.ConditionalColorId),
                                                   view.Options.GetOptionValue(StructureAdornmentManager.LoopColorId),
                                                   view.Options.GetOptionValue(StructureAdornmentManager.MethodColorId),
                                                   view.Options.GetOptionValue(StructureAdornmentManager.UnknownColorId));

            this.blockTagger = factory.TagAggregatorFactoryService.CreateTagAggregator <IBlockTag>(view);

            view.Closed += OnClosed;

            view.Options.OptionChanged += this.OnOptionsChanged;
        }
Ejemplo n.º 6
0
        private static FormattedText FormatStatements(string tipText, BlockColoring coloring, TextRunProperties properties)
        {
            FormattedText formattedText = new FormattedText(tipText, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, properties.Typeface, properties.FontRenderingEmSize, properties.ForegroundBrush);

            if (coloring != null)
            {
                string[] keywords  = new string[] { "for", "while", "foreach" };
                string[] strArray2 = new string[] { "if", "then", "else", "case", "when", "otherwise" };
                string[] strArray3 = new string[] { "function", "main", "report", "dialog" };
                SetColors(coloring.GetToolTipBrush(BlockType.Loop), keywords, tipText, formattedText);
                SetColors(coloring.GetToolTipBrush(BlockType.Conditional), strArray2, tipText, formattedText);
                SetColors(coloring.GetToolTipBrush(BlockType.Method), strArray3, tipText, formattedText);
            }
            return(formattedText);
        }
Ejemplo n.º 7
0
        public FrameworkElement Context(BlockColoring coloring, TextRunProperties properties)
        {
            CodeBlock         context = this;
            Stack <CodeBlock> stack   = new Stack <CodeBlock>();

            while (true)
            {
                if (context._type == BlockType.Root)
                {
                    break;
                }
                if (context._type != BlockType.Unknown)
                {
                    stack.Push(context);
                }

                context = context._parent;
                if (context._type == BlockType.Namespace)
                {
                    break;
                }
            }

            int           indent = 0;
            StringBuilder b      = new StringBuilder();

            while (true)
            {
                context = stack.Pop();
                b.Append(context._statement);

                indent += 2;
                if (stack.Count != 0)
                {
                    b.Append('\r');
                    b.Append(' ', indent);
                }
                else
                {
                    break;
                }
            }
            return(new TextBlob(FormatStatements(b.ToString(), coloring, properties)));
        }
Ejemplo n.º 8
0
        private bool UpdateShowAdornments(bool enabled)
        {
            enabled = enabled && (_view.VisualElement.IsVisible || _view.Roles.Contains("PRINTABLE")) && (_showAdornments || _showMethodSeparator);

            if (_enabled != enabled)
            {
                _enabled = enabled;

                if (enabled)
                {
                    _coloring          = new BlockColoring(_formatMap, 1.0);
                    _coloring.Changed += this.OnColoringChanged;

                    _view.LayoutChanged             += OnLayoutChanged;
                    _blockTagger                     = _factory.TagAggregatorFactoryService.CreateTagAggregator <IBlockTag>(_view);
                    _blockTagger.BatchedTagsChanged += OnTagsChanged;

                    this.RedrawAllAdornments();

                    return(true);
                }
                else
                {
                    _view.LayoutChanged -= OnLayoutChanged;

                    _coloring.Changed -= this.OnColoringChanged;
                    _coloring.Dispose();
                    _coloring = null;

                    _blockTagger.BatchedTagsChanged -= OnTagsChanged;
                    _blockTagger.Dispose();
                    _blockTagger = null;

                    _visibleBlocks.Clear();
                    _methodSeparators.Clear();
                    _layer.RemoveAllAdornments();

                    this.CloseTip();
                }
            }

            return(false);
        }
Ejemplo n.º 9
0
 public FrameworkElement Context(BlockColoring coloring)
 {
     return(Context(coloring, new Typeface("Lucida Console"), 12.0));
 }
        /// <summary>
        /// Constructor for the StructureMarginElement.
        /// </summary>
        /// <param name="textView">ITextView to which this StructureMargenElement will be attacheded.</param>
        /// <param name="verticalScrollbar">Vertical scrollbar of the ITextViewHost that contains <paramref name="textView"/>.</param>
        /// <param name="tagFactory">MEF tag factory.</param>
        public StructureMarginElement(IWpfTextView textView, IVerticalScrollBar verticalScrollbar, StructureMarginFactory factory)
        {
            factory.LoadOption(textView.Options, StructureMarginElement.EnabledOptionId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.MarginWidthId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.MethodEllipseColorId.Name);

            factory.LoadOption(textView.Options, StructureMarginElement.ClassColorId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.ConditionalColorId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.LoopColorId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.MethodColorId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.UnknownColorId.Name);

            factory.LoadOption(textView.Options, StructureMarginElement.LineWidthId.Name);
            factory.LoadOption(textView.Options, StructureMarginElement.GapWidthId.Name);

            this.textView  = textView;
            this.scrollBar = verticalScrollbar;

            this.SnapsToDevicePixels = true;

            this.gapWidth  = textView.Options.GetOptionValue(StructureMarginElement.GapWidthId);
            this.lineWidth = textView.Options.GetOptionValue(StructureMarginElement.LineWidthId);

            this.blockColoring = new BlockColoring(this.lineWidth,
                                                   textView.Options.GetOptionValue(StructureMarginElement.ClassColorId),
                                                   textView.Options.GetOptionValue(StructureMarginElement.ConditionalColorId),
                                                   textView.Options.GetOptionValue(StructureMarginElement.LoopColorId),
                                                   textView.Options.GetOptionValue(StructureMarginElement.MethodColorId),
                                                   textView.Options.GetOptionValue(StructureMarginElement.UnknownColorId));

            this.tagger = factory.TagAggregatorFactoryService.CreateTagAggregator <IBlockTag>(textView);

            Color methodColor = textView.Options.GetOptionValue(StructureMarginElement.MethodEllipseColorId);

            if (methodColor.A != 0)
            {
                this.methodBrush = new SolidColorBrush(methodColor);
                this.methodBrush.Freeze();
            }

            //Make our width big enough to see, but not so big that it consumes a lot of
            //real-estate.
            this.Width = textView.Options.GetOptionValue(StructureMarginElement.MarginWidthId);

            this.OnOptionsChanged(null, null);
            this.textView.Options.OptionChanged += this.OnOptionsChanged;

            this.IsVisibleChanged += delegate(object sender, DependencyPropertyChangedEventArgs e)
            {
                if ((bool)e.NewValue)
                {
                    //Hook up to the various events we need to keep the caret margin current.
                    this.tagger.BatchedTagsChanged  += OnTagsChanged;
                    this.scrollBar.TrackSpanChanged += OnTrackSpanChanged;

                    //Force the margin to be rerendered since things might have changed while the margin was hidden.
                    this.InvalidateVisual();
                }
                else
                {
                    this.tagger.BatchedTagsChanged  -= OnTagsChanged;
                    this.scrollBar.TrackSpanChanged -= OnTrackSpanChanged;
                }
            };
        }
Ejemplo n.º 11
0
 public FrameworkElement Context(BlockColoring coloring)
 {
     return Context(coloring, new Typeface("Lucida Console"), 12.0);
 }
Ejemplo n.º 12
0
        private static FormattedText FormatStatements(string tipText, BlockColoring coloring, Typeface typeface, double emSize)
        {
            FormattedText formattedText = new FormattedText(tipText,
                                           CultureInfo.InvariantCulture,
                                           FlowDirection.LeftToRight,
                                           typeface,
                                           emSize,
                                           Brushes.Black);

            if (coloring != null)
            {
                string[] loopKeywords = new string[] { "for", "while", "do", "foreach", "For", "While", "Do", "Loop", "Until", "End While" };
                string[] ifKeywords = new string[] { "if", "else", "switch", "If", "Else", "ElseIf", "End If" };
                string[] methodKeywords = new string[] { "private", "public", "protected", "internal", "sealed", "static",
                                                     "new", "override",
                                                     "int", "double", "void", "bool",
                                                     "Sub", "Function", "Module", "Class", "Property", "Get", "Set",
                                                     "Private", "Public",
                                                     "End Sub", "End Function", "End Module", "End Class", "End Property", "End Get", "End Set"};

                SetColors(coloring.GetBrush(BlockType.Loop), loopKeywords, tipText, formattedText);
                SetColors(coloring.GetBrush(BlockType.Conditional), ifKeywords, tipText, formattedText);
                SetColors(coloring.GetBrush(BlockType.Method), methodKeywords, tipText, formattedText);
            }
            return formattedText;
        }
Ejemplo n.º 13
0
        public FrameworkElement Context(BlockColoring coloring, Typeface typeface, double emSize)
        {
            CodeBlock context = this;
            Stack<CodeBlock> stack = new Stack<CodeBlock>();
            while (true)
            {
                if (context.type == BlockType.Root)
                    break;
                if (context.type != BlockType.Unknown)
                {
                    stack.Push(context);
                }

                context = context.parent;
                if (context.type == BlockType.Namespace)
                    break;
            }

            int indent = 0;
            StringBuilder b = new StringBuilder();
            while (stack.Count != 0)
            {
                context = stack.Pop();
                b.Append(context.statement);

                indent += 2;
                if (stack.Count != 0)
                {
                    b.Append('\r');
                    b.Append(' ', indent);
                }
            }
            return new TextBlob(FormatStatements(b.ToString(), coloring, typeface, emSize));
        }