private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _roslynHost = _viewModel.MainViewModel.RoslynHost; _viewModel.MainViewModel.EditorFontSizeChanged += OnEditorFontSizeChanged; Editor.FontSize = _viewModel.MainViewModel.EditorFontSize; var avalonEditTextContainer = new AvalonEditTextContainer(Editor); await _viewModel.Initialize( avalonEditTextContainer, a => _syncContext.Post(o => ProcessDiagnostics(a), null), text => avalonEditTextContainer.UpdateText(text), this).ConfigureAwait(true); var documentText = await _viewModel.LoadText().ConfigureAwait(true); Editor.AppendText(documentText); Editor.Document.UndoStack.ClearAll(); Editor.Document.TextChanged += (o, e) => _viewModel.SetDirty(Editor.Document.TextLength); Editor.TextArea.TextView.LineTransformers.Insert(0, new RoslynHighlightingColorizer(_viewModel.DocumentId, _roslynHost)); _contextActionsRenderer = new ContextActionsRenderer(Editor, _textMarkerService); _contextActionsRenderer.Providers.Add(new RoslynContextActionProvider(_viewModel.DocumentId, _roslynHost)); Editor.CompletionProvider = new RoslynCodeEditorCompletionProvider(_viewModel.DocumentId, _roslynHost); }
private async void OnDataContextChanged(object?sender, EventArgs args) { _viewModel = (OpenDocumentViewModel)DataContext; if (_viewModel == null) { return; } _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _viewModel.EditorFocus += (o, e) => _editor.Focus(); _viewModel.MainViewModel.EditorFontSizeChanged += size => _editor.FontSize = size; _editor.FontSize = _viewModel.MainViewModel.EditorFontSize; var documentText = await _viewModel.LoadText().ConfigureAwait(true); var documentId = _editor.Initialize(_viewModel.MainViewModel.RoslynHost, new ClassificationHighlightColors(), _viewModel.WorkingDirectory, documentText); _viewModel.Initialize(documentId, OnError, () => new TextSpan(_editor.SelectionStart, _editor.SelectionLength), this); _editor.Document.TextChanged += (o, e) => _viewModel.OnTextChanged(); }
private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.ResultsAvailable += ResultsAvailable; _viewModel.ReadInput += OnReadInput; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _viewModel.EditorFocus += (o, e) => Editor.Focus(); _viewModel.DocumentUpdated += (o, e) => Dispatcher.InvokeAsync(() => Editor.RefreshHighlighting()); _viewModel.OutputMessageReceived += s => { ShowBottomPaneRow(); BottomTabs.SelectedItem = OutputTab; OutputText.AppendText($"{DateTime.Now:dd/MM/yyyy HH:mm:ss.fff} - {s}{Environment.NewLine}"); OutputText.ScrollToEnd(); }; _viewModel.ConsoleMessageReceived += (s, t) => { ConsoleTextType consoleTextType; string separator; if (t == ConsoleMessageType.Err) { separator = "!"; consoleTextType = ConsoleTextType.Error; } else { consoleTextType = ConsoleTextType.Output; separator = ">"; } WriteConsole(s, consoleTextType, separator); }; _viewModel.ExecutionStarted += s => { _viewModel.Dispatcher.InvokeAsync(() => WriteConsole($"['{s}.csx' code Execution Started]", ConsoleTextType.Information, "-")); }; _viewModel.BuildStarted += () => OutputText.Clear(); _viewModel.MainViewModel.EditorFontSizeChanged += OnEditorFontSizeChanged; Editor.FontSize = _viewModel.MainViewModel.EditorFontSize; var documentText = await _viewModel.LoadText().ConfigureAwait(true); var documentId = Editor.Initialize( _viewModel.MainViewModel.RoslynHost, new ClassificationHighlightColors(), _viewModel.WorkingDirectory, documentText); _viewModel.Initialize( documentId, OnError, () => new TextSpan(Editor.SelectionStart, Editor.SelectionLength), this); Editor.Document.TextChanged += (o, e) => _viewModel.OnTextChanged(); }
private async void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { _viewModel = (OpenDocumentViewModel)args.NewValue; _viewModel.ResultsAvailable += ResultsAvailable; _viewModel.NuGet.PackageInstalled += NuGetOnPackageInstalled; _viewModel.EditorFocus += (o, e) => Editor.Focus(); _viewModel.MainViewModel.EditorFontSizeChanged += OnEditorFontSizeChanged; Editor.FontSize = _viewModel.MainViewModel.EditorFontSize; var documentText = await _viewModel.LoadText().ConfigureAwait(true); var documentId = Editor.Initialize(_viewModel.MainViewModel.RoslynHost, new ClassificationHighlightColors(), _viewModel.WorkingDirectory, documentText); _viewModel.Initialize(documentId, OnError, () => new TextSpan(Editor.SelectionStart, Editor.SelectionLength), this); Editor.Document.TextChanged += (o, e) => _viewModel.SetDirty(); }