Example #1
0
        static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FoldingMargin m = null;

            if (d is FoldingMargin)
            {
                m = (FoldingMargin)d;
            }
            else if (d is TextEditor)
            {
                m = ((TextEditor)d).TextArea.LeftMargins.FirstOrDefault(c => c is FoldingMargin) as FoldingMargin;
            }
            if (m == null)
            {
                return;
            }
            if (e.Property.Name == FoldingMarkerBrushProperty.Name)
            {
                m.foldingControlPen = MakeFrozenPen((Brush)e.NewValue);
            }
            if (e.Property.Name == SelectedFoldingMarkerBrushProperty.Name)
            {
                m.selectedFoldingControlPen = MakeFrozenPen((Brush)e.NewValue);
            }
        }
Example #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            FoldingMargin margin      = VisualParent as FoldingMargin;
            Pen           activePen   = new Pen(margin.SelectedFoldingMarkerBrush, 1);
            Pen           inactivePen = new Pen(margin.FoldingMarkerBrush, 1);

            activePen.StartLineCap = inactivePen.StartLineCap = PenLineCap.Square;
            activePen.EndLineCap   = inactivePen.EndLineCap = PenLineCap.Square;
            Size pixelSize = PixelSnapHelpers.GetPixelSize(this);
            Rect rect      = new Rect(pixelSize.Width / 2,
                                      pixelSize.Height / 2,
                                      this.RenderSize.Width - pixelSize.Width,
                                      this.RenderSize.Height - pixelSize.Height);

            drawingContext.DrawRectangle(
                IsMouseDirectlyOver ? margin.SelectedFoldingMarkerBackgroundBrush : margin.FoldingMarkerBackgroundBrush,
                IsMouseDirectlyOver ? activePen : inactivePen, rect);
            double middleX = rect.Left + rect.Width / 2;
            double middleY = rect.Top + rect.Height / 2;
            double space   = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width;

            drawingContext.DrawLine(activePen,
                                    new Point(rect.Left + space, middleY),
                                    new Point(rect.Right - space, middleY));
            if (!isExpanded)
            {
                drawingContext.DrawLine(activePen,
                                        new Point(middleX, rect.Top + space),
                                        new Point(middleX, rect.Bottom - space));
            }
        }
Example #3
0
            /*
             * void DemoMode()
             * {
             *      foldingGenerator = new FoldingElementGenerator() { FoldingManager = fm };
             *      foldingMargin = new FoldingMargin { FoldingManager = fm };
             *      foldingMarginBorder = new Border {
             *              Child = foldingMargin,
             *              Background = new LinearGradientBrush(Colors.White, Colors.Transparent, 0)
             *      };
             *      foldingMarginBorder.SizeChanged += UpdateTextViewClip;
             *      textEditor.TextArea.TextView.ElementGenerators.Add(foldingGenerator);
             *      textEditor.TextArea.LeftMargins.Add(foldingMarginBorder);
             * }
             *
             * void UpdateTextViewClip(object sender, SizeChangedEventArgs e)
             * {
             *      textEditor.TextArea.TextView.Clip = new RectangleGeometry(
             *              new Rect(-foldingMarginBorder.ActualWidth,
             *                       0,
             *                       textEditor.TextArea.TextView.ActualWidth + foldingMarginBorder.ActualWidth,
             *                       textEditor.TextArea.TextView.ActualHeight));
             * }
             */

            public void Uninstall()
            {
                Clear();
                if (textArea != null)
                {
                    textArea.Caret.PositionChanged -= textArea_Caret_PositionChanged;
                    textArea.LeftMargins.Remove(margin);
                    textArea.TextView.ElementGenerators.Remove(generator);
                    textArea.TextView.Services.RemoveService(typeof(FoldingManager));
                    margin    = null;
                    generator = null;
                    textArea  = null;
                }
            }
Example #4
0
 public FoldingManagerInstallation(TextArea textArea) : base(textArea.Document)
 {
     this.textArea = textArea;
     margin        = new FoldingMargin()
     {
         FoldingManager = this
     };
     generator = new FoldingElementGenerator()
     {
         FoldingManager = this
     };
     textArea.LeftMargins.Add(margin);
     textArea.TextView.Services.AddService(typeof(FoldingManager), this);
     // HACK: folding only works correctly when it has highest priority
     textArea.TextView.ElementGenerators.Insert(0, generator);
     textArea.Caret.PositionChanged += textArea_Caret_PositionChanged;
 }