public TextEditorControl(IThemeManager themeManager, ToolTipHelper toolTipHelper, ITextEditorSettings textEditorSettings, ITextEditorUIContextImpl uiContext, ITextEditorHelper textEditorHelper, ITextLineObjectManager textLineObjectManager, IImageManager imageManager, IIconBarCommandManager iconBarCommandManager)
        {
            this.references         = new TextSegmentCollection <ReferenceSegment>();
            this.themeManager       = themeManager;
            this.toolTipHelper      = toolTipHelper;
            this.textEditorSettings = textEditorSettings;
            this.textEditorHelper   = textEditorHelper;
            InitializeComponent();
            this.textEditorSettings.PropertyChanged += TextEditorSettings_PropertyChanged;

            themeManager.ThemeChanged += ThemeManager_ThemeChanged;

            textEditor = new NewTextEditor(themeManager, textEditorSettings);
            this.toolTipHelper.Initialize(TextEditor);
            RemoveCommands(TextEditor);
            newTextEditor.Content      = TextEditor;
            TextEditor.IsReadOnly      = true;
            TextEditor.ShowLineNumbers = true;

            referenceElementGenerator = new ReferenceElementGenerator(JumpToReference, a => true);
            // Add the ref elem generator first in case one of the refs looks like a http link etc
            TextEditor.TextArea.TextView.ElementGenerators.Insert(0, referenceElementGenerator);
            this.uiElementGenerator = new UIElementGenerator();
            textEditor.TextArea.TextView.ElementGenerators.Add(uiElementGenerator);

            iconBarMargin = new IconBarMargin(uiContext, textLineObjectManager, imageManager, themeManager);
            iconBarCommandManager.Initialize(iconBarMargin);
            TextEditor.TextArea.LeftMargins.Insert(0, iconBarMargin);
            TextEditor.TextArea.TextView.VisualLinesChanged += (s, e) => iconBarMargin.InvalidateVisual();

            textMarkerService = new TextMarkerService(this, uiContext, textLineObjectManager);
            TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
            TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);

            TextEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;

            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(true)), Key.Tab, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(false)), Key.Tab, ModifierKeys.Shift));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(true)), Key.Down, ModifierKeys.Control | ModifierKeys.Shift));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(false)), Key.Up, ModifierKeys.Control | ModifierKeys.Shift));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveToNextDefinition(true)), Key.Down, ModifierKeys.Alt));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveToNextDefinition(false)), Key.Up, ModifierKeys.Alt));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReference()), Key.F12, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReference()), Key.Enter, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReferenceNewTab()), Key.F12, ModifierKeys.Control));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReferenceNewTab()), Key.Enter, ModifierKeys.Control));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => ClearMarkedReferencesAndToolTip()), Key.Escape, ModifierKeys.None));

            TextEditor.OnShowLineNumbersChanged();
            OnAutoHighlightRefsChanged();
        }
Example #2
0
        public TextEditorControl(IThemeManager themeManager, ToolTipHelper toolTipHelper, ITextEditorSettings textEditorSettings, ITextEditorUIContextImpl uiContext, ITextEditorHelper textEditorHelper, ITextLineObjectManager textLineObjectManager, IImageManager imageManager, IIconBarCommandManager iconBarCommandManager)
        {
            this.references         = new TextSegmentCollection <ReferenceSegment>();
            this.themeManager       = themeManager;
            this.toolTipHelper      = toolTipHelper;
            this.textEditorSettings = textEditorSettings;
            this.textEditorHelper   = textEditorHelper;
            InitializeComponent();
            this.textEditorSettings.PropertyChanged += TextEditorSettings_PropertyChanged;

            themeManager.ThemeChanged += ThemeManager_ThemeChanged;

            textEditor = new NewTextEditor(themeManager);
            this.toolTipHelper.Initialize(TextEditor);
            RemoveCommands(TextEditor);
            newTextEditor.Content      = TextEditor;
            TextEditor.IsReadOnly      = true;
            TextEditor.ShowLineNumbers = true;
            TextEditor.Options.RequireControlModifierForHyperlinkClick = false;

            referenceElementGenerator = new ReferenceElementGenerator(JumpToReference, a => true);
            // Add the ref elem generator first in case one of the refs looks like a http link etc
            TextEditor.TextArea.TextView.ElementGenerators.Insert(0, referenceElementGenerator);
            this.uiElementGenerator = new UIElementGenerator();
            textEditor.TextArea.TextView.ElementGenerators.Add(uiElementGenerator);

            TextEditor.SetBinding(FontFamilyProperty, new Binding {
                Source = textEditorSettings,
                Path   = new PropertyPath("FontFamily"),
                Mode   = BindingMode.OneWay,
            });
            TextEditor.SetBinding(FontSizeProperty, new Binding {
                Source = textEditorSettings,
                Path   = new PropertyPath("FontSize"),
                Mode   = BindingMode.OneWay,
            });
            TextEditor.SetBinding(ICSharpCode.AvalonEdit.TextEditor.WordWrapProperty, new Binding {
                Source = textEditorSettings,
                Path   = new PropertyPath("WordWrap"),
                Mode   = BindingMode.OneWay,
            });

            iconBarMargin = new IconBarMargin(uiContext, textLineObjectManager, imageManager, themeManager);
            iconBarCommandManager.Initialize(iconBarMargin);
            TextEditor.TextArea.LeftMargins.Insert(0, iconBarMargin);
            TextEditor.TextArea.TextView.VisualLinesChanged += (s, e) => iconBarMargin.InvalidateVisual();

            textMarkerService = new TextMarkerService(this, uiContext, textLineObjectManager);
            TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
            TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);

            searchPanel = SearchPanel.Install(TextEditor.TextArea);
            searchPanel.RegisterCommands(this.CommandBindings);
            searchPanel.Localization = new AvalonEditSearchPanelLocalization();

            TextEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;

            TextEditor.TextArea.MouseRightButtonDown += (s, e) => TextEditor.GoToMousePosition();

            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(true)), Key.Tab, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveReference(false)), Key.Tab, ModifierKeys.Shift));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveToNextDefinition(true)), Key.Down, ModifierKeys.Alt));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => MoveToNextDefinition(false)), Key.Up, ModifierKeys.Alt));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReference()), Key.F12, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReference()), Key.Enter, ModifierKeys.None));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReferenceNewTab()), Key.F12, ModifierKeys.Control));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => FollowReferenceNewTab()), Key.Enter, ModifierKeys.Control));
            InputBindings.Add(new KeyBinding(new RelayCommand(a => ClearMarkedReferencesAndToolTip()), Key.Escape, ModifierKeys.None));

            this.AddHandler(GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(OnGotKeyboardFocus), true);
            this.AddHandler(LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(OnLostKeyboardFocus), true);

            OnHighlightCurrentLineChanged();
            OnShowLineNumbersChanged();
            OnAutoHighlightRefsChanged();
        }