public void InitComments(XBackgroundRenderer renderer, TextEditor avalon) { _renderer = renderer; _avalon = avalon; // Events to ScrollViewer MouseEnter += (sender, args) => Cursor = Cursor = Cursors.IBeam; MouseLeave += (sender, args) => Cursor = null; PreviewMouseLeftButtonDown += (sender, args) => { // Проверяем попадание в сетку с комментариями // Если попадания нет, то юзер тыкнул куда-то в свободное место // Тогда поставим фокус в последний комментарий, в самый конец Point pt = args.GetPosition((UIElement)sender); HitTestResult res = VisualTreeHelper.HitTest(ElementsGrid, pt); if (res == null && Elements.Count > 0) { Elements[Elements.Count - 1].CaretIndex = Elements[Elements.Count - 1].Text.Length; Dispatcher.BeginInvoke(new Action(() => Elements[Elements.Count - 1].Focus())); // official hack! BAD! } }; }
// ---------------------------------------------------------------------------------------- public void Init(ErrorsListView errorsListView) { OnPropertyChanged("CurrentCodeFile"); // Без этого не скрывает все изначально _colorizeErrors = new ColorizeErrors(this); _colorizeErrorForPopUp = new ColorizeErrorForPopup(); // Tabs control tabControl.SelectionChanged += (sender, args) => { SetNewCodeFile(); OnPropertyChanged("CurrentCodeFile"); OnActiveFileChanged(); //Dispatcher.BeginInvoke(new Action(() => AvalonEditor.Focus())); // official hack! BAD! }; tabControl.FileOpened += (sender, args) => OnFileOpened(args); tabControl.FileClosed += (sender, args) => OnFileClosed(args); tabControl.Init(this); // Setting view _errorListView = errorsListView; // Скроллбары AvalonEditor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; AvalonEditor.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible; IsKeyboardFocusWithinChanged += (sender, args) => { IsEditorFocused = IsKeyboardFocusWithin; _isEditorFocused.Value = IsKeyboardFocusWithin || CommentsPanel.IsKeyboardFocusWithin; Redraw(); OnPropertyChanged("IsEditorFocused"); }; CommentsPanel.IsKeyboardFocusWithinChanged += (sender, args) => { _isEditorFocused.Value = IsKeyboardFocusWithin || CommentsPanel.IsKeyboardFocusWithin; Redraw(); }; // Выделение цветом XBackgroundRenderer currentLineColorize = new XBackgroundRenderer(AvalonEditor, _isEditorFocused, CommentsPanel); AvalonEditor.TextArea.TextView.BackgroundRenderers.Add(currentLineColorize); AvalonEditor.TextArea.TextView.LineTransformers.Add(new ColorizeColorSegments(this)); AvalonEditor.TextArea.TextView.LineTransformers.Add(_colorizeErrors); AvalonEditor.TextArea.TextView.LineTransformers.Add(_colorizeErrorForPopUp); // Отключаем drag&drop // Если разрешить DragDrop, выделение цветом рушится, и вообще нестабильно, ну его AvalonEditor.TextArea.Options.EnableTextDragDrop = false; AvalonEditor.Options.EnableEmailHyperlinks = false; AvalonEditor.Options.EnableHyperlinks = false; // Изначально никакой файл не открыт //SetNewCodeFile(); // Line numbers AvalonEditor.ShowLineNumbers = true; AvalonEditor.LineNumbersForeground = new SolidColorBrush(Colors.SteelBlue); // Update Line and Column in the bottom AvalonEditor.TextArea.Caret.PositionChanged += (sender, args) => { OnPropertyChanged("Caret"); SelectCurrentErrorForCaret(); if (CaretLine.Text != AvalonEditor.TextArea.Caret.Line.ToString()) { OnPropertyChanged("Line"); ScrollToErrorInCurrentLine(); } if (CaretColumn.Text != AvalonEditor.TextArea.Caret.Column.ToString()) { OnPropertyChanged("Column"); } CaretLine.Text = AvalonEditor.TextArea.Caret.Line.ToString(); CaretColumn.Text = AvalonEditor.TextArea.Caret.Column.ToString(); }; // Verical editor panels CheckboxesPanel.Init(this); CheckboxesPanel.InitCheckboxes(AvalonEditor); CommentsPanel.Init(this); CommentsPanel.InitComments(currentLineColorize, AvalonEditor); ErrorMarkersPanel.Init(this); BookmarksPanel.Init(this); BookmarksPanel.Init2(Resources["BookmarksContextMenu"] as ContextMenu, Resources["BookmarksEmptyContextMenu"] as ContextMenu); // Popups InitPopups(); }