protected virtual CodeEditorView CreateTextEditor()
        {
            CodeEditorView    codeEditorView = new CodeEditorView();
            CodeEditorAdapter adapter        = new CodeEditorAdapter(this, codeEditorView);

            codeEditorView.Adapter = adapter;
            TextView textView = codeEditorView.TextArea.TextView;

            textView.Services.AddService(typeof(ITextEditor), adapter);
            textView.Services.AddService(typeof(CodeEditor), this);

            codeEditorView.TextArea.TextEntering          += TextAreaTextEntering;
            codeEditorView.TextArea.TextEntered           += TextAreaTextEntered;
            codeEditorView.TextArea.Caret.PositionChanged += TextAreaCaretPositionChanged;
            codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
                new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion));

            textView.BackgroundRenderers.Add(textMarkerService);
            textView.LineTransformers.Add(textMarkerService);
            textView.Services.AddService(typeof(ITextMarkerService), textMarkerService);

            textView.Services.AddService(typeof(IEditorUIService), new AvalonEditEditorUIService(textView));

            textView.Services.AddService(typeof(IBookmarkMargin), iconBarManager);
            codeEditorView.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager));

            textView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(textView));

            codeEditorView.TextArea.MouseRightButtonDown += TextAreaMouseRightButtonDown;
            codeEditorView.TextArea.ContextMenuOpening   += TextAreaContextMenuOpening;
            codeEditorView.TextArea.TextCopied           += textEditor_TextArea_TextCopied;
            codeEditorView.GotFocus += textEditor_GotFocus;

            return(codeEditorView);
        }
        public CodeEditor()
        {
            CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged;
            ParserService.ParseInformationUpdated           += ParserServiceParseInformationUpdated;

            this.FlowDirection = FlowDirection.LeftToRight;             // code editing is always left-to-right
            this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));

            textMarkerService = new TextMarkerService(this);
            iconBarManager    = new IconBarManager();

            primaryTextEditor        = CreateTextEditor();
            primaryTextEditorAdapter = (CodeEditorAdapter)primaryTextEditor.TextArea.GetService(typeof(ITextEditor));
            Debug.Assert(primaryTextEditorAdapter != null);
            activeTextEditor = primaryTextEditor;

            this.Document = primaryTextEditor.Document;
            primaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding("Document")
            {
                Source = this
            });

            this.ColumnDefinitions.Add(new ColumnDefinition());
            this.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight
            });
            SetRow(primaryTextEditor, 1);

            this.Children.Add(primaryTextEditor);
        }
 public CodeEditorAdapter(CodeEditor codeEditor, CodeEditorView textEditor) : base(textEditor)
 {
     if (codeEditor == null)
     {
         throw new ArgumentNullException("codeEditor");
     }
     this.codeEditor = codeEditor;
 }
        CodeEditorView GetTextEditorFromSender(object sender)
        {
            ITextEditorComponent textArea   = (ITextEditorComponent)sender;
            CodeEditorView       textEditor = (CodeEditorView)textArea.GetService(typeof(TextEditor));

            if (textEditor == null)
            {
                throw new InvalidOperationException("could not find TextEditor service");
            }
            return(textEditor);
        }
        void OnSplitView(object sender, ExecutedRoutedEventArgs e)
        {
            if (secondaryTextEditor == null)
            {
                // create secondary editor
                this.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight
                });
                secondaryTextEditor        = CreateTextEditor();
                secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor));
                Debug.Assert(primaryTextEditorAdapter != null);

                secondaryTextEditor.SetBinding(TextEditor.DocumentProperty,
                                               new Binding(TextEditor.DocumentProperty.Name)
                {
                    Source = primaryTextEditor
                });
                secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty,
                                               new Binding(TextEditor.IsReadOnlyProperty.Name)
                {
                    Source = primaryTextEditor
                });
                secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting;

                gridSplitter = new GridSplitter {
                    Height = 4,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                SetRow(gridSplitter, 2);
                this.Children.Add(gridSplitter);

                secondaryTextEditor.Margin = new Thickness(0, 4, 0, 0);
                SetRow(secondaryTextEditor, 2);
                this.Children.Add(secondaryTextEditor);

                secondaryTextEditorAdapter.FileNameChanged();
                FetchParseInformation();
            }
            else
            {
                // remove secondary editor
                this.Children.Remove(secondaryTextEditor);
                this.Children.Remove(gridSplitter);
                secondaryTextEditorAdapter.Language.Detach();
                DisposeTextEditor(secondaryTextEditor);
                secondaryTextEditor        = null;
                secondaryTextEditorAdapter = null;
                gridSplitter = null;
                this.RowDefinitions.RemoveAt(this.RowDefinitions.Count - 1);
                this.ActiveTextEditor = primaryTextEditor;
            }
        }
 /// <summary>
 /// In the code editor, highlights all references to the expression under the caret (for better code readability).
 /// </summary>
 public CaretReferencesRenderer(CodeEditorView editorView)
 {
     this.editorView        = editorView;
     this.highlightRenderer = new ExpressionHighlightRenderer(this.editorView.TextArea.TextView);
     this.delayTimer        = new DispatcherTimer()
     {
         Interval = TimeSpan.FromMilliseconds(delayMs)
     };
     this.delayTimer.Stop();
     this.delayTimer.Tick += TimerTick;
     this.delayMoveTimer   = new DispatcherTimer()
     {
         Interval = TimeSpan.FromMilliseconds(delayMoveMs)
     };
     this.delayMoveTimer.Stop();
     this.delayMoveTimer.Tick += TimerMoveTick;
     this.editorView.TextArea.Caret.PositionChanged += CaretPositionChanged;
 }
        void OnCodeCompletion(object sender, ExecutedRoutedEventArgs e)
        {
            if (CompletionWindow != null)
            {
                CompletionWindow.Close();
            }

            // disable all code completion bindings when CC is disabled
            if (!CodeCompletionOptions.EnableCodeCompletion)
            {
                return;
            }

            CodeEditorView textEditor = GetTextEditorFromSender(sender);

            foreach (ICodeCompletionBinding cc in CodeCompletionBindings)
            {
                if (cc.CtrlSpace(textEditor.Adapter))
                {
                    e.Handled = true;
                    break;
                }
            }
        }
 protected virtual void DisposeTextEditor(CodeEditorView textEditor)
 {
     // detach IconBarMargin from IconBarManager
     textEditor.TextArea.LeftMargins.OfType <IconBarMargin>().Single().TextView = null;
     textEditor.Dispose();
 }
Exemple #9
0
 public CustomTabCommand(CodeEditorView editor, ICommand baseCommand)
 {
     this.editor      = editor;
     this.baseCommand = baseCommand;
 }