Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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);
                }
            };
        }
Пример #4
0
 public Task <ITextDocument> CreateDocumentAsync(string path)
 {
     return(AvalonStudioTextDocument.CreateAsync(path));
 }