private void UserControl_Loaded(object sender, RoutedEventArgs e) { var rootWindow = Window.GetWindow(this); if (rootWindow != null) { // add the Find command to the window so that we can press Ctrl+F from anywhere to bring up the search box _searchPanel.RegisterCommands(rootWindow.CommandBindings); } }
public NewTextEditor(IThemeManager themeManager, ITextEditorSettings textEditorSettings) { this.themeManager = themeManager; this.textEditorSettings = textEditorSettings; this.textEditorSettings.PropertyChanged += TextEditorSettings_PropertyChanged; this.themeManager.ThemeChanged += ThemeManager_ThemeChanged; Options.AllowToggleOverstrikeMode = true; Options.RequireControlModifierForHyperlinkClick = false; UpdateColors(false); searchPanel = SearchPanel.Install(TextArea); searchPanel.RegisterCommands(this.CommandBindings); searchPanel.Localization = new AvalonEditSearchPanelLocalization(); TextArea.SelectionCornerRadius = 0; TextArea.PreviewKeyDown += TextArea_PreviewKeyDown; TextArea.InputBindings.Add(new KeyBinding(new RelayCommand(a => PageUp()), Key.PageUp, ModifierKeys.Control)); TextArea.InputBindings.Add(new KeyBinding(new RelayCommand(a => PageDown()), Key.PageDown, ModifierKeys.Control)); TextArea.InputBindings.Add(new KeyBinding(new RelayCommand(a => UpDownLine(false)), Key.Down, ModifierKeys.Control)); TextArea.InputBindings.Add(new KeyBinding(new RelayCommand(a => UpDownLine(true)), Key.Up, ModifierKeys.Control)); this.AddHandler(GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(OnGotKeyboardFocus), true); this.AddHandler(LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(OnLostKeyboardFocus), true); TextArea.MouseRightButtonDown += (s, e) => GoToMousePosition(); SetBinding(FontFamilyProperty, new Binding { Source = textEditorSettings, Path = new PropertyPath("FontFamily"), Mode = BindingMode.OneWay, }); SetBinding(FontSizeProperty, new Binding { Source = textEditorSettings, Path = new PropertyPath("FontSize"), Mode = BindingMode.OneWay, }); SetBinding(WordWrapProperty, new Binding { Source = textEditorSettings, Path = new PropertyPath("WordWrap"), Mode = BindingMode.OneWay, }); OnHighlightCurrentLineChanged(); OnShowLineNumbersChanged(); }
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(); }