void SyntaxHighlighter_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null && e.NewValue is SyntaxHighlighterViewModel)
            {
                int[] lineNumbers = ((SyntaxHighlighterViewModel)this.DataContext).LineNumbers;
                textEditor.TextArea.LeftMargins.Clear();
                textEditor.TextArea.LeftMargins.Add(new SnippetLineNumber(lineNumbers));
                textEditor.TextArea.LeftMargins.Add(DottedLineMargin.Create());
                textEditor.TextArea.TextView.LineTransformers.Add(new PreviewHighlighter(((SyntaxHighlighterViewModel)this.DataContext).SearchResult, lineNumbers));

                string ext = ".txt";
                if (!string.IsNullOrWhiteSpace(((SyntaxHighlighterViewModel)this.DataContext).FileName))
                {
                    ext = System.IO.Path.GetExtension((((SyntaxHighlighterViewModel)this.DataContext).FileName)).ToLower();
                }

                IHighlightingDefinition def = null;
                if (ext == ".sql")
                {
                    def = loadHighlightingDefinition("sqlmode.xshd");
                }
                else
                {
                    def = HighlightingManager.Instance.GetDefinitionByExtension(ext);
                }
                textEditor.SyntaxHighlighting = def;
            }
        }
Beispiel #2
0
        private static void OnShowLineNumbersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextEditor editor      = (TextEditor)d;
            var        leftMargins = editor.TextArea.LeftMargins;

            if ((bool)e.NewValue)
            {
                LineNumberMargin lineNumbers = new LineNumberMargin();
                Line             line        = (Line)DottedLineMargin.Create();
                leftMargins.Insert(0, lineNumbers);
                leftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = editor
                };
                line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
                lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
            }
            else
            {
                for (int i = 0; i < leftMargins.Count; i++)
                {
                    if (leftMargins[i] is LineNumberMargin)
                    {
                        leftMargins.RemoveAt(i);
                        if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
                        {
                            leftMargins.RemoveAt(i);
                        }
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        static void OnShowLineNumbersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextEditor editor      = (TextEditor)d;
            var        leftMargins = editor.TextArea.LeftMargins;

            if ((bool)e.NewValue)
            {
                leftMargins.Insert(0, new LineNumberMargin());
                leftMargins.Insert(1, DottedLineMargin.Create());
            }
            else
            {
                for (int i = 0; i < leftMargins.Count; i++)
                {
                    if (leftMargins[i] is LineNumberMargin)
                    {
                        leftMargins.RemoveAt(i);
                        if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
                        {
                            leftMargins.RemoveAt(i);
                        }
                        break;
                    }
                }
            }
        }
        private static void AddMargins(TextEditor textEditor)
        {
            textEditor.TextArea.LeftMargins.Clear();

            textEditor.TextArea.LeftMargins.Add(new MarginControl()
            {
                Chunk = (ChunkDiff)textEditor.DataContext,
                EnterAddModeCommand = GetEnterAddModeCommand(textEditor)
            });
            textEditor.TextArea.LeftMargins.Add(DottedLineMargin.Create());
        }
Beispiel #5
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...
            }
        }
Beispiel #6
0
        private static void BehaviourAttached(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextEditor textEditor = d as TextEditor;

            // textEditor.TextArea.TextView.LineTransformers.Add(new DiffLineColorizer((ChunkDiff)textEditor.DataContext));
            textEditor.TextArea.LeftMargins.Add(new TwoColumnMargin());
            textEditor.TextArea.LeftMargins.Add(DottedLineMargin.Create());

            var theme = GetTheme(textEditor);

            ChangeBackgroundRenderer(textEditor, theme);
        }
        private static void addLineNumberMarching(TextEditor _editor, LineNumberMargin lineNumbers)
        {
            var leftMargins = _editor.TextArea.LeftMargins;

            Line line = (Line)DottedLineMargin.Create();

            leftMargins.Insert(0, lineNumbers);
            leftMargins.Insert(1, line);
            var lineNumbersForeground = new Binding("LineNumbersForeground")
            {
                Source = _editor
            };

            line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
            lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
        }
Beispiel #8
0
        public AsmCodeEditor()
        {
            InitializeComponent();

            TextView textView = textEditor.TextArea.TextView;

            // Line numbers
            textEditor.ShowLineNumbers = true;

            // Line addresses
            LineAddressMargin lineAddresses = new LineAddressMargin(this);

            lineAddresses.SetValue(Control.ForegroundProperty, System.Windows.Media.Brushes.LightBlue);
            textEditor.TextArea.LeftMargins.Add(lineAddresses);
            Line verticalSeparator = (Line)DottedLineMargin.Create();

            verticalSeparator.Stroke = System.Windows.Media.Brushes.LightBlue;
            textEditor.TextArea.LeftMargins.Add(verticalSeparator);

            // Assembly syntax highlighting
            textView.LineTransformers.Add(new AsmSyntaxHighlighting());

            // Search box
            textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(textEditor.TextArea));

            // Compilation errors
            textMarkerService = new TextMarkerService(textEditor);
            textView.BackgroundRenderers.Add(textMarkerService);
            textView.LineTransformers.Add(textMarkerService);
            textView.MouseHover         += MouseHover;
            textView.MouseHoverStopped  += TextEditorMouseHoverStopped;
            textView.VisualLinesChanged += VisualLinesChanged;

            // Incremental compilation
            textEditor.Document.Changed += Document_Changed;
        }
Beispiel #9
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;
        }
Beispiel #10
0
        public ReplaceWindow()
        {
            InitializeComponent();

            if (Properties.Settings.Default.ReplaceBounds == Rect.Empty ||
                Properties.Settings.Default.ReplaceBounds == new Rect(0, 0, 0, 0))
            {
                Width  = 800;
                Height = 980;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                Left   = Properties.Settings.Default.ReplaceBounds.Left;
                Top    = Properties.Settings.Default.ReplaceBounds.Top;
                Width  = Properties.Settings.Default.ReplaceBounds.Width;
                Height = Properties.Settings.Default.ReplaceBounds.Height;
            }

            Loaded += (s, e) =>
            {
                if (!this.IsOnScreen())
                {
                    this.CenterWindow();
                }

                this.ConstrainToScreen();
            };

            cbWrapText.IsChecked = GrepSettings.Instance.Get <bool?>(GrepSettings.Key.ReplaceWindowWrap);
            zoomSlider.Value     = GrepSettings.Instance.Get <int>(GrepSettings.Key.ReplaceWindowFontSize);

            textEditor.ShowLineNumbers = false; // using custom line numbers

            lineNumberMargin = new ReplaceViewLineNumberMargin();
            Line line = (Line)DottedLineMargin.Create();

            textEditor.TextArea.LeftMargins.Insert(0, lineNumberMargin);
            textEditor.TextArea.LeftMargins.Insert(1, line);
            var lineNumbersForeground = new Binding("LineNumbersForeground")
            {
                Source = textEditor
            };

            line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
            lineNumberMargin.SetBinding(Control.ForegroundProperty, lineNumbersForeground);

            DataContext = ViewModel;

            ViewModel.LoadFile        += (s, e) => LoadFile();
            ViewModel.ReplaceMatch    += (s, e) => textEditor.TextArea.TextView.Redraw();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
            ViewModel.CloseTrue       += ViewModel_CloseTrue;

            textEditor.Loaded += (s, e) =>
            {
                // once loaded, move to the first file
                ViewModel.SelectNextFile();
            };

            Closing += (s, e) => SaveSettings();

            textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
        }
Beispiel #11
0
        public ReplaceWindow()
        {
            InitializeComponent();

            if (LayoutProperties.ReplaceBounds == Rect.Empty ||
                LayoutProperties.ReplaceBounds == new Rect(0, 0, 0, 0) ||
                !ViewModel.IsFullDialog)
            {
                Width  = ViewModel.DialogSize.Width;
                Height = ViewModel.DialogSize.Height;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                Left   = LayoutProperties.ReplaceBounds.Left;
                Top    = LayoutProperties.ReplaceBounds.Top;
                Width  = LayoutProperties.ReplaceBounds.Width;
                Height = LayoutProperties.ReplaceBounds.Height;
            }

            Loaded += (s, e) =>
            {
                if (!this.IsOnScreen())
                {
                    this.CenterWindow();
                }

                this.ConstrainToScreen();
            };

            if (ViewModel.IsFullDialog)
            {
                cbWrapText.IsChecked = GrepSettings.Instance.Get <bool?>(GrepSettings.Key.ReplaceWindowWrap);
                zoomSlider.Value     = GrepSettings.Instance.Get <int>(GrepSettings.Key.ReplaceWindowFontSize);

                textEditor.ShowLineNumbers = false; // using custom line numbers

                lineNumberMargin = new ReplaceViewLineNumberMargin();
                Line line = (Line)DottedLineMargin.Create();
                textEditor.TextArea.LeftMargins.Insert(0, lineNumberMargin);
                textEditor.TextArea.LeftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = textEditor
                };
                line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
                lineNumberMargin.SetBinding(Control.ForegroundProperty, lineNumbersForeground);

                searchPanel             = SearchPanel.Install(textEditor);
                searchPanel.MarkerBrush = Application.Current.Resources["Match.Highlight.Background"] as Brush;

                ViewModel.LoadFile        += (s, e) => LoadFile();
                ViewModel.ReplaceMatch    += (s, e) => textEditor.TextArea.TextView.Redraw();
                ViewModel.PropertyChanged += ViewModel_PropertyChanged;

                textEditor.Loaded += (s, e) =>
                {
                    // once loaded, move to the first file
                    ViewModel.SelectNextFile();
                };

                textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            }
            else
            {
                Loaded += (s, e) =>
                {
                    // once loaded, move to the first file
                    ViewModel.SelectNextFile();
                };
            }

            ViewModel.CloseTrue += ViewModel_CloseTrue;

            DataContext = ViewModel;

            Closing += (s, e) => SaveSettings();
        }