/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="documentTabContent">New content</param>
		/// <param name="uiState">UI state (passed to <see cref="DocumentTabUIContext.RestoreUIState(object)"/>) or null</param>
		/// <param name="onShownHandler">Handler or null</param>
		public DocumentTabReferenceResult(DocumentTabContent documentTabContent, object uiState = null, Action<ShowTabContentEventArgs> onShownHandler = null) {
			if (documentTabContent == null)
				throw new ArgumentNullException(nameof(documentTabContent));
			DocumentTabContent = documentTabContent;
			UIState = uiState;
			OnShownHandler = onShownHandler;
		}
		public DocumentTabReferenceResult Create(IDocumentTabService documentTabService, DocumentTabContent sourceContent, object @ref) {
			var textRef = @ref as TextReference;
			if (textRef != null)
				@ref = textRef.Reference;
			var node = @ref as DocumentTreeNodeData;
			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 document = @ref as IDsDocument;
			if (document != null)
				return Create(document);
			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) {
				document = documentTreeView.DocumentService.Resolve(asmRef, null);
				if (document != null)
					return Create(document);
			}
			return null;
		}
		public Guid? Serialize(DocumentTabContent content, ISettingsSection section) {
			var dc = content as HexDocumentTabContent;
			if (dc == null)
				return null;

			return GUID_SerializedContent;
		}
		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 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;
		}
		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;
		}
		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 DocumentTabReferenceResult Create(IDocumentTabService documentTabService, DocumentTabContent sourceContent, object @ref) {
			var tokRef = @ref as TokenReference;
			if (tokRef == null)
				tokRef = (@ref as TextReference)?.Reference as TokenReference;
			if (tokRef != null)
				return Create(tokRef, documentTabService);
			return null;
		}
Exemple #9
0
		public void SetCurrent(DocumentTabContent content, bool saveCurrent) {
			if (content == null)
				throw new ArgumentNullException(nameof(content));
			if (saveCurrent && current != null)
				oldList.Add(new TabContentState(current, current.DocumentTab.UIContext.CreateUIState()));
			current = content;
			newList.Clear();
		}
		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;
		}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="documentTabContent">New content</param>
 /// <param name="uiState">UI state (passed to <see cref="DocumentTabUIContext.RestoreUIState(object)"/>) or null</param>
 /// <param name="onShownHandler">Handler or null</param>
 public DocumentTabReferenceResult(DocumentTabContent documentTabContent, object uiState = null, Action <ShowTabContentEventArgs> onShownHandler = null)
 {
     if (documentTabContent == null)
     {
         throw new ArgumentNullException(nameof(documentTabContent));
     }
     DocumentTabContent = documentTabContent;
     UIState            = uiState;
     OnShownHandler     = onShownHandler;
 }
Exemple #12
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;
		}
Exemple #13
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;
		}
		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);
		}
		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;
				}
			});
		}
Exemple #17
0
		bool CheckRemove(DocumentTabContent content, HashSet<DsDocumentNode> removedDocuments) =>
			content.Nodes.Any(a => removedDocuments.Contains(a.GetDocumentNode()));
Exemple #18
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();
			var showCtx = new ShowContext(cachedUIContext, isRefresh);
			tabContent.OnShow(showCtx);
			bool asyncShow = false;
			var asyncTabContent = tabContent as AsyncDocumentTabContent;
			if (asyncTabContent != null) {
				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);
		}
Exemple #19
0
		public void FollowReference(object @ref, DocumentTabContent sourceContent, Action<ShowTabContentEventArgs> onShown) {
			if (NotifyReferenceHandlers(@ref, Content, onShown))
				return;
			FollowReferenceCore(@ref, sourceContent, onShown);
		}
Exemple #20
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;
		}
Exemple #21
0
			public ReferenceHandlerContext(object @ref, DocumentTabContent content, DocumentTabContent sourceContent) {
				Reference = @ref;
				Content = content;
				SourceContent = sourceContent;
			}
Exemple #22
0
		public void OverwriteCurrent(DocumentTabContent content) {
			if (content == null)
				throw new ArgumentNullException(nameof(content));
			current = content;
		}
Exemple #23
0
		public Guid? Serialize(DocumentTabContent content, ISettingsSection section) {
			if (content is AboutScreenDocumentTabContent)
				return GUID_SerializedContent;
			return null;
		}
Exemple #24
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);
		}
Exemple #25
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));
			}
		}
Exemple #26
0
		public TabContentState(DocumentTabContent documentTabContent, object uiState) {
			DocumentTabContent = documentTabContent;
			UIState = uiState;
		}