Example #1
0
        // Remove commands the text editor added so we can use them for our own purposes
        static void RemoveCommands(NewTextEditor textEditor)
        {
            var handler = textEditor.TextArea.DefaultInputHandler;

            RemoveCommands(handler.Editing);
            RemoveCommands(handler.CaretNavigation);
            RemoveCommands(handler.CommandBindings);
        }
        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 #3
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();
        }
Example #4
0
 public NewHighlightingColorizer(NewTextEditor textEditor)
 {
     this.textEditor = textEditor;
 }
Example #5
0
 public NewHighlighter(NewTextEditor textEditor, TextDocument document)
 {
     this.textEditor = textEditor;
     this.document = document;
 }
Example #6
0
 public NewHighlighter(NewTextEditor textEditor, TextDocument document)
 {
     this.textEditor = textEditor;
     this.document   = document;
 }
Example #7
0
 public NewHighlightingColorizer(NewTextEditor textEditor)
 {
     this.textEditor = textEditor;
 }