public override void OnShow(IShowContext ctx) { // Get the real type, created by CreateUIContext() above. var uiCtx = (AssemblyChildNodeUIContext)ctx.UIContext; // You could initialize some stuff, eg. update its DataContext or whatever uiCtx.Initialize("some input"); // pretend we need to initialize something }
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; } }
public override void OnShow(IShowContext ctx) { UpdateLanguage(); var decompileContext = CreateDecompileContext(ctx); decompileContext.CachedContent = decompileDocumentTabContentFactory.DecompilationCache.Lookup(decompileContext.DecompileNodeContext.Decompiler, nodes, out var contentType); decompileContext.DecompileNodeContext.ContentType = contentType; ctx.Tag = decompileContext; }
public void OnShow(IShowContext ctx) { UpdateLanguage(); var decompileContext = CreateDecompileContext(ctx); IHighlightingDefinition highlighting; decompileContext.CachedOutput = decompileFileTabContentFactory.DecompilationCache.Lookup(decompileContext.DecompileNodeContext.Language, nodes, out highlighting); decompileContext.DecompileNodeContext.HighlightingDefinition = highlighting; ctx.UserData = decompileContext; }
public void OnShow(IShowContext ctx) { UpdateLanguage(); var decompileContext = CreateDecompileContext(ctx); IContentType contentType; decompileContext.CachedContent = decompileFileTabContentFactory.DecompilationCache.Lookup(decompileContext.DecompileNodeContext.Language, nodes, out contentType); decompileContext.DecompileNodeContext.ContentType = contentType; ctx.UserData = decompileContext; }
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 = ContentTypes.TryGetContentTypeStringByExtension(decompileContext.DecompileNodeContext.Language.FileExtension) ?? ContentTypes.PlainText; } contentType = decompileFileTabContentFactory.ContentTypeRegistryService.GetContentType(contentTypeString); Debug.Assert(contentType != null); } DocumentViewerContent content; if (result.IsCanceled) { var docViewerOutput = new DocumentViewerOutput(); docViewerOutput.Write(dnSpy_Resources.DecompilationCanceled, BoxedTextColor.Error); content = CreateContent(documentViewer, docViewerOutput); } else if (result.Exception != null) { var docViewerOutput = new DocumentViewerOutput(); docViewerOutput.Write(dnSpy_Resources.DecompilationException, BoxedTextColor.Error); docViewerOutput.WriteLine(); docViewerOutput.Write(result.Exception.ToString(), BoxedTextColor.Text); content = CreateContent(documentViewer, docViewerOutput); } else { content = decompileContext.CachedContent; if (content == null) { var docViewerOutput = (DocumentViewerOutput)decompileContext.DecompileNodeContext.Output; content = CreateContent(documentViewer, docViewerOutput); if (docViewerOutput.CanBeCached) { decompileFileTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Language, nodes, content, contentType); } } } if (result.CanShowOutput) { documentViewer.SetContent(content, contentType); } }
public override void OnShow(IShowContext ctx) { Debug.Assert(!isVisible); isVisible = true; var documentViewer = (IDocumentViewer)ctx.UIContext; if (cachedDocumentViewerContent == null) { (cachedDocumentViewerContent, cachedContentType) = CreateContent(documentViewer); } documentViewer.SetContent(cachedDocumentViewerContent, cachedContentType); }
public bool CanStartAsyncWorker(IShowContext ctx) { var decompileContext = (DecompileContext)ctx.UserData; if (decompileContext.CachedContent != null) { return(false); } var uiCtx = (IDocumentViewer)ctx.UIContext; uiCtx.ShowCancelButton(dnSpy_Resources.Decompiling, () => decompileContext.CancellationTokenSource.Cancel()); return(true); }
public bool CanStartAsyncWorker(IShowContext ctx) { var decompileContext = (DecompileContext)ctx.UserData; if (decompileContext.CachedOutput != null) { return(false); } var uiCtx = (ITextEditorUIContext)ctx.UIContext; uiCtx.ShowCancelButton(() => decompileContext.CancellationTokenSource.Cancel(), dnSpy_Resources.Decompiling); return(true); }
public override bool NeedAsyncWork(IShowContext ctx) { var decompileContext = (DecompileContext)ctx.Tag; if (decompileContext.CachedContent != null) { return(false); } var uiCtx = (IDocumentViewer)ctx.UIContext; uiCtx.ShowCancelButton(dnSpy_Resources.Decompiling, () => decompileContext.AsyncShowContext.Cancel()); return(true); }
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); } }
public override void OnShowAsync(IShowContext ctx, IAsyncShowResult result) { var decompileContext = (DecompileContext)ctx.Tag !; var documentViewer = (IDocumentViewer)ctx.UIContext; Debug.Assert(!(decompileContext.DecompileNodeContext is null)); Debug.Assert(!(decompileContext.DocumentViewerContentFactory is 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 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); }
void OnShown(object uiState, Action <ShowTabContentEventArgs> onShownHandler, IShowContext showCtx, bool success) { if (uiState != null) { RestoreUIState(uiState); } if (onShownHandler != null || showCtx.OnShown != null) { var e = new ShowTabContentEventArgs(success, this); onShownHandler?.Invoke(e); showCtx.OnShown?.Invoke(e); } }
DecompileContext CreateDecompileContext(IShowContext ctx) { var decompileContext = new DecompileContext(); var decompilationContext = new DecompilationContext(); decompilationContext.CalculateILRanges = true; decompilationContext.GetDisableAssemblyLoad = () => decompileFileTabContentFactory.FileManager.DisableAssemblyLoad(); decompilationContext.IsBodyModified = m => decompileFileTabContentFactory.MethodAnnotations.IsBodyModified(m); var output = new AvalonEditTextOutput(); var dispatcher = Dispatcher.CurrentDispatcher; decompileContext.DecompileNodeContext = new DecompileNodeContext(decompilationContext, language, output, dispatcher); if (ctx.IsRefresh) { decompileContext.SavedRefPos = ((ITextEditorUIContext)ctx.UIContext).SaveReferencePosition(); if (decompileContext.SavedRefPos != null) { ctx.OnShown = e => { if (e.Success && !e.HasMovedCaret) { e.HasMovedCaret = ((ITextEditorUIContext)ctx.UIContext).RestoreReferencePosition(decompileContext.SavedRefPos); if (!e.HasMovedCaret) { ((ITextEditorUIContext)ctx.UIContext).ScrollAndMoveCaretTo(1, 1); e.HasMovedCaret = true; } } }; } } return decompileContext; }
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); }
public ShowRepository(IShowContext showContext, IMapper mapper) { _showCollection = showContext.Show; _mapper = mapper; }
public bool CanStartAsyncWorker(IShowContext ctx) { var decompileContext = (DecompileContext)ctx.UserData; if (decompileContext.CachedOutput != null) return false; var uiCtx = (ITextEditorUIContext)ctx.UIContext; uiCtx.ShowCancelButton(() => decompileContext.CancellationTokenSource.Cancel(), dnSpy_Resources.Decompiling); return true; }
/// <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 OnShow(IShowContext ctx) { }
public void OnShow(IShowContext ctx) { var uiCtx = (ITextEditorUIContext)ctx.UIContext; var output = new AvalonEditTextOutput(); Write(output); uiCtx.SetOutput(output, null); }
public override bool NeedAsyncWork(IShowContext ctx) { var decompileContext = (DecompileContext)ctx.Tag; if (decompileContext.CachedContent != null) return false; var uiCtx = (IDocumentViewer)ctx.UIContext; uiCtx.ShowCancelButton(dnSpy_Resources.Decompiling, () => decompileContext.AsyncShowContext.Cancel()); return true; }
/// <summary> /// Returns true if <see cref="CreateContentAsync(IAsyncShowContext)"/> /// should be called /// </summary> /// <param name="ctx">Context</param> /// <returns></returns> public abstract bool NeedAsyncWork(IShowContext ctx);
public override void OnShow(IShowContext ctx) { var documentViewer = (IDocumentViewer)ctx.UIContext; var contentFactory = documentViewerContentFactoryProvider.Create(); Write(contentFactory.Output); documentViewer.SetContent(contentFactory.CreateContent(documentViewer, aboutContentType), aboutContentType); }
public ShowRepository(IShowContext showContext) { _showContext = showContext; }
public ShowRepository(IShowContext showContext, IOptions <RepositorySettings> settings, ILogger <ShowRepository> logger) { _context = showContext; _logger = logger; _idColumn = settings.Value.IdColumn; }
/// <summary> /// Called to show its content in the UI. Derive from <see cref="AsyncDocumentTabContent"/> to /// create the content in a worker thread. /// </summary> /// <param name="ctx">UI Context created by <see cref="CreateUIContext(IDocumentTabUIContextLocator)"/></param> /// <returns></returns> public virtual void OnShow(IShowContext ctx) { }
public AsyncShowContext(IShowContext showContext, AsyncWorkerContext asyncWorkerContext) { this.showContext = showContext; this.asyncWorkerContext = asyncWorkerContext; }
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; }
public override void OnShow(IShowContext ctx) { UpdateLanguage(); var decompileContext = CreateDecompileContext(ctx); IContentType contentType; decompileContext.CachedContent = decompileDocumentTabContentFactory.DecompilationCache.Lookup(decompileContext.DecompileNodeContext.Decompiler, nodes, out contentType); decompileContext.DecompileNodeContext.ContentType = contentType; ctx.Tag = decompileContext; }
void OnShown(object uiState, Action<ShowTabContentEventArgs> onShownHandler, IShowContext showCtx, ShowTabContentResult result) { if (uiState != null) RestoreUIState(uiState); if (onShownHandler != null || showCtx.OnShown != null) { var e = new ShowTabContentEventArgs(result, this); onShownHandler?.Invoke(e); showCtx.OnShown?.Invoke(e); } }
void OnShown(object serializedUI, Action<ShowTabContentEventArgs> onShownHandler, IShowContext showCtx, bool success) { if (serializedUI != null) Deserialize(serializedUI); if (onShownHandler != null || showCtx.OnShown != null) { var e = new ShowTabContentEventArgs(success, this); if (onShownHandler != null) onShownHandler(e); if (showCtx.OnShown != null) showCtx.OnShown(e); } }
public void AsyncWorker(IShowContext ctx, CancellationTokenSource source) { var decompileContext = (DecompileContext)ctx.UserData; decompileContext.CancellationTokenSource = source; decompileContext.DecompileNodeContext.DecompilationContext.CancellationToken = source.Token; decompileFileTabContentFactory.FileTreeNodeDecompiler.Decompile(decompileContext.DecompileNodeContext, nodes); }
void OnShown(object serializedUI, Action <ShowTabContentEventArgs> onShownHandler, IShowContext showCtx, bool success) { if (serializedUI != null) { Deserialize(serializedUI); } if (onShownHandler != null || showCtx.OnShown != null) { var e = new ShowTabContentEventArgs(success, this); onShownHandler?.Invoke(e); showCtx.OnShown?.Invoke(e); } }
void OnShown(object uiState, Action <ShowTabContentEventArgs> onShownHandler, IShowContext showCtx, ShowTabContentResult result) { if (uiState != null) { RestoreUIState(uiState); } if (onShownHandler != null || showCtx.OnShown != null) { var e = new ShowTabContentEventArgs(result, this); onShownHandler?.Invoke(e); showCtx.OnShown?.Invoke(e); } DnSpyEventSource.Log.ShowDocumentTabContentStop(); }
DecompileContext CreateDecompileContext(IShowContext ctx) { var decompileContext = new DecompileContext(); var decompilationContext = new DecompilationContext(); decompilationContext.CalculateBinSpans = true; decompilationContext.GetDisableAssemblyLoad = () => decompileDocumentTabContentFactory.DocumentService.DisableAssemblyLoad(); decompilationContext.IsBodyModified = m => decompileDocumentTabContentFactory.MethodAnnotations.IsBodyModified(m); var dispatcher = Dispatcher.CurrentDispatcher; decompileContext.DocumentViewerContentFactory = decompileDocumentTabContentFactory.DocumentViewerContentFactoryProvider.Create(); decompileContext.DecompileNodeContext = new DecompileNodeContext(decompilationContext, Decompiler, decompileContext.DocumentViewerContentFactory.Output, decompileDocumentTabContentFactory.DocumentWriterService, dispatcher); if (ctx.IsRefresh) { decompileContext.SavedRefPos = ((IDocumentViewer)ctx.UIContext).SaveReferencePosition(); if (decompileContext.SavedRefPos != null) { ctx.OnShown = e => { if (e.Success && !e.HasMovedCaret) { e.HasMovedCaret = ((IDocumentViewer)ctx.UIContext).RestoreReferencePosition(decompileContext.SavedRefPos); if (!e.HasMovedCaret) { ((IDocumentViewer)ctx.UIContext).MoveCaretToPosition(0); e.HasMovedCaret = true; } } }; } } return decompileContext; }