public SampleErrorListViewModel() : base(new MockErrorListView(), new MockDocumentService(), null, null) { var documentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", ""); documentFile.Content.ErrorList = new[] { new ErrorListItem(ErrorSeverity.Info, "Info", 0, 0, 0, 0), new ErrorListItem(ErrorSeverity.Warning, "Warning", 3, 13, 3, 13), new ErrorListItem(ErrorSeverity.Error, "Error", 20, 8, 20, 8) }; DocumentService.ActiveDocumentFile = documentFile; }
public SampleCodeEditorViewModel() : base(new MockCodeEditorView(), new MockShellService(), null, null) { var code = @"using System; using System.Linq; namespace Sample { internal static class Program { internal static void Main() { Console.WriteLine(""Hello World""); } } }"; DocumentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", code); }
public void ClearOutput(DocumentFile document) { }
private void SaveCore(DocumentFile document, string fileName) { try { using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { using (var writer = new StreamWriter(stream, Encoding.UTF8)) { writer.Write(document.Content.Code); } } document.FileName = fileName; document.ResetModified(); } catch (Exception e) { Trace.TraceError(e.ToString()); messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.SaveFileError, fileName)); } }
private void ResetBuildResult(DocumentFile documentFile) { if (lastBuildResult != null && lastBuildResult.Item1 == documentFile) { lastBuildResult = null; } }
public void RemoveDocument(DocumentFile document) { documentFiles.Remove(document); }
private DocumentDataModel CreateDocumentDataModel(DocumentFile documentFile) { return new DocumentDataModel(documentFile, new Lazy<object>(() => CreateDocumentViewModel(documentFile).View)); }
private void RemoveProject(DocumentFile documentFile) { DocumentId documentId; if (documentIds.TryGetValue(documentFile, out documentId)) { workspace.RemoveProject(documentId); } documentIds.Remove(documentFile); ResetBuildResult(documentFile); }
private void Save(DocumentFile document) { if (Path.IsPathRooted(document.FileName)) { SaveCore(document, document.FileName); } else { SaveAs(document); } }
public SetCaretEventArgs(DocumentFile documentFile, int line, int column) { DocumentFile = documentFile; Line = line; Column = column; }
public void AppendErrorText(DocumentFile document, string text) { outputParagraphs[document].Inlines.Add(new Run(text) { Foreground = (Brush)FindResource("ErrorForeground") }); }
public void ClearOutput(DocumentFile document) { outputParagraphs[document].Inlines.Clear(); }
public void AppendOutputText(DocumentFile document, string text) { outputParagraphs[document].Inlines.Add(text); }
public PerformanceTrace(string name, DocumentFile document) : this(document.FileName + ": " + name) { }
private CodeEditorViewModel CreateDocumentViewModel(DocumentFile document) { var viewModel = codeEditorViewModelFactory.CreateExport().Value; viewModel.DocumentFile = document; return viewModel; }
private void FileServicePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(IFileService.ActiveDocumentFile)) { if (lastActiveDocumentFile != null) { PropertyChangedEventManager.RemoveHandler(lastActiveDocumentFile, ActiveDocumentPropertyChanged, ""); } lastActiveDocumentFile = ActiveDocumentFile; if (lastActiveDocumentFile != null) { PropertyChangedEventManager.AddHandler(lastActiveDocumentFile, ActiveDocumentPropertyChanged, ""); } UpdateCommands(); } else if (e.PropertyName == nameof(IFileService.LockedDocumentFile)) { UpdateCommands(); } }
public void SetCaret(DocumentFile documentFile, int line, int column) { OnRequestSetCaret(new SetCaretEventArgs(documentFile, line, column)); }
public void UpdateText(DocumentFile documentFile, string text) { if (documentFile.Content.Code == text) { return; } var documentId = documentIds[documentFile]; workspace.UpdateText(documentId, text); documentFile.Content.Code = text; ResetBuildResult(documentFile); updateDiagnosticsAction.InvokeAccumulated(); }
private void SaveAs(DocumentFile document) { FileType fileType = document.DocumentType == DocumentType.CSharp ? cSharpFileType : visualBasicFileType; string fileName = Path.GetFileNameWithoutExtension(document.FileName); FileDialogResult result = fileDialogService.ShowSaveFileDialog(shellService.ShellView, fileType, fileName); if (result.IsValid) { SaveCore(document, result.FileName); } }
public DocumentDataModel(DocumentFile documentFile, Lazy<object> lazyCodeEditorView) { DocumentFile = documentFile; LazyCodeEditorView = lazyCodeEditorView; }
public Document GetDocument(DocumentFile documentFile) { var documentId = documentIds[documentFile]; return workspace.CurrentSolution.GetDocument(documentId); }
private void NewCore(DocumentType documentType, string code = null) { int startCaretPosition = 0; if (string.IsNullOrEmpty(code)) { code = documentType == DocumentType.CSharp ? TemplateCode.InitialCSharpCode : TemplateCode.InitialVisualBasicCode; startCaretPosition = documentType == DocumentType.CSharp ? TemplateCode.StartCaretPositionCSharp : TemplateCode.StartCaretPositionVisualBasic; } string fileName = "Script" + (documentCounter + 1) + (documentType == DocumentType.CSharp ? ".cs" : ".vb"); var document = new DocumentFile(documentType, fileName, code, startCaretPosition); document.ResetModified(); fileService.AddDocument(document); ActiveDocumentFile = document; documentCounter++; }
private async void AddProject(DocumentFile documentFile) { await TaskHelper.WaitForProperty(documentFile, x => x.IsContentLoaded); using (new PerformanceTrace("AddProjectWithDocument", documentFile)) { var documentId = workspace.AddProjectWithDocument(documentFile.FileName, documentFile.Content != null ? documentFile.Content.Code : ""); documentIds.Add(documentFile, documentId); updateDiagnosticsAction.InvokeAccumulated(); } }
private void CloseCore(DocumentFile document) { if (!PrepareToClose(new[] { document })) { return; } if (ActiveDocumentFile == document) { var nextDocument = CollectionHelper.GetNextElementOrDefault(fileService.DocumentFiles, ActiveDocumentFile) ?? fileService.DocumentFiles.Take(fileService.DocumentFiles.Count - 1).LastOrDefault(); ActiveDocumentFile = nextDocument; } fileService.RemoveDocument(document); }
private async void StartScript() { var documentFile = documentService.ActiveDocumentFile; runScriptCancellation = new CancellationTokenSource(); var cancellationToken = runScriptCancellation.Token; RunningDocument = documentFile; startCommand.RaiseCanExecuteChanged(); stopCommand.RaiseCanExecuteChanged(); OutputViewModel.ClearOutput(documentFile); if (lastBuildResult == null || lastBuildResult.Item1 != documentFile) { using (new PerformanceTrace("BuildAsync", documentFile)) { var result = await workspace.BuildAsync(documentIds[documentFile], CancellationToken.None); documentFile.Content.ErrorList = result.Diagnostic.Where(x => x.Severity != DiagnosticSeverity.Hidden).Select(CreateErrorListItem).ToArray(); if (result.InMemoryAssembly != null) { lastBuildResult = new Tuple<DocumentFile, BuildResult>(documentFile, result); } else { lastBuildResult = null; } } } if (lastBuildResult != null) { using (new PerformanceTrace("RunScriptAsync", documentFile)) { var buildResult = lastBuildResult.Item2; try { await host.RunScriptAsync(buildResult.InMemoryAssembly, buildResult.InMemorySymbolStore, outputTextWriter, errorTextWriter, cancellationToken); } catch (OperationCanceledException) { } } ShellViewModel.IsOutputViewVisible = true; } else { ShellViewModel.IsErrorListViewVisible = true; } RunningDocument = null; runScriptCancellation = null; startCommand.RaiseCanExecuteChanged(); stopCommand.RaiseCanExecuteChanged(); }
private void CloseAll() { if (!PrepareToClose(fileService.DocumentFiles)) { return; } ActiveDocumentFile = null; fileService.ClearDocuments(); }
public void AddDocument(DocumentFile document) { documentFiles.Add(document); }
private DocumentFile OpenCore(string fileName = null, bool setActiveDocument = true) { if (string.IsNullOrEmpty(fileName)) { FileDialogResult result = fileDialogService.ShowOpenFileDialog(shellService.ShellView, allFilesType); if (result.IsValid) { fileName = result.FileName; } } if (string.IsNullOrEmpty(fileName)) { return null; } // Check if document is already opened DocumentFile document = fileService.DocumentFiles.SingleOrDefault(d => d.FileName == fileName); if (document == null) { string fileExtension = Path.GetExtension(fileName); if (!new[] { ".cs", ".vb" }.Contains(fileExtension)) { Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "The extension of the file '{0}' is not supported.", fileName)); messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.OpenFileUnsupportedExtension, fileName)); return null; } var documentType = fileExtension == ".cs" ? DocumentType.CSharp : DocumentType.VisualBasic; document = new DocumentFile(documentType, LoadDocumentContent) { FileName = fileName }; fileService.AddDocument(document); } if (setActiveDocument) { ActiveDocumentFile = document; } return document; }
private DocumentContent LoadDocumentContent(DocumentFile documentFile) { Trace.WriteLine(">> Load document content: " + documentFile.FileName); using (var stream = new FileStream(documentFile.FileName, FileMode.Open, FileAccess.Read)) { using (var reader = new StreamReader(stream, Encoding.UTF8)) { var documentContent = new DocumentContent() { Code = reader.ReadToEnd() }; documentFile.ResetModified(); return documentContent; } } }
public void AppendErrorText(DocumentFile document, string text) { }