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);
        }
Beispiel #2
0
        public void CreateNewDocument()
        {
            var openDocument = new OpenDocumentViewModel(this, null);

            OpenDocuments.Add(openDocument);
            CurrentOpenDocument = openDocument;
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        public async Task CloseDocument(OpenDocumentViewModel document)
        {
            if (document == null)
            {
                return;
            }

            var result = await document.Save(promptSave : true).ConfigureAwait(true);

            if (result == SaveResult.Cancel)
            {
                return;
            }

            // ReSharper disable once PossibleNullReferenceException
            var autoSavePath = document.Document?.GetAutoSavePath();

            if (autoSavePath != null && File.Exists(autoSavePath))
            {
                File.Delete(autoSavePath);
            }

            RoslynHost.CloseDocument(document.DocumentId);
            OpenDocuments.Remove(document);
            document.Close();
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        public void OpenDocument(DocumentViewModel document)
        {
            var openDocument = OpenDocuments.FirstOrDefault(x => x.Document == document);

            if (openDocument == null)
            {
                openDocument = new OpenDocumentViewModel(this, document);
                OpenDocuments.Add(openDocument);
            }
            CurrentOpenDocument = openDocument;
        }
Beispiel #7
0
        public async Task CloseDocument(OpenDocumentViewModel document)
        {
            var result = await document.Save(promptSave : true).ConfigureAwait(true);

            if (result == SaveResult.Cancel)
            {
                return;
            }
            if (document.Document?.IsAutoSave == true)
            {
                File.Delete(document.Document.Path);
            }
            RoslynHost.CloseDocument(document.DocumentId);
            OpenDocuments.Remove(document);
            document.Close();
        }
Beispiel #8
0
        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();
        }