Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 void GoToReference(DocumentTabContent content, object @ref, MethodDef method, uint ilOffset, bool center)
 {
     if (!GoToReferenceCore(content, method, ilOffset, center))
     {
         GoToReference(content, @ref, center);
     }
 }
Ejemplo n.º 3
0
        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));
                }
            }
        }
Ejemplo n.º 4
0
 public void FollowReference(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown)
 {
     if (NotifyReferenceHandlers(@ref, Content, onShown))
     {
         return;
     }
     FollowReferenceCore(@ref, sourceContent, onShown);
 }
Ejemplo n.º 5
0
 public void OverwriteCurrent(DocumentTabContent content)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     this.current = content;
 }
Ejemplo n.º 6
0
 public Guid?Serialize(DocumentTabContent content, ISettingsSection section)
 {
     if (content is AboutScreenDocumentTabContent)
     {
         return(GUID_SerializedContent);
     }
     return(null);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public Guid?Serialize(DocumentTabContent content, ISettingsSection section)
        {
            var dc = content as HexDocumentTabContent;

            if (dc == null)
            {
                return(null);
            }

            return(GUID_SerializedContent);
        }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 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);
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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;
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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;
                }
            }));
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 public TabContentState(DocumentTabContent documentTabContent, object?uiState)
 {
     DocumentTabContent = documentTabContent;
     UIState            = uiState;
 }
Ejemplo n.º 25
0
 bool CheckRemove(DocumentTabContent content, HashSet <DsDocumentNode> removedDocuments) =>
 content.Nodes.Any(a => removedDocuments.Contains(a.GetDocumentNode()));
Ejemplo n.º 26
0
        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));
        }
Ejemplo n.º 27
0
 public ReferenceHandlerContext(object @ref, DocumentTabContent content, DocumentTabContent sourceContent)
 {
     Reference     = @ref;
     Content       = content;
     SourceContent = sourceContent;
 }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 public void OverwriteCurrent(DocumentTabContent content)
 {
     Dispose(current);
     current = content ?? throw new ArgumentNullException(nameof(content));
 }
Ejemplo n.º 30
0
 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);
 }