Example #1
0
        /// <summary>
        /// Hock event handlers and restore editor states (if any) or defaults
        /// when the control is fully loaded.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="args"></param>
        private void OnLoaded(object obj, RoutedEventArgs args)
        {
            try
            {
                // This adds a search panel into the edit
                // It is available via Ctrl-F
                SearchPanel.Install(this);

                // Remove rounded corners from text selection
                this.TextArea.SelectionCornerRadius = 0;
                this.TextArea.SelectionBorder       = null;

                // Initialize Diff line background color rendering
                _DiffBackgroundRenderer = new DiffLineBackgroundRenderer(this);
                this.TextArea.TextView.BackgroundRenderers.Add(_DiffBackgroundRenderer);

                // Customize display of line numbers using real lines (shown with a number)
                // and imaginary lines (shown without a number)
                // Switch off default line handler in AvalonEdit
                ShowLineNumbers = false;
                this.TextArea.LeftMargins.Clear();
                var leftMargins = this.TextArea.LeftMargins;

                // Configure and insert custom line number margin indicator
                LineNumberMargin lineNumbers = new CustomLineNumberMargin(this);
                Line             line        = (Line)DottedLineMargin.Create();
                leftMargins.Insert(0, lineNumbers);
                leftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = this
                };
                line.SetBinding(Shape.StrokeProperty, lineNumbersForeground);
                lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);

                // Attach more event handlers
                this.GotFocus += DiffView_GotFocus;
                ////this.Focus();
                ////this.ForceCursor = true;

                // Restore cursor position for CTRL-TAB Support http://avalondock.codeplex.com/workitem/15079
                this.ScrollToHorizontalOffset(this.EditorScrollOffsetX);
                this.ScrollToVerticalOffset(this.EditorScrollOffsetY);

                // Highlight current line in editor (even if editor is not focused) via themable dp-property
                this.AdjustCurrentLineBackground();

                this.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            }
            catch
            {
                // catch this to make sure initialization can continue...
            }
        }
Example #2
0
        /// <summary>Updates the Custom Display of LineNumbers (inlcuding gaps) via binding through <see cref="ItemsSource"/></summary>
        /// <param name="showCustomLineNumbers"></param>
        private void DisplayCustomLineNumbers(bool showCustomLineNumbers)
        {
            // Check if current setup is different from request and return if this is already set
            if (_currentShowCustomLineNumbers != null)
            {
                if (_currentShowCustomLineNumbers == showCustomLineNumbers)
                {
                    return;
                }
            }

            // Customize display of line numbers using real lines (shown with a number)
            // and imaginary lines (shown without a number)
            // Switch off default line handler in AvalonEdit
            ShowLineNumbers = false;
            this.TextArea.LeftMargins.Clear();

            if (showCustomLineNumbers)
            {
                var leftMargins = this.TextArea.LeftMargins;

                // Configure and insert custom line number margin indicator
                LineNumberMargin lineNumbers = new CustomLineNumberMargin(this);
                Line             line        = (Line)DottedLineMargin.Create();
                leftMargins.Insert(0, lineNumbers);
                leftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = this
                };
                line.SetBinding(Shape.StrokeProperty, lineNumbersForeground);
                lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
            }

            _currentShowCustomLineNumbers = showCustomLineNumbers;
        }