internal void Add(ITabGroup group, DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShown) { Debug.Assert(TabGroupService.TabGroups.Contains(group)); var tab = OpenEmptyTab(group); tab.Show(tabContent, uiState, onShown); }
void GoToReference(DocumentTabContent content, object @ref, MethodDef method, uint ilOffset, bool center) { if (!GoToReferenceCore(content, method, ilOffset, center)) { GoToReference(content, @ref, center); } }
void FollowReferenceCore(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown) { var result = TryCreateContentFromReference(@ref, sourceContent); if (result != null) { Show(result.DocumentTabContent, result.UIState, e => { // Call the original caller (onShown()) first and result last since both could // move the caret. The result should only move the caret if the original caller // hasn't moved the caret. onShown?.Invoke(e); result.OnShownHandler?.Invoke(e); }); } else { var defaultContent = TryCreateDefaultContent(); if (defaultContent != null) { Show(defaultContent, null, e => { onShown?.Invoke(new ShowTabContentEventArgs(ShowTabContentResult.Failed, this)); }); } else { onShown?.Invoke(new ShowTabContentEventArgs(ShowTabContentResult.Failed, this)); } } }
public void FollowReference(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown) { if (NotifyReferenceHandlers(@ref, Content, onShown)) { return; } FollowReferenceCore(@ref, sourceContent, onShown); }
public void OverwriteCurrent(DocumentTabContent content) { if (content == null) { throw new ArgumentNullException(nameof(content)); } this.current = content; }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { if (content is AboutScreenDocumentTabContent) { return(GUID_SerializedContent); } return(null); }
public void SetCurrent(DocumentTabContent content, bool saveCurrent) { if (saveCurrent && current != null) { oldList.Add(new TabContentState(current, current.DocumentTab.UIContext.CreateUIState())); } current = content ?? throw new ArgumentNullException(nameof(content)); newList.Clear(); }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { if (content is AssemblyChildNodeTabContent) { // There's nothing else we need to serialize it, but if there were, use 'section' // to write the info needed by Deserialize() above. return(GUID_SerializedContent); } return(null); }
void ShowInternal(DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh) { Debug.Assert(asyncWorkerContext == null); UIContext = tabContent.CreateUIContext(documentTabUIContextLocator); var cachedUIContext = UIContext; Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this); cachedUIContext.DocumentTab = this; Debug.Assert(cachedUIContext.DocumentTab == this); Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this); tabContent.DocumentTab = this; Debug.Assert(tabContent.DocumentTab == this); UpdateTitleAndToolTip(); DnSpyEventSource.Log.ShowDocumentTabContentStart(); var showCtx = new ShowContext(cachedUIContext, isRefresh); tabContent.OnShow(showCtx); bool asyncShow = false; if (tabContent is AsyncDocumentTabContent asyncTabContent) { if (asyncTabContent.NeedAsyncWork(showCtx)) { asyncShow = true; var ctx = new AsyncWorkerContext(); asyncWorkerContext = ctx; var asyncShowCtx = new AsyncShowContext(showCtx, ctx); Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken) .ContinueWith(t => { bool canShowAsyncOutput = ctx == asyncWorkerContext && cachedUIContext.DocumentTab == this && UIContext == cachedUIContext; if (asyncWorkerContext == ctx) { asyncWorkerContext = null; } ctx.Dispose(); asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput)); bool success = !t.IsFaulted && !t.IsCanceled; OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } else { asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult()); } } if (!asyncShow) { OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent); } documentTabService.OnNewTabContentShown(this); }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { var dc = content as HexDocumentTabContent; if (dc == null) { return(null); } return(GUID_SerializedContent); }
public void Show(DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShown) { if (tabContent == null) { throw new ArgumentNullException(nameof(tabContent)); } Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this); HideCurrentContent(); Content = tabContent; ShowInternal(tabContent, uiState, onShown, false); }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { var hb = content as HexViewDocumentTabContent; if (hb == null) { return(null); } section.Attribute("filename", hb.Filename); return(GUID_SerializedContent); }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { var dc = content as DecompileDocumentTabContent; if (dc == null) { return(null); } section.Attribute("Language", dc.Decompiler.UniqueGuid); return(GUID_SerializedContent); }
DocumentTabReferenceResult TryCreateContentFromReference(object @ref, DocumentTabContent sourceContent) { foreach (var f in referenceDocumentTabContentProviders) { var c = f.Value.Create(DocumentTabService, sourceContent, @ref); if (c != null) { return(c); } } return(null); }
public void SetCurrent(DocumentTabContent content, bool saveCurrent) { if (saveCurrent && !(current is null)) { oldList.Add(new TabContentState(current, current.DocumentTab?.UIContext.CreateUIState())); } current = content ?? throw new ArgumentNullException(nameof(content)); foreach (var state in newList) { Dispose(state.DocumentTabContent); } newList.Clear(); }
public void FollowReference(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown) { if (removed) { onShown(new ShowTabContentEventArgs(ShowTabContentResult.Failed, this)); return; } if (NotifyReferenceHandlers(@ref, Content, onShown)) { return; } FollowReferenceCore(@ref, sourceContent, onShown); }
bool NotifyReferenceHandlers(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown) { var context = new ReferenceHandlerContext(@ref, Content, sourceContent); foreach (var lz in referenceHandlers) { if (lz.Value.OnFollowReference(context)) { onShown?.Invoke(new ShowTabContentEventArgs(ShowTabContentResult.ReferenceHandler, this)); return(true); } } return(false); }
public object NavigateForward() { Debug.Assert(CanNavigateForward); if (newList.Count == 0) { return(null); } var old = newList[newList.Count - 1]; newList.RemoveAt(newList.Count - 1); oldList.Add(new TabContentState(current, current.DocumentTab.UIContext.CreateUIState())); current = old.DocumentTabContent; return(old.UIState); }
public Guid?Serialize(DocumentTabContent content, ISettingsSection section) { var nodes = content.Nodes.ToArray(); var context = new DocumentTabContentFactoryContext(nodes); foreach (var factory in tabContentFactories) { var guid = factory.Value.Serialize(content, section); if (guid != null) { return(guid); } } return(null); }
public void Dispose() { foreach (var state in oldList) { Dispose(state.DocumentTabContent); } oldList.Clear(); foreach (var state in newList) { Dispose(state.DocumentTabContent); } newList.Clear(); Dispose(current); current = null; }
void GoToReference(DocumentTabContent content, object @ref, bool center) { Debug.Assert(IsSupportedReference(@ref)); var uiCtx = content.DocumentTab.UIContext as IDocumentViewer; if (uiCtx == null) { return; } var options = MoveCaretOptions.Select | MoveCaretOptions.Focus; if (center) { options |= MoveCaretOptions.Center; } uiCtx.MoveCaretToReference(@ref, options); }
DocumentTabReferenceResult CreateLocalRefResult(DocumentTabContent sourceContent, TextReference textRef) { Debug.Assert(IsSupportedReference(textRef)); if (sourceContent == null) { return(null); } if (!sourceContent.CanClone) { return(null); } var content = sourceContent.Clone(); return(new DocumentTabReferenceResult(content, null, a => { if (a.Success && !a.HasMovedCaret) { GoToReference(content, textRef, false); a.HasMovedCaret = true; } })); }
bool GoToReferenceCore(DocumentTabContent content, MethodDef method, uint ilOffset, bool center) { var uiCtx = content.DocumentTab.UIContext as IDocumentViewer; if (uiCtx == null) { return(false); } var methodDebugService = uiCtx.GetMethodDebugService(); if (methodDebugService == null) { return(false); } var info = methodDebugService.TryGetMethodDebugInfo(method); if (info == null) { return(false); } var sourceStatement = info.GetSourceStatementByCodeOffset(ilOffset); if (sourceStatement == null) { return(false); } var options = MoveCaretOptions.Select | MoveCaretOptions.Focus; if (center) { options |= MoveCaretOptions.Center; } uiCtx.MoveCaretToPosition(sourceStatement.Value.TextSpan.Start, options); return(true); }
public TabContentState(DocumentTabContent documentTabContent, object?uiState) { DocumentTabContent = documentTabContent; UIState = uiState; }
bool CheckRemove(DocumentTabContent content, HashSet <DsDocumentNode> removedDocuments) => content.Nodes.Any(a => removedDocuments.Contains(a.GetDocumentNode()));
public DocumentTabReferenceResult Create(IDocumentTabService documentTabService, DocumentTabContent sourceContent, object @ref) { var textRef = @ref as TextReference; if (textRef != null) { if (textRef.Reference is IAssembly || textRef.Reference is ModuleDef || textRef.Reference is ModuleRef || textRef.Reference is NamespaceReference) { return(null); } var result = CreateMemberRefResult(documentTabService, textRef.Reference); if (result != null) { return(result); } return(CreateLocalRefResult(sourceContent, textRef)); } return(CreateMemberRefResult(documentTabService, @ref)); }
public ReferenceHandlerContext(object @ref, DocumentTabContent content, DocumentTabContent sourceContent) { Reference = @ref; Content = content; SourceContent = sourceContent; }
public DocumentTabReferenceResult Create(IDocumentTabService documentTabService, DocumentTabContent sourceContent, object @ref) { var addrRef = @ref as AddressReference; if (addrRef == null) { addrRef = (@ref as TextReference)?.Reference as AddressReference; } if (addrRef != null) { return(Create(addrRef, documentTabService.DocumentTreeView)); } return(null); }
public void OverwriteCurrent(DocumentTabContent content) { Dispose(current); current = content ?? throw new ArgumentNullException(nameof(content)); }
public DocumentTabReferenceResult Create(IDocumentTabService documentTabService, DocumentTabContent sourceContent, object @ref) { if (@ref is TextReference textRef) { @ref = textRef.Reference; } if (@ref is DocumentTreeNodeData node) { return(Create(node)); } if (@ref is NamespaceRef nsRef) { return(Create(nsRef)); } if (@ref is NamespaceReference nsRef2) { return(Create(nsRef2)); } if (@ref is IDsDocument document) { return(Create(document)); } if (@ref is AssemblyDef asm) { return(Create(asm)); } if (@ref is ModuleDef mod) { return(Create(mod)); } if (@ref is IAssembly asmRef) { document = documentTreeView.DocumentService.Resolve(asmRef, null); if (document != null) { return(Create(document)); } } return(null); }