public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var node = @ref as IFileTreeNodeData;

            if (node != null)
            {
                return(Create(node));
            }
            var nsRef = @ref as NamespaceRef;

            if (nsRef != null)
            {
                return(Create(nsRef));
            }
            var file = @ref as IDnSpyFile;

            if (file != null)
            {
                return(Create(file));
            }
            var asm = @ref as AssemblyDef;

            if (asm != null)
            {
                return(Create(asm));
            }
            var mod = @ref as ModuleDef;

            if (mod != null)
            {
                return(Create(mod));
            }
            return(null);
        }
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="fileTabContent">New content</param>
		/// <param name="serializedUI">Serialized UI data or null</param>
		/// <param name="onShownHandler">Handler or null</param>
		public FileTabReferenceResult(IFileTabContent fileTabContent, object serializedUI = null, Action<ShowTabContentEventArgs> onShownHandler = null) {
			if (fileTabContent == null)
				throw new ArgumentNullException();
			this.FileTabContent = fileTabContent;
			this.SerializedUI = serializedUI;
			this.OnShownHandler = onShownHandler;
		}
Beispiel #3
0
        public void FollowReference(object @ref, IFileTabContent sourceContent, Action <ShowTabContentEventArgs> onShown)
        {
            var result = TryCreateContentFromReference(@ref, sourceContent);

            if (result != null)
            {
                Show(result.FileTabContent, result.SerializedUI, 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(false, this));
                    });
                }
                else
                {
                    onShown?.Invoke(new ShowTabContentEventArgs(false, this));
                }
            }
        }
Beispiel #4
0
        internal void Add(ITabGroup group, IFileTabContent tabContent, object serializedUI, Action <ShowTabContentEventArgs> onShown)
        {
            Debug.Assert(TabGroupManager.TabGroups.Contains(group));
            var tab = OpenEmptyTab(group);

            tab.Show(tabContent, serializedUI, onShown);
        }
Beispiel #5
0
		public Guid? Serialize(IFileTabContent content, ISettingsSection section) {
			var dc = content as HexFileTabContent;
			if (dc == null)
				return null;

			return GUID_SerializedContent;
		}
		public Guid? Serialize(IFileTabContent 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;
		}
Beispiel #7
0
		public void SetCurrent(IFileTabContent content, bool saveCurrent) {
			if (content == null)
				throw new ArgumentNullException();
			if (saveCurrent && current != null)
				oldList.Add(new TabContentState(current, current.FileTab.UIContext.Serialize()));
			this.current = content;
			newList.Clear();
		}
		public Guid? Serialize(IFileTabContent content, ISettingsSection section) {
			var hb = content as HexBoxFileTabContent;
			if (hb == null)
				return null;

			section.Attribute("filename", hb.Filename);
			return GUID_SerializedContent;
		}
Beispiel #9
0
 public void OverwriteCurrent(IFileTabContent content)
 {
     if (content == null)
     {
         throw new ArgumentNullException();
     }
     this.current = content;
 }
Beispiel #10
0
 public Guid?Serialize(IFileTabContent content, ISettingsSection section)
 {
     if (content is AboutScreenFileTabContent)
     {
         return(GUID_SerializedContent);
     }
     return(null);
 }
		public Guid? Serialize(IFileTabContent content, ISettingsSection section) {
			var dc = content as DecompileFileTabContent;
			if (dc == null)
				return null;

			section.Attribute("Language", dc.Language.UniqueGuid);
			return GUID_SerializedContent;
		}
Beispiel #12
0
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;

            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;

            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);

            tabContent.OnShow(showCtx);
            bool asyncShow       = false;
            var  asyncTabContent = tabContent as IAsyncFileTabContent;

            if (asyncTabContent != null)
            {
                if (asyncTabContent.CanStartAsyncWorker(showCtx))
                {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => {
                        AppCulture.InitializeCulture();
                        asyncTabContent.AsyncWorker(showCtx, ctx.CancellationTokenSource);
                    }, ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                  cachedUIContext.FileTab == this &&
                                                  UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                        {
                            asyncWorkerContext = null;
                        }
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, showCtx, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult());
                }
            }
            if (!asyncShow)
            {
                OnShown(serializedUI, onShownHandler, showCtx, true);
            }
            fileTabManager.OnNewTabContentShown(this);
        }
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var textRef = @ref as TextReference;

            if (textRef != null)
            {
                @ref = textRef.Reference;
            }
            var node = @ref as IFileTreeNodeData;

            if (node != null)
            {
                return(Create(node));
            }
            var nsRef = @ref as NamespaceRef;

            if (nsRef != null)
            {
                return(Create(nsRef));
            }
            var nsRef2 = @ref as NamespaceReference;

            if (nsRef2 != null)
            {
                return(Create(nsRef2));
            }
            var file = @ref as IDnSpyFile;

            if (file != null)
            {
                return(Create(file));
            }
            var asm = @ref as AssemblyDef;

            if (asm != null)
            {
                return(Create(asm));
            }
            var mod = @ref as ModuleDef;

            if (mod != null)
            {
                return(Create(mod));
            }
            var asmRef = @ref as IAssembly;

            if (asmRef != null)
            {
                file = fileTreeView.FileManager.Resolve(asmRef, null);
                if (file != null)
                {
                    return(Create(file));
                }
            }
            return(null);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fileTabContent">New content</param>
 /// <param name="serializedUI">Serialized UI data or null</param>
 /// <param name="onShownHandler">Handler or null</param>
 public FileTabReferenceResult(IFileTabContent fileTabContent, object serializedUI = null, Action <ShowTabContentEventArgs> onShownHandler = null)
 {
     if (fileTabContent == null)
     {
         throw new ArgumentNullException();
     }
     this.FileTabContent = fileTabContent;
     this.SerializedUI   = serializedUI;
     this.OnShownHandler = onShownHandler;
 }
Beispiel #15
0
		public object NavigateBackward() {
			Debug.Assert(CanNavigateBackward);
			if (oldList.Count == 0)
				return null;
			var old = oldList[oldList.Count - 1];
			oldList.RemoveAt(oldList.Count - 1);
			newList.Add(new TabContentState(current, current.FileTab.UIContext.Serialize()));
			current = old.FileTabContent;
			return old.SerializedData;
		}
Beispiel #16
0
 public Guid?Serialize(IFileTabContent 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);
 }
		public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref) {
			var tokRef = @ref as TokenReference;
			if (tokRef == null) {
				var codeRef = @ref as CodeReference;
				tokRef = codeRef == null ? null : codeRef.Reference as TokenReference;
			}
			if (tokRef != null)
				return Create(tokRef, fileTabManager);
			return null;
		}
		public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref) {
			var addrRef = @ref as AddressReference;
			if (addrRef == null) {
				var codeRef = @ref as CodeReference;
				addrRef = codeRef == null ? null : codeRef.Reference as AddressReference;
			}
			if (addrRef != null)
				return Create(addrRef, fileTabManager.FileTreeView);
			return null;
		}
Beispiel #19
0
        public Guid?Serialize(IFileTabContent content, ISettingsSection section)
        {
            var dc = content as HexFileTabContent;

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

            return(GUID_SerializedContent);
        }
Beispiel #20
0
 public void Show(IFileTabContent tabContent, object serializedUI, Action <ShowTabContentEventArgs> onShown)
 {
     if (tabContent == null)
     {
         throw new ArgumentNullException();
     }
     Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
     HideCurrentContent();
     Content = tabContent;
     ShowInternal(tabContent, serializedUI, onShown);
 }
        public Guid?Serialize(IFileTabContent content, ISettingsSection section)
        {
            var dc = content as DecompileFileTabContent;

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

            section.Attribute("Language", dc.Language.UniqueGuid);
            return(GUID_SerializedContent);
        }
        void GoToReference(IFileTabContent content, object @ref)
        {
            Debug.Assert(IsSupportedReference(@ref));
            var uiCtx = content.FileTab.UIContext as ITextEditorUIContext;

            if (uiCtx == null)
            {
                return;
            }

            uiCtx.MoveCaretTo(@ref);
        }
Beispiel #23
0
        public Guid?Serialize(IFileTabContent content, ISettingsSection section)
        {
            var hb = content as HexBoxFileTabContent;

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

            section.Attribute("filename", hb.Filename);
            return(GUID_SerializedContent);
        }
Beispiel #24
0
 FileTabReferenceResult TryCreateContentFromReference(object @ref, IFileTabContent sourceContent)
 {
     foreach (var f in refFactories)
     {
         var c = f.Value.Create(FileTabManager, sourceContent, @ref);
         if (c != null)
         {
             return(c);
         }
     }
     return(null);
 }
Beispiel #25
0
 public void SetCurrent(IFileTabContent content, bool saveCurrent)
 {
     if (content == null)
     {
         throw new ArgumentNullException();
     }
     if (saveCurrent && current != null)
     {
         oldList.Add(new TabContentState(current, current.FileTab.UIContext.Serialize()));
     }
     this.current = content;
     newList.Clear();
 }
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var codeRef = @ref as CodeReference;
            if (codeRef != null) {
                var result = CreateMemberRefResult(fileTabManager, codeRef.Reference);
                if (result != null)
                    return result;

                return CreateLocalRefResult(sourceContent, codeRef);
            }

            return CreateMemberRefResult(fileTabManager, @ref);
        }
Beispiel #27
0
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var tokRef = @ref as TokenReference;

            if (tokRef == null)
            {
                tokRef = (@ref as TextReference)?.Reference as TokenReference;
            }
            if (tokRef != null)
            {
                return(Create(tokRef, fileTabManager));
            }
            return(null);
        }
Beispiel #28
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.FileTab.UIContext.Serialize()));
            current = old.FileTabContent;
            return(old.SerializedData);
        }
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var addrRef = @ref as AddressReference;

            if (addrRef == null)
            {
                addrRef = (@ref as TextReference)?.Reference as AddressReference;
            }
            if (addrRef != null)
            {
                return(Create(addrRef, fileTabManager.FileTreeView));
            }
            return(null);
        }
        public Guid?Serialize(IFileTabContent content, ISettingsSection section)
        {
            var nodes   = content.Nodes.ToArray();
            var context = new FileTabContentFactoryContext(nodes);

            foreach (var factory in tabContentFactories)
            {
                var guid = factory.Value.Serialize(content, section);
                if (guid != null)
                {
                    return(guid);
                }
            }
            return(null);
        }
        FileTabReferenceResult CreateLocalRefResult(IFileTabContent sourceContent, CodeReference codeRef)
        {
            Debug.Assert(IsSupportedReference(codeRef));
            if (sourceContent == null)
            {
                return(null);
            }
            var content = sourceContent.Clone();

            return(new FileTabReferenceResult(content, null, a => {
                if (a.Success && !a.HasMovedCaret)
                {
                    GoToReference(content, codeRef);
                    a.HasMovedCaret = true;
                }
            }));
        }
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
        {
            var codeRef = @ref as CodeReference;

            if (codeRef != null)
            {
                var result = CreateMemberRefResult(fileTabManager, codeRef.Reference);
                if (result != null)
                {
                    return(result);
                }

                return(CreateLocalRefResult(sourceContent, codeRef));
            }

            return(CreateMemberRefResult(fileTabManager, @ref));
        }
 public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent sourceContent, object @ref)
 {
     var node = @ref as IFileTreeNodeData;
     if (node != null)
         return Create(node);
     var nsRef = @ref as NamespaceRef;
     if (nsRef != null)
         return Create(nsRef);
     var file = @ref as IDnSpyFile;
     if (file != null)
         return Create(file);
     var asm = @ref as AssemblyDef;
     if (asm != null)
         return Create(asm);
     var mod = @ref as ModuleDef;
     if (mod != null)
         return Create(mod);
     return null;
 }
Beispiel #34
0
        public void FollowReference(object @ref, IFileTabContent sourceContent, Action <ShowTabContentEventArgs> onShown)
        {
            var result = TryCreateContentFromReference(@ref, sourceContent);

            if (result != null)
            {
                Show(result.FileTabContent, result.SerializedUI, 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.
                    if (onShown != null)
                    {
                        onShown(e);
                    }
                    if (result.OnShownHandler != null)
                    {
                        result.OnShownHandler(e);
                    }
                });
            }
        }
Beispiel #35
0
        public FileTabReferenceResult Create(IFileTabManager fileTabManager, IFileTabContent 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(fileTabManager, textRef.Reference);
                if (result != null)
                {
                    return(result);
                }

                return(CreateLocalRefResult(sourceContent, textRef));
            }

            return(CreateMemberRefResult(fileTabManager, @ref));
        }
 public Guid? Serialize(IFileTabContent content, ISettingsSection section)
 {
     var nodes = content.Nodes.ToArray();
     var context = new FileTabContentFactoryContext(nodes);
     foreach (var factory in tabContentFactories) {
         var guid = factory.Value.Serialize(content, section);
         if (guid != null)
             return guid;
     }
     return null;
 }
Beispiel #37
0
		public void OverwriteCurrent(IFileTabContent content) {
			if (content == null)
				throw new ArgumentNullException();
			this.current = content;
		}
Beispiel #38
0
 public void FollowReference(object @ref, IFileTabContent sourceContent, Action<ShowTabContentEventArgs> onShown)
 {
     var result = TryCreateContentFromReference(@ref, sourceContent);
     if (result != null) {
         Show(result.FileTabContent, result.SerializedUI, 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.
             if (onShown != null)
                 onShown(e);
             if (result.OnShownHandler != null)
                 result.OnShownHandler(e);
         });
     }
 }
Beispiel #39
0
 public void Show(IFileTabContent tabContent, object serializedUI, Action<ShowTabContentEventArgs> onShown)
 {
     if (tabContent == null)
         throw new ArgumentNullException();
     Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
     HideCurrentContent();
     Content = tabContent;
     ShowInternal(tabContent, serializedUI, onShown);
 }
Beispiel #40
0
 public TabContentState(IFileTabContent fileTabContent, object serializedData)
 {
     this.FileTabContent = fileTabContent;
     this.SerializedData = serializedData;
 }
Beispiel #41
0
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action<ShowTabContentEventArgs> onShownHandler)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;
            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;
            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var userData = tabContent.OnShow(cachedUIContext);
            bool asyncShow = false;
            var asyncTabContent = tabContent as IAsyncFileTabContent;
            if (asyncTabContent != null) {
                if (asyncTabContent.CanStartAsyncWorker(cachedUIContext, userData)) {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => {
                        AppCulture.InitializeCulture();
                        asyncTabContent.AsyncWorker(cachedUIContext, userData, ctx.CancellationTokenSource);
                    }, ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                cachedUIContext.FileTab == this &&
                                                UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                            asyncWorkerContext = null;
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(cachedUIContext, userData, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                    asyncTabContent.EndAsyncShow(cachedUIContext, userData, new AsyncShowResult());
            }
            if (!asyncShow)
                OnShown(serializedUI, onShownHandler, true);
            fileTabManager.OnNewTabContentShown(this);
        }
Beispiel #42
0
 bool CheckRemove(IFileTabContent content, HashSet <IDnSpyFileNode> removedFiles) =>
 content.Nodes.Any(a => removedFiles.Contains(a.GetDnSpyFileNode()));
Beispiel #43
0
 bool CheckRemove(IFileTabContent content, HashSet<IDnSpyFileNode> removedFiles)
 {
     return content.Nodes.Any(a => removedFiles.Contains(a.GetDnSpyFileNode()));
 }
Beispiel #44
0
		public TabContentState(IFileTabContent fileTabContent, object serializedData) {
			this.FileTabContent = fileTabContent;
			this.SerializedData = serializedData;
		}
        void GoToReference(IFileTabContent content, object @ref)
        {
            Debug.Assert(IsSupportedReference(@ref));
            var uiCtx = content.FileTab.UIContext as ITextEditorUIContext;
            if (uiCtx == null)
                return;

            uiCtx.MoveCaretTo(@ref);
        }
Beispiel #46
0
 FileTabReferenceResult TryCreateContentFromReference(object @ref, IFileTabContent sourceContent)
 {
     foreach (var f in refFactories) {
         var c = f.Value.Create(FileTabManager, sourceContent, @ref);
         if (c != null)
             return c;
     }
     return null;
 }
Beispiel #47
0
 public Guid? Serialize(IFileTabContent content, ISettingsSection section)
 {
     if (content is AboutScreenFileTabContent)
         return GUID_SerializedContent;
     return null;
 }
 FileTabReferenceResult CreateLocalRefResult(IFileTabContent sourceContent, CodeReference codeRef)
 {
     Debug.Assert(IsSupportedReference(codeRef));
     if (sourceContent == null)
         return null;
     var content = sourceContent.Clone();
     return new FileTabReferenceResult(content, null, a => {
         if (a.Success && !a.HasMovedCaret) {
             GoToReference(content, codeRef);
             a.HasMovedCaret = true;
         }
     });
 }