Example #1
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...
            }
        }
Example #2
0
        public ReplEditor(ReplEditorOptions options, IDsTextEditorFactoryService dsTextEditorFactoryService, IContentTypeRegistryService contentTypeRegistryService, ITextBufferFactoryService textBufferFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, IClassificationTypeRegistryService classificationTypeRegistryService, IThemeClassificationTypeService themeClassificationTypeService, IPickSaveFilename pickSaveFilename)
        {
            this.dispatcher       = Dispatcher.CurrentDispatcher;
            this.pickSaveFilename = pickSaveFilename;
            options = options?.Clone() ?? new ReplEditorOptions();
            options.CreateGuidObjects     = CommonGuidObjectsProvider.Create(options.CreateGuidObjects, new GuidObjectsProvider(this));
            this.PrimaryPrompt            = options.PrimaryPrompt;
            this.SecondaryPrompt          = options.SecondaryPrompt;
            this.subBuffers               = new List <ReplSubBuffer>();
            this.cachedColorsList         = new CachedColorsList();
            TextClassificationType        = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.Text);
            ReplPrompt1ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt1);
            ReplPrompt2ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt2);

            var contentType = contentTypeRegistryService.GetContentType(options.ContentType, options.ContentTypeString) ?? textBufferFactoryService.TextContentType;
            var textBuffer  = textBufferFactoryService.CreateTextBuffer(contentType);

            CachedColorsListTaggerProvider.AddColorizer(textBuffer, cachedColorsList);
            var roles           = dsTextEditorFactoryService.CreateTextViewRoleSet(options.Roles);
            var textView        = dsTextEditorFactoryService.CreateTextView(textBuffer, roles, editorOptionsFactoryService.GlobalOptions, options);
            var wpfTextViewHost = dsTextEditorFactoryService.CreateTextViewHost(textView, false);

            this.wpfTextViewHost = wpfTextViewHost;
            this.wpfTextView     = wpfTextViewHost.TextView;
            ReplEditorUtils.AddInstance(this, wpfTextView);
            wpfTextView.Options.SetOptionValue(DefaultWpfViewOptions.AppearanceCategory, AppearanceCategoryConstants.REPL);
            wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.DragDropEditingId, false);
            //TODO: ReplEditorOperations doesn't support virtual space
            wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.UseVirtualSpaceId, false);
            //TODO: Support box selection
            wpfTextView.Options.SetOptionValue(DefaultDsTextViewOptions.AllowBoxSelectionId, false);
            wpfTextView.Options.OptionChanged         += Options_OptionChanged;
            wpfTextView.TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
            wpfTextView.Closed += WpfTextView_Closed;
            this.wpfTextView.TextBuffer.Changed += TextBuffer_Changed;
            AddNewDocument();
            WriteOffsetOfPrompt(null, true);
            ReplEditorOperations              = new ReplEditorOperations(this, wpfTextView, editorOperationsFactoryService);
            wpfTextView.VisualElement.Loaded += WpfTextView_Loaded;
            UpdateRefreshScreenOnChange();
            CustomLineNumberMargin.SetOwner(wpfTextView, new ReplCustomLineNumberMarginOwner(this, themeClassificationTypeService));
        }
Example #3
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;
        }
 public CustomLineNumberMarginImpl(IWpfTextViewHost wpfTextViewHost, IClassificationFormatMapService classificationFormatMapService, ITextFormatterProvider textFormatterProvider)
     : base(PredefinedDnSpyMarginNames.CustomLineNumber, wpfTextViewHost, classificationFormatMapService, textFormatterProvider)
 {
     CustomLineNumberMargin.SetMargin(wpfTextViewHost.TextView, this);
 }