コード例 #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);
        }
コード例 #2
0
 void GoToReference(DocumentTabContent content, object @ref, MethodDef method, uint ilOffset, bool center)
 {
     if (!GoToReferenceCore(content, method, ilOffset, center))
     {
         GoToReference(content, @ref, center);
     }
 }
コード例 #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));
                }
            }
        }
コード例 #4
0
 public void FollowReference(object @ref, DocumentTabContent sourceContent, Action <ShowTabContentEventArgs> onShown)
 {
     if (NotifyReferenceHandlers(@ref, Content, onShown))
     {
         return;
     }
     FollowReferenceCore(@ref, sourceContent, onShown);
 }
コード例 #5
0
ファイル: TabHistory.cs プロジェクト: formylover/dnSpy-1
 public void OverwriteCurrent(DocumentTabContent content)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     this.current = content;
 }
コード例 #6
0
 public Guid?Serialize(DocumentTabContent content, ISettingsSection section)
 {
     if (content is AboutScreenDocumentTabContent)
     {
         return(GUID_SerializedContent);
     }
     return(null);
 }
コード例 #7
0
ファイル: TabHistory.cs プロジェクト: azureidea/dnSpy-1
 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();
 }
コード例 #8
0
 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);
 }
コード例 #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);
        }
コード例 #10
0
        public Guid?Serialize(DocumentTabContent content, ISettingsSection section)
        {
            var dc = content as HexDocumentTabContent;

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

            return(GUID_SerializedContent);
        }
コード例 #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);
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
 }
コード例 #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();
 }
コード例 #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);
 }
コード例 #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);
        }
コード例 #18
0
ファイル: TabHistory.cs プロジェクト: azureidea/dnSpy-1
        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);
        }
コード例 #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);
        }
コード例 #20
0
ファイル: TabHistory.cs プロジェクト: zst96226/dnSpy
        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;
        }
コード例 #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);
        }
コード例 #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;
                }
            }));
        }
コード例 #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);
        }
コード例 #24
0
 public TabContentState(DocumentTabContent documentTabContent, object?uiState)
 {
     DocumentTabContent = documentTabContent;
     UIState            = uiState;
 }
コード例 #25
0
 bool CheckRemove(DocumentTabContent content, HashSet <DsDocumentNode> removedDocuments) =>
 content.Nodes.Any(a => removedDocuments.Contains(a.GetDocumentNode()));
コード例 #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));
        }
コード例 #27
0
 public ReferenceHandlerContext(object @ref, DocumentTabContent content, DocumentTabContent sourceContent)
 {
     Reference     = @ref;
     Content       = content;
     SourceContent = sourceContent;
 }
コード例 #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);
        }
コード例 #29
0
 public void OverwriteCurrent(DocumentTabContent content)
 {
     Dispose(current);
     current = content ?? throw new ArgumentNullException(nameof(content));
 }
コード例 #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);
 }