예제 #1
0
            protected override async Task OnLoad()
            {
                var text = await TextFileUtility.GetTextAsync(FilePath, CancellationToken.None);

                MimeType = (await Runtime.GetService <DesktopService> ()).GetMimeTypeForUri(FilePath);
                var contentType = (MimeType == null) ? PlatformCatalog.Instance.TextBufferFactoryService.InertContentType : GetContentTypeFromMimeType(FilePath, MimeType);

                if (textDocument != null)
                {
                    // Reloading
                    try {
                        FreezeChangeEvent();
                        OnSetText(text.Text);
                        if (textDocument.TextBuffer.ContentType != contentType)
                        {
                            textDocument.TextBuffer.ChangeContentType(contentType, null);
                        }
                        textDocument.Encoding = text.Encoding;
                        textDocument.UpdateDirtyState(false, System.IO.File.GetLastWriteTime(FilePath));
                    } finally {
                        ThawChangeEvent();
                    }
                }
                else
                {
                    var buffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer(text.Text, contentType);
                    var doc    = PlatformCatalog.Instance.TextDocumentFactoryService.CreateTextDocument(buffer, FilePath);
                    doc.Encoding = text.Encoding;
                    SetTextDocument(doc);
                }
                Encoding               = textDocument.Encoding;
                UseByteOrderMark       = text.HasByteOrderMark;
                cleanReiteratedVersion = textDocument.TextBuffer.CurrentSnapshot.Version.ReiteratedVersionNumber;
                HasUnsavedChanges      = false;
            }
예제 #2
0
        async Task <TextAndVersion> GetTextAndVersion(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!File.Exists(fileName))
            {
                var document = ((MonoDevelopWorkspace)workspace).GetDocument(documentId);
                if (document == null)
                {
                    return(null);
                }
                return(TextAndVersion.Create(await document.GetTextAsync(cancellationToken), VersionStamp.Create()));
            }
            SourceText text;

            if (workspace.IsDocumentOpen(documentId))
            {
                text = new MonoDevelopSourceText(TextFileProvider.Instance.GetTextEditorData(fileName).CreateDocumentSnapshot());
            }
            else
            {
                text = SourceText.From(await TextFileUtility.GetTextAsync(fileName, cancellationToken));
            }
            return(TextAndVersion.Create(text, VersionStamp.Create()));
        }
예제 #3
0
        async Task LoadNew()
        {
            textEditor.MimeType = MimeType;
            string text = null;
            var    res  = await TextFileUtility.GetTextAsync(FileModel.GetContent());

            text = textEditor.Text = res.Text;
            textEditor.Encoding = res.Encoding;
            await RunFirstTimeFoldUpdate(text);

            textEditorImpl.InformLoadComplete();
        }
예제 #4
0
        public override async Task LoadNew(Stream content, string mimeType)
        {
            textEditor.MimeType = mimeType;
            string text = null;

            if (content != null)
            {
                var res = await TextFileUtility.GetTextAsync(content);

                text = textEditor.Text = res.Text;
                textEditor.Encoding = res.Encoding;
            }
            await RunFirstTimeFoldUpdate(text);

            textEditorImpl.InformLoadComplete();
        }
예제 #5
0
        public override async Task <TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            SourceText text;

            if (IdeApp.Workbench?.Documents.Any(doc => FilePath.PathComparer.Compare(doc.FileName, fileName) == 0) == true)
            {
                text = new MonoDevelopSourceText(TextFileProvider.Instance.GetTextEditorData(fileName).CreateDocumentSnapshot());
            }
            else
            {
                if (!File.Exists(fileName))
                {
                    return(TextAndVersion.Create(SourceText.From(""), VersionStamp.Create()));
                }
                text = SourceText.From(await TextFileUtility.GetTextAsync(fileName, cancellationToken).ConfigureAwait(false));
            }
            return(TextAndVersion.Create(text, VersionStamp.Create()));
        }