private async Task <ITextDocumentTabViewModel> OpenDocumentAsync(ISourceFile file) { var shell = IoC.Get <IShell>(); var currentTab = shell.Documents.OfType <ITextDocumentTabViewModel>().FirstOrDefault(t => t.SourceFile?.FilePath == file.FilePath); if (currentTab == null) { var provider = IoC.Get <IStudio>().EditorProviders.FirstOrDefault(p => p.Value.CanEdit(file))?.Value; if (provider != null) { currentTab = await provider.CreateViewModel(file); } else { var document = await AvalonStudioTextDocument.CreateAsync(file); currentTab = new TextEditorViewModel(document, file); } } shell.AddOrSelectDocument(currentTab); return(currentTab); }
public async Task <ITextDocumentTabViewModel> CreateViewModel(ISourceFile file) { if (file is MetaDataFile metaDataFile) { return(new CodeEditorViewModel(AvalonStudioTextDocument.Create(await metaDataFile.GetTextAsync()), file) { IsReadOnly = true }); } throw new NotSupportedException(); }
private TestEditorManager(string initialText, IEnumerable <ITextEditorInputHelper> helpers = null) { Document = AvalonStudioTextDocument.Create(initialText); Editor = new TextEditorViewModel(Document, null); if (helpers != null) { foreach (var helper in helpers) { (Editor as TextEditorViewModel).InputHelpers.Add(helper); } } Document.Changed += (sender, e) => { if (e.Offset <= Editor.Offset) { SetCursor(Editor.Offset + e.InsertionLength - e.RemovalLength); } }; }
public Task <ITextDocument> CreateDocumentAsync(string path) { return(AvalonStudioTextDocument.CreateAsync(path)); }