示例#1
0
 protected virtual void DisposeTextEditor(CodeEditorView textEditor)
 {
     foreach (var d in textEditor.TextArea.LeftMargins.OfType <IDisposable>())
     {
         d.Dispose();
     }
     textEditor.Dispose();
 }
示例#2
0
        /// <summary>
        /// Uninitializes the specified code editor view and (if there is no other document open) removes the corresponding workspace from Roslyn.
        /// </summary>
        /// <param name="codeEditor">The code editor.</param>
        public void Uninitialize(CodeEditorView codeEditor)
        {
            var adapter = codeEditor.Adapter;

            codeEditor.Adapter = null;
            if (null != adapter)
            {
                adapter.Workspace.CloseDocument(adapter.DocumentId);
                if (null == adapter.Workspace.GetOpenDocumentIds().FirstOrDefault()) // dispose workspace if it has no open documents
                {
                    adapter.Workspace.Dispose();
                }
            }
        }
示例#3
0
        protected virtual void OnUnloaded()
        {
            DocumentChanged               = null;
            CaretPositionChanged          = null;
            quickClassBrowser.JumpAction -= EhQuickClassBrowser_JumpTo;
            Adapter  = null;
            Document = null;

            primaryTextEditor   = null;
            secondaryTextEditor = null;
            activeTextEditor    = null;
            quickClassBrowser   = null;
            Children.Clear();
        }
示例#4
0
        public CodeEditor()
        {
            //CodeEditorOptions.Instance.PropertyChanged += CodeEditorOptions_Instance_PropertyChanged;
            //CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged;
            //ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated;

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

            //textMarkerService = new TextMarkerService(this);
            //iconBarManager = new IconBarManager();
            //if (CodeEditorOptions.Instance.EnableChangeMarkerMargin)
            //{
            //	changeWatcher = new DefaultChangeWatcher();
            //}
            primaryTextEditor = CreateTextEditor();
            //primaryTextEditorAdapter = (CodeEditorAdapter)primaryTextEditor.TextArea.GetService(typeof(ITextEditor));
            //Debug.Assert(primaryTextEditorAdapter != null);
            activeTextEditor = primaryTextEditor;

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

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

            quickClassBrowser             = new QuickClassBrowser();
            quickClassBrowser.JumpAction += EhQuickClassBrowser_JumpTo;
            Children.Add(quickClassBrowser);

            Children.Add(primaryTextEditor);

            Unloaded += (s, e) => OnUnloaded();
        }
示例#5
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()
        {
            var codeEditorView = new CodeEditorView();

            //CodeEditorAdapter adapter = new CodeEditorAdapter(this, codeEditorView);
            //codeEditorView.Adapter = adapter;
            var textView = codeEditorView.TextArea.TextView;

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

            //codeEditorView.TextArea.TextEntering += TextAreaTextEntering;
            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.TextCopied           += textEditor_TextArea_TextCopied;
            codeEditorView.GotFocus += textEditor_GotFocus;

            return(codeEditorView);
        }
示例#6
0
        /// <summary>
        /// Gets a new instance of the code editor view. This is the lowest level code editor control.
        /// </summary>
        /// <param name="workspace">The workspace (contains solution, project and referenced assemblies).</param>
        /// <param name="initialText">The initial code text.</param>
        /// <param name="fontFamily">The font family used for the code editor.</param>
        /// <param name="fontSize">Size of the font used for the code editor.</param>
        /// <returns>New instance of the code editor view.</returns>
        /// <exception cref="ArgumentNullException">workspace</exception>
        public CodeEditorView NewCodeEditorView(AltaxoWorkspaceBase workspace, string initialText, FontFamily fontFamily = null, double?fontSize = null)
        {
            if (null == workspace)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            var editor = new CodeEditorView();

            editor.Document.Text = initialText;

            editor.FontFamily = fontFamily ?? _defaultFont;
            editor.FontSize   = fontSize ?? _defaultFontSize;

            // create the source text container that is connected with this editor
            var sourceTextContainer = new RoslynSourceTextContainerAdapter(editor.Document, editor);

            var document = workspace.CreateAndOpenDocument(sourceTextContainer, sourceTextContainer.UpdateText);

            editor.Adapter = new CodeEditorViewAdapterCSharp(workspace, document.Id, sourceTextContainer);
            editor.Document.UndoStack.ClearAll();

            return(editor);
        }