public override void OnShowAsync(IShowContext ctx, IAsyncShowResult result) { var decompileContext = (DecompileContext)ctx.Tag !; var documentViewer = (IDocumentViewer)ctx.UIContext; Debug2.Assert(decompileContext.DecompileNodeContext is not null); Debug2.Assert(decompileContext.DocumentViewerContentFactory is not null); var contentType = decompileContext.DecompileNodeContext.ContentType; if (contentType is null) { var contentTypeString = decompileContext.DecompileNodeContext.ContentTypeString; if (contentTypeString is null) { contentTypeString = ContentTypesHelper.TryGetContentTypeStringByExtension(decompileContext.DecompileNodeContext.Decompiler.FileExtension) ?? ContentTypes.PlainText; } contentType = decompileDocumentTabContentFactory.ContentTypeRegistryService.GetContentType(contentTypeString) ?? decompileDocumentTabContentFactory.ContentTypeRegistryService.GetContentType(ContentTypes.Text) ?? decompileDocumentTabContentFactory.ContentTypeRegistryService.UnknownContentType; } DocumentViewerContent?content; if (result.IsCanceled) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationCanceled, BoxedTextColor.Error); content = docViewContentFactory.CreateContent(documentViewer, contentType); } else if (result.Exception is not null) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationException, BoxedTextColor.Error); docViewContentFactory.Output.WriteLine(); docViewContentFactory.Output.Write(result.Exception.ToString(), BoxedTextColor.Text); content = docViewContentFactory.CreateContent(documentViewer, contentType); } else { content = decompileContext.CachedContent; if (content is null) { bool canBeCached = decompileContext.DocumentViewerContentFactory.Output.CanBeCached; content = decompileContext.DocumentViewerContentFactory.CreateContent(documentViewer, contentType); if (canBeCached) { decompileDocumentTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Decompiler, nodes, content, contentType); } } } if (result.CanShowOutput) { WasNewContent = documentViewer.SetContent(content, contentType); } else { WasNewContent = false; } }
public void EndAsyncShow(IShowContext ctx, IAsyncShowResult result) { var decompileContext = (DecompileContext)ctx.UserData; var documentViewer = (IDocumentViewer)ctx.UIContext; var contentType = decompileContext.DecompileNodeContext.ContentType; if (contentType == null) { var contentTypeString = decompileContext.DecompileNodeContext.ContentTypeString; if (contentTypeString == null) { contentTypeString = ContentTypesHelper.TryGetContentTypeStringByExtension(decompileContext.DecompileNodeContext.Decompiler.FileExtension) ?? ContentTypes.PlainText; } contentType = decompileDocumentTabContentFactory.ContentTypeRegistryService.GetContentType(contentTypeString); Debug.Assert(contentType != null); } DocumentViewerContent content; if (result.IsCanceled) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationCanceled, BoxedTextColor.Error); content = docViewContentFactory.CreateContent(documentViewer); } else if (result.Exception != null) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationException, BoxedTextColor.Error); docViewContentFactory.Output.WriteLine(); docViewContentFactory.Output.Write(result.Exception.ToString(), BoxedTextColor.Text); content = docViewContentFactory.CreateContent(documentViewer); } else { content = decompileContext.CachedContent; if (content == null) { bool canBeCached = decompileContext.DocumentViewerContentFactory.Output.CanBeCached; content = decompileContext.DocumentViewerContentFactory.CreateContent(documentViewer); if (canBeCached) { decompileDocumentTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Decompiler, nodes, content, contentType); } } } if (result.CanShowOutput) { documentViewer.SetContent(content, contentType); } }
public void EndAsyncShow(IShowContext ctx, IAsyncShowResult result) { var decompileContext = (DecompileContext)ctx.UserData; var uiCtx = (ITextEditorUIContext)ctx.UIContext; IHighlightingDefinition highlighting; if (decompileContext.DecompileNodeContext.HighlightingDefinition != null) { highlighting = decompileContext.DecompileNodeContext.HighlightingDefinition; } else if (decompileContext.DecompileNodeContext.HighlightingExtension != null) { highlighting = HighlightingManager.Instance.GetDefinitionByExtension(decompileContext.DecompileNodeContext.HighlightingExtension); } else { highlighting = decompileContext.DecompileNodeContext.Language.GetHighlightingDefinition(); } AvalonEditTextOutput output; if (result.IsCanceled) { output = new AvalonEditTextOutput(); output.Write(dnSpy_Resources.DecompilationCanceled, TextTokenKind.Error); } else if (result.Exception != null) { output = new AvalonEditTextOutput(); output.Write(dnSpy_Resources.DecompilationException, TextTokenKind.Error); output.WriteLine(); output.Write(result.Exception.ToString(), TextTokenKind.Text); } else { output = decompileContext.CachedOutput; if (output == null) { output = (AvalonEditTextOutput)decompileContext.DecompileNodeContext.Output; decompileFileTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Language, nodes, output, highlighting); } } if (result.CanShowOutput) { uiCtx.SetOutput(output, highlighting); } }
/// <summary> /// Called in the main UI thread after the worker thread has exited or was interrupted /// </summary> /// <param name="ctx">Context</param> /// <param name="result">Result</param> public abstract void OnShowAsync(IShowContext ctx, IAsyncShowResult result);
public void EndAsyncShow(IFileTabUIContext uiContext, object userData, IAsyncShowResult result) { var decompileContext = (DecompileContext)userData; var uiCtx = (ITextEditorUIContext)uiContext; IHighlightingDefinition highlighting; if (decompileContext.DecompileNodeContext.HighlightingDefinition != null) highlighting = decompileContext.DecompileNodeContext.HighlightingDefinition; else if (decompileContext.DecompileNodeContext.HighlightingExtension != null) highlighting = HighlightingManager.Instance.GetDefinitionByExtension(decompileContext.DecompileNodeContext.HighlightingExtension); else highlighting = decompileContext.DecompileNodeContext.Language.GetHighlightingDefinition(); AvalonEditTextOutput output; if (result.IsCanceled) { output = new AvalonEditTextOutput(); output.Write(dnSpy_Resources.DecompilationCanceled, TextTokenKind.Error); } else if (result.Exception != null) { output = new AvalonEditTextOutput(); output.Write(dnSpy_Resources.DecompilationException, TextTokenKind.Error); output.WriteLine(); output.Write(result.Exception.ToString(), TextTokenKind.Text); } else { output = decompileContext.CachedOutput; if (output == null) { output = (AvalonEditTextOutput)decompileContext.DecompileNodeContext.Output; decompileFileTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Language, nodes, output, highlighting); } } if (result.CanShowOutput) uiCtx.SetOutput(output, highlighting); }
public override void OnShowAsync(IShowContext ctx, IAsyncShowResult result) { var decompileContext = (DecompileContext)ctx.Tag; var documentViewer = (IDocumentViewer)ctx.UIContext; var contentType = decompileContext.DecompileNodeContext.ContentType; if (contentType == null) { var contentTypeString = decompileContext.DecompileNodeContext.ContentTypeString; if (contentTypeString == null) contentTypeString = ContentTypesHelper.TryGetContentTypeStringByExtension(decompileContext.DecompileNodeContext.Decompiler.FileExtension) ?? ContentTypes.PlainText; contentType = decompileDocumentTabContentFactory.ContentTypeRegistryService.GetContentType(contentTypeString) ?? decompileDocumentTabContentFactory.ContentTypeRegistryService.GetContentType(ContentTypes.Text) ?? decompileDocumentTabContentFactory.ContentTypeRegistryService.UnknownContentType; } DocumentViewerContent content; if (result.IsCanceled) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationCanceled, BoxedTextColor.Error); content = docViewContentFactory.CreateContent(documentViewer, contentType); } else if (result.Exception != null) { var docViewContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); docViewContentFactory.Output.Write(dnSpy_Resources.DecompilationException, BoxedTextColor.Error); docViewContentFactory.Output.WriteLine(); docViewContentFactory.Output.Write(result.Exception.ToString(), BoxedTextColor.Text); content = docViewContentFactory.CreateContent(documentViewer, contentType); } else { content = decompileContext.CachedContent; if (content == null) { bool canBeCached = decompileContext.DocumentViewerContentFactory.Output.CanBeCached; content = decompileContext.DocumentViewerContentFactory.CreateContent(documentViewer, contentType); if (canBeCached) decompileDocumentTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Decompiler, nodes, content, contentType); } } if (result.CanShowOutput) WasNewContent = documentViewer.SetContent(content, contentType); else WasNewContent = false; }