Exemplo n.º 1
0
        public CodeEditor()
        {
            CodeEditorOptions.Instance.PropertyChanged      += CodeEditorOptions_Instance_PropertyChanged;
            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();
            changeWatcher     = new DefaultChangeWatcher();

            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);
        }
Exemplo n.º 2
0
		public CodeEditorAdapter(CodeEditor codeEditor, CodeEditorView textEditor) : base(textEditor)
		{
			if (codeEditor == null)
				throw new ArgumentNullException("codeEditor");
			this.codeEditor = codeEditor;
			options = CodeEditorOptions.Instance;
		}
Exemplo n.º 3
0
        public CodeEditor()
        {
            CodeEditorOptions.Instance.PropertyChanged      += CodeEditorOptions_Instance_PropertyChanged;
            CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged;
            SD.ParserService.ParseInformationUpdated        += ParserServiceParseInformationUpdated;

            this.FlowDirection = FlowDirection.LeftToRight;             // code editing is always left-to-right
            this.document      = new TextDocument();
            var documentServiceContainer = document.GetRequiredService <IServiceContainer>();

            textMarkerService = new TextMarkerService(document);
            documentServiceContainer.AddService(typeof(ITextMarkerService), textMarkerService);

            iconBarManager = new IconBarManager();
            documentServiceContainer.AddService(typeof(IBookmarkMargin), iconBarManager);

            if (CodeEditorOptions.Instance.EnableChangeMarkerMargin)
            {
                changeWatcher = new DefaultChangeWatcher();
            }
            primaryTextEditor        = CreateTextEditor();
            primaryTextEditorAdapter = (CodeEditorAdapter)primaryTextEditor.TextArea.GetService(typeof(ITextEditor));
            Debug.Assert(primaryTextEditorAdapter != null);

            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);
        }
Exemplo n.º 4
0
 protected virtual void DisposeTextEditor(CodeEditorView textEditor)
 {
     foreach (var d in textEditor.TextArea.LeftMargins.OfType <IDisposable>())
     {
         d.Dispose();
     }
     textEditor.Dispose();
 }
Exemplo n.º 5
0
 public CodeEditorAdapter(CodeEditor codeEditor, CodeEditorView textEditor) : base(textEditor)
 {
     if (codeEditor == null)
     {
         throw new ArgumentNullException("codeEditor");
     }
     this.codeEditor = codeEditor;
 }
Exemplo n.º 6
0
        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;
                secondaryTextEditor.UpdateCustomizedHighlighting();

                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;
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
		/// <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;
		}
Exemplo n.º 9
0
        protected virtual void DisposeTextEditor(CodeEditorView textEditor)
        {
            foreach (var d in textEditor.TextArea.LeftMargins.OfType <IDisposable>())
            {
                d.Dispose();
            }
            textEditor.TextArea.GetRequiredService <EnhancedScrollBar>().Dispose();
            var highlighter = textEditor.TextArea.GetService <IHighlighter>();

            if (highlighter != null)
            {
                highlighter.Dispose();
            }
            textEditor.Dispose();
        }
		public ContextActionsRenderer(CodeEditorView editor)
		{
			if (editor == null)
				throw new ArgumentNullException("editor");
			this.editorView = editor;
			
			this.editorView.TextArea.Caret.PositionChanged += CaretPositionChanged;
			
			this.editorView.KeyDown += new KeyEventHandler(ContextActionsRenderer_KeyDown);
			
			editor.TextArea.TextView.ScrollOffsetChanged += ScrollChanged;
			this.delayMoveTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMoveMilliseconds) };
			this.delayMoveTimer.Stop();
			this.delayMoveTimer.Tick += TimerMoveTick;
			WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchSingleton_Workbench_ActiveViewContentChanged;
		}
Exemplo n.º 11
0
		/// <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;
			// fixes SD-1873 - Unhandled WPF Exception when deleting text in text editor
			// clear highlights to avoid exceptions when trying to draw highlights in
			// locations that have been deleted already.
			this.editorView.Document.Changed += delegate { lastResolveResult = null; ClearHighlight(); };
		}
Exemplo n.º 12
0
 /// <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;
 }
Exemplo n.º 13
0
        /// <summary>
        /// This method is called to create a new text editor view (=once for the primary editor; and whenever splitting the editor)
        /// </summary>
        protected virtual CodeEditorView CreateTextEditor()
        {
            CodeEditorView    codeEditorView = new CodeEditorView();
            CodeEditorAdapter adapter        = new CodeEditorAdapter(this, codeEditorView);

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

            textView.Services.AddService(typeof(ITextEditor), adapter);
            textView.Services.AddService(typeof(CodeEditor), this);
            textView.Services.AddService(typeof(ICSharpCode.SharpDevelop.Gui.IEditable), this);
            textView.Services.AddService(typeof(ICSharpCode.SharpDevelop.Gui.IPositionable), this);
            textView.Services.AddService(typeof(IFileDocumentProvider), this);

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

            textView.BackgroundRenderers.Add(textMarkerService);
            textView.LineTransformers.Add(textMarkerService);

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

            codeEditorView.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager));

            if (changeWatcher != null)
            {
                codeEditorView.TextArea.LeftMargins.Add(new ChangeMarkerMargin(changeWatcher));
            }
            textView.Services.AddService(typeof(EnhancedScrollBar), new EnhancedScrollBar(codeEditorView, textMarkerService, changeWatcher));

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

            return(codeEditorView);
        }
Exemplo n.º 14
0
        /// <summary>
        /// This method is called to create a new text editor view (=once for the primary editor; and whenever splitting the editor)
        /// </summary>
        protected virtual CodeEditorView CreateTextEditor()
        {
            CodeEditorView    codeEditorView = new CodeEditorView();
            CodeEditorAdapter adapter        = new CodeEditorAdapter(this, codeEditorView);

            codeEditorView.Adapter  = adapter;
            codeEditorView.Document = document;
            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));
            codeEditorView.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(codeEditorView.TextArea));

            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));

            if (changeWatcher != null)
            {
                codeEditorView.TextArea.LeftMargins.Add(new ChangeMarkerMargin(changeWatcher));
            }

            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);
        }
Exemplo n.º 15
0
        public ContextActionsRenderer(CodeEditorView editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            this.editorView = editor;

            this.editorView.TextArea.Caret.PositionChanged += CaretPositionChanged;

            this.editorView.KeyDown += new KeyEventHandler(ContextActionsRenderer_KeyDown);

            editor.TextArea.TextView.ScrollOffsetChanged += ScrollChanged;
            this.delayMoveTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(delayMoveMilliseconds)
            };
            this.delayMoveTimer.Stop();
            this.delayMoveTimer.Tick += TimerMoveTick;
            WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchSingleton_Workbench_ActiveViewContentChanged;
        }
Exemplo n.º 16
0
 /// <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;
     // fixes SD-1873 - Unhandled WPF Exception when deleting text in text editor
     // clear highlights to avoid exceptions when trying to draw highlights in
     // locations that have been deleted already.
     this.editorView.Document.Changed += delegate { lastResolveResult = null; ClearHighlight(); };
 }
Exemplo n.º 17
0
        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;
                }
            }
        }
Exemplo n.º 18
0
        void OnCodeInsight(object sender, ExecutedRoutedEventArgs e)
        {
            if (InsightWindow != null)
            {
                InsightWindow.Close();
            }

            // disable all code insight bindings when Insight is disabled
            if (!CodeCompletionOptions.InsightEnabled)
            {
                return;
            }

            CodeEditorView textEditor = GetTextEditorFromSender(sender);

            foreach (IInsightCodeCompletionBinding cc in CodeCompletionBindings.OfType <IInsightCodeCompletionBinding>())
            {
                if (cc.CtrlShiftSpace(textEditor.Adapter))
                {
                    e.Handled = true;
                    break;
                }
            }
        }
Exemplo n.º 19
0
		/// <summary>
		/// This method is called to create a new text editor view (=once for the primary editor; and whenever splitting the editor)
		/// </summary>
		protected virtual CodeEditorView CreateTextEditor()
		{
			CodeEditorView codeEditorView = new CodeEditorView();
			CodeEditorAdapter adapter = new CodeEditorAdapter(this, codeEditorView);
			codeEditorView.Adapter = adapter;
			codeEditorView.Document = document;
			TextView textView = codeEditorView.TextArea.TextView;
			textView.Services.AddService(typeof(ITextEditor), adapter);
			textView.Services.AddService(typeof(CodeEditor), this);
			textView.Services.AddService(typeof(ICSharpCode.SharpDevelop.Gui.IEditable), this);
			textView.Services.AddService(typeof(ICSharpCode.SharpDevelop.Gui.IPositionable), this);
			textView.Services.AddService(typeof(IFileDocumentProvider), this);
			
			codeEditorView.TextArea.TextEntering += TextAreaTextEntering;
			codeEditorView.TextArea.TextEntered += TextAreaTextEntered;
			codeEditorView.TextArea.Caret.PositionChanged += TextAreaCaretPositionChanged;
			codeEditorView.TextArea.SelectionChanged += TextAreaSelectionChanged;
			codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
				new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion));
			codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
				new CommandBinding(CustomCommands.CtrlShiftSpaceInsight, OnCodeInsight));
			SearchPanel.Install(codeEditorView.TextArea);
			
			textView.BackgroundRenderers.Add(textMarkerService);
			textView.LineTransformers.Add(textMarkerService);
			
			textView.Services.AddService(typeof(IEditorUIService), new AvalonEditEditorUIService(textView));
			
			codeEditorView.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager));
			
			if (changeWatcher != null) {
				codeEditorView.TextArea.LeftMargins.Add(new ChangeMarkerMargin(changeWatcher));
			}
			textView.Services.AddService(typeof(EnhancedScrollBar), new EnhancedScrollBar(codeEditorView, textMarkerService, changeWatcher));
			
			codeEditorView.TextArea.MouseRightButtonDown += TextAreaMouseRightButtonDown;
			codeEditorView.TextArea.ContextMenuOpening += TextAreaContextMenuOpening;
			codeEditorView.TextArea.TextCopied += textEditor_TextArea_TextCopied;
			
			return codeEditorView;
		}
Exemplo n.º 20
0
		public CodeEditor()
		{
			CodeEditorOptions.Instance.PropertyChanged += CodeEditorOptions_Instance_PropertyChanged;
			CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged;
			SD.ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated;
			
			this.FlowDirection = FlowDirection.LeftToRight; // code editing is always left-to-right
			this.document = new TextDocument();
			var documentServiceContainer = document.GetRequiredService<IServiceContainer>();
			
			textMarkerService = new TextMarkerService(document);
			documentServiceContainer.AddService(typeof(ITextMarkerService), textMarkerService);
			
			iconBarManager = new IconBarManager();
			documentServiceContainer.AddService(typeof(IBookmarkMargin), iconBarManager);
			
			if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) {
				changeWatcher = new DefaultChangeWatcher();
			}
			primaryTextEditor = CreateTextEditor();
			primaryTextEditorAdapter = (CodeEditorAdapter)primaryTextEditor.TextArea.GetService(typeof(ITextEditor));
			Debug.Assert(primaryTextEditorAdapter != null);
			
			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);
		}
Exemplo n.º 21
0
		protected virtual void DisposeTextEditor(CodeEditorView textEditor)
		{
			foreach (var d in textEditor.TextArea.LeftMargins.OfType<IDisposable>())
				d.Dispose();
			textEditor.TextArea.GetRequiredService<EnhancedScrollBar>().Dispose();
			var highlighter = textEditor.TextArea.GetService<IHighlighter>();
			if (highlighter != null)
				highlighter.Dispose();
			textEditor.Dispose();
		}
Exemplo n.º 22
0
			public CustomTabCommand(CodeEditorView editor, ICommand baseCommand)
			{
				this.editor = editor;
				this.baseCommand = baseCommand;
			}
Exemplo n.º 23
0
		/// <summary>
		/// This method is called to create a new text editor view (=once for the primary editor; and whenever splitting the editor)
		/// </summary>
		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));
			
			codeEditorView.TextArea.LeftMargins.Add(new ChangeMarkerMargin(changeWatcher));
			
			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;
		}
Exemplo n.º 24
0
		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;
			}
		}
Exemplo n.º 25
0
		protected virtual void DisposeTextEditor(CodeEditorView textEditor)
		{
			foreach (var d in textEditor.TextArea.LeftMargins.OfType<IDisposable>())
				d.Dispose();
			textEditor.Dispose();
		}
Exemplo n.º 26
0
 public CustomTabCommand(CodeEditorView editor, ICommand baseCommand)
 {
     this.editor      = editor;
     this.baseCommand = baseCommand;
 }
Exemplo n.º 27
0
		public CodeEditor()
		{
			CodeEditorOptions.Instance.PropertyChanged += CodeEditorOptions_Instance_PropertyChanged;
			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();
			changeWatcher = new DefaultChangeWatcher();
			
			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);
		}