Example #1
0
        bool GoTo(IFileTab tab, MethodDef method, uint?ilOffset, object @ref)
        {
            if (method == null || ilOffset == null)
            {
                return(false);
            }
            var uiContext = tab.TryGetTextEditorUIContext();

            if (uiContext == null)
            {
                return(false);
            }
            var cm      = uiContext.GetCodeMappings();
            var mapping = cm.Find(method, ilOffset.Value);

            if (mapping == null)
            {
                return(false);
            }

            var location = mapping.StartPosition;
            var loc      = FindLocation(uiContext.GetCodeReferences(location.Line, location.Column), mapping.EndPosition, @ref);

            if (loc == null)
            {
                loc = new TextEditorLocation(location.Line, location.Column);
            }

            uiContext.ScrollAndMoveCaretTo(loc.Value.Line, loc.Value.Column);
            return(true);
        }
Example #2
0
        public void FollowReference(object @ref, bool newTab, bool setFocus, Action <ShowTabContentEventArgs> onShown)
        {
            if (@ref == null)
            {
                return;
            }

            IFileTab tab       = ActiveTabContentImpl;
            var      sourceTab = tab;

            if (tab == null)
            {
                tab = SafeActiveTabContentImpl;
            }
            else if (newTab)
            {
                var g = TabGroupManager.ActiveTabGroup;
                Debug.Assert(g != null);
                if (g == null)
                {
                    return;
                }
                tab = OpenEmptyTab(g);
            }
            tab.FollowReference(@ref, sourceTab == null ? null : sourceTab.Content, onShown);
            if (setFocus)
            {
                SetFocus(tab);
            }
        }
Example #3
0
 internal void OnNewTabContentShown(IFileTab fileTab)
 {
     if (fileTab == null)
     {
         return;
     }
     if (!isTreeViewVisible)
     {
         return;
     }
     if (!tabsLoaded)
     {
         return;
     }
     if (disableSelectTreeNodes > 0)
     {
         return;
     }
     if (fileTab != ActiveTabContentImpl)
     {
         return;
     }
     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
         if (fileTab == ActiveTabContentImpl)
         {
             OnNewTabContentShownDelay(fileTab);
         }
     }));
 }
Example #4
0
 BamlTabSaver(IFileTab tab, BamlResourceElementNode bamlNode, ITextEditorUIContext uiContext, IMessageBoxManager messageBoxManager)
 {
     this.tab               = tab;
     this.bamlNode          = bamlNode;
     this.uiContext         = uiContext;
     this.messageBoxManager = messageBoxManager;
 }
Example #5
0
 public void Save(IFileTab tab)
 {
     var ts = GetTabSaver(tab);
     if (ts == null || !ts.CanSave)
         return;
     ts.Save();
 }
Example #6
0
 public TabVM(TabsVM owner, IFileTab tab)
 {
     this.owner = owner;
     this.tab = tab;
     var node = tab.Content.Nodes.FirstOrDefault().GetTopNode();
     this.file = node == null ? null : node.DnSpyFile;
 }
Example #7
0
        bool GoTo(IFileTab tab, MethodDef method, uint?ilOffset, object @ref)
        {
            if (method == null || ilOffset == null)
            {
                return(false);
            }
            var documentViewer = tab.TryGetDocumentViewer();

            if (documentViewer == null)
            {
                return(false);
            }
            var methodDebugService = documentViewer.GetMethodDebugService();
            var methodStatement    = methodDebugService.FindByCodeOffset(method, ilOffset.Value);

            if (methodStatement == null)
            {
                return(false);
            }

            var textSpan = methodStatement.Value.Statement.TextSpan;
            var loc      = FindLocation(documentViewer.Content.ReferenceCollection.FindFrom(textSpan.Start), documentViewer.TextView.TextSnapshot, methodStatement.Value.Statement.TextSpan.End, @ref);

            if (loc == null)
            {
                loc = textSpan.Start;
            }

            documentViewer.MoveCaretToPosition(loc.Value);
            return(true);
        }
Example #8
0
 BamlTabSaver(IFileTab tab, BamlResourceElementNode bamlNode, IDocumentViewer documentViewer, IMessageBoxManager messageBoxManager)
 {
     this.tab               = tab;
     this.bamlNode          = bamlNode;
     this.documentViewer    = documentViewer;
     this.messageBoxManager = messageBoxManager;
 }
Example #9
0
        public TabVM(TabsVM owner, IFileTab tab)
        {
            this.owner = owner;
            this.tab   = tab;
            var node = tab.Content.Nodes.FirstOrDefault().GetTopNode();

            this.file = node == null ? null : node.DnSpyFile;
        }
Example #10
0
 NodeTabSaver(IMessageBoxManager messageBoxManager, IFileTab tab, IFileTreeNodeDecompiler fileTreeNodeDecompiler, ILanguage language, ITextEditorUIContext uiContext, IFileTreeNodeData[] nodes)
 {
     this.messageBoxManager = messageBoxManager;
     this.tab = tab;
     this.fileTreeNodeDecompiler = fileTreeNodeDecompiler;
     this.language = language;
     this.uiContext = uiContext;
     this.nodes = nodes;
 }
Example #11
0
 NodeTabSaver(IMessageBoxManager messageBoxManager, IFileTab tab, IFileTreeNodeDecompiler fileTreeNodeDecompiler, IDecompiler decompiler, IDocumentViewer documentViewer, IFileTreeNodeData[] nodes)
 {
     this.messageBoxManager = messageBoxManager;
     this.tab = tab;
     this.fileTreeNodeDecompiler = fileTreeNodeDecompiler;
     this.decompiler             = decompiler;
     this.documentViewer         = documentViewer;
     this.nodes = nodes;
 }
Example #12
0
 NodeTabSaver(IMessageBoxManager messageBoxManager, IFileTab tab, IFileTreeNodeDecompiler fileTreeNodeDecompiler, ILanguage language, ITextEditorUIContext uiContext, IFileTreeNodeData[] nodes)
 {
     this.messageBoxManager = messageBoxManager;
     this.tab = tab;
     this.fileTreeNodeDecompiler = fileTreeNodeDecompiler;
     this.language  = language;
     this.uiContext = uiContext;
     this.nodes     = nodes;
 }
Example #13
0
 static ITokenResolver GetResolver(IFileTabManager fileTabManager, out IFileTab tab)
 {
     tab = fileTabManager.ActiveTab;
     if (tab == null)
     {
         return(null);
     }
     return(tab.Content.Nodes.FirstOrDefault().GetModule());
 }
Example #14
0
        public void Save(IFileTab tab)
        {
            var ts = GetTabSaver(tab);

            if (ts == null || !ts.CanSave)
            {
                return;
            }
            ts.Save();
        }
Example #15
0
		public static ITabSaver TryCreate(Lazy<IDocumentSaver> documentSaver, IFileTab tab) {
			var uiContext = tab.UIContext as HexBoxFileTabUIContext;
			if (uiContext == null)
				return null;
			var doc = uiContext.DnHexBox.Document as AsmEdHexDocument;
			Debug.Assert(doc != null);
			if (doc == null)
				return null;

			return new HexTabSaver(documentSaver, doc);
		}
Example #16
0
 ITabSaver GetTabSaver(IFileTab tab)
 {
     if (tab == null)
         return null;
     foreach (var creator in creators) {
         var ts = creator.Create(tab);
         if (ts != null)
             return ts;
     }
     return null;
 }
Example #17
0
		public static BamlTabSaver TryCreate(IFileTab tab, IMessageBoxManager messageBoxManager) {
			var uiContext = tab.UIContext as ITextEditorUIContext;
			if (uiContext == null)
				return null;
			var nodes = tab.Content.Nodes.ToArray();
			if (nodes.Length != 1)
				return null;
			var bamlNode = nodes[0] as BamlResourceElementNode;
			if (bamlNode == null)
				return null;

			return new BamlTabSaver(tab, bamlNode, uiContext, messageBoxManager);
		}
Example #18
0
 ITabSaver GetTabSaver(IFileTab tab)
 {
     if (tab == null)
     {
         return(null);
     }
     foreach (var provider in tabSaverProviders)
     {
         var ts = provider.Create(tab);
         if (ts != null)
         {
             return(ts);
         }
     }
     return(null);
 }
Example #19
0
 ITabSaver GetTabSaver(IFileTab tab)
 {
     if (tab == null)
     {
         return(null);
     }
     foreach (var creator in creators)
     {
         var ts = creator.Create(tab);
         if (ts != null)
         {
             return(ts);
         }
     }
     return(null);
 }
Example #20
0
        bool MustRefresh(IFileTab tab, IEnumerable <IDnSpyFile> files)
        {
            var modules = new HashSet <IDnSpyFile>(files);

            if (InModifiedModuleHelper.IsInModifiedModule(modules, tab.Content.Nodes))
            {
                return(true);
            }
            var documentViewer = tab.TryGetDocumentViewer();

            if (documentViewer != null && InModifiedModuleHelper.IsInModifiedModule(FileTreeView.FileManager, modules, documentViewer.Content.ReferenceCollection.Select(a => a.Data.Reference)))
            {
                return(true);
            }

            return(false);
        }
Example #21
0
        bool MustRefresh(IFileTab tab, IEnumerable <IDnSpyFile> files)
        {
            var modules = new HashSet <IDnSpyFile>(files);

            if (InModifiedModuleHelper.IsInModifiedModule(modules, tab.Content.Nodes))
            {
                return(true);
            }
            var uiContext = tab.TryGetTextEditorUIContext();

            if (uiContext != null && InModifiedModuleHelper.IsInModifiedModule(FileTreeView.FileManager, modules, uiContext.References))
            {
                return(true);
            }

            return(false);
        }
Example #22
0
        public static ITabSaver TryCreate(Lazy <IDocumentSaver> documentSaver, IFileTab tab)
        {
            var uiContext = tab.UIContext as HexBoxFileTabUIContext;

            if (uiContext == null)
            {
                return(null);
            }
            var doc = uiContext.DnHexBox.Document as AsmEdHexDocument;

            Debug.Assert(doc != null);
            if (doc == null)
            {
                return(null);
            }

            return(new HexTabSaver(documentSaver, doc));
        }
Example #23
0
        static string GetHeader(int i, IFileTab tab)
        {
            string s;

            if (i == 10)
            {
                s = "1_0";
            }
            else if (i > 10)
            {
                s = i.ToString();
            }
            else
            {
                s = string.Format("_{0}", i);
            }
            return(string.Format("{0} {1}", s, GetShortMenuItemHeader(tab.Content.Title)));
        }
Example #24
0
        void OnNewTabContentShownDelay(IFileTab fileTab)
        {
            var newNodes = fileTab.Content.Nodes.ToArray();

            if (Equals(fileTreeView.TreeView.SelectedItems, newNodes))
            {
                return;
            }

            // The treeview steals the focus so remember the current focused element. Don't restore
            // the focus if it's a node in the treeview.
            var focusedElem = Keyboard.FocusedElement;

            if (((UIElement)fileTreeView.TreeView.UIObject).IsKeyboardFocusWithin)
            {
                focusedElem = null;
            }
            bool tabGroupHasFocus = tabGroupManager.TabGroups.Any(a => a.IsKeyboardFocusWithin);

            disableSelectionChangedEventCounter++;
            try {
                fileTreeView.TreeView.SelectItems(newNodes);
            }
            finally {
                disableSelectionChangedEventCounter--;
            }

            if (focusedElem != null && Keyboard.FocusedElement != focusedElem)
            {
                if (tabGroupHasFocus)
                {
                    var tab = ActiveTabContentImpl;
                    Debug.Assert(tab != null);
                    if (tab != null)
                    {
                        tab.TrySetFocus();
                    }
                }
                else
                {
                    wpfFocusManager.Focus(focusedElem);
                }
            }
        }
Example #25
0
        bool GoTo(IFileTab tab, MethodDef method, uint ilOffset)
        {
            var documentViewer = tab.TryGetDocumentViewer();

            if (documentViewer == null || method == null)
            {
                return(false);
            }
            var methodDebugService = documentViewer.GetMethodDebugService();
            var methodStatement    = methodDebugService.FindByCodeOffset(method, ilOffset);

            if (methodStatement == null)
            {
                return(false);
            }

            documentViewer.MoveCaretToPosition(methodStatement.Value.Statement.TextSpan.Start);
            return(true);
        }
Example #26
0
        public void Close(IFileTab tab)
        {
            if (tab == null)
            {
                throw new ArgumentNullException();
            }
            var impl = tab as TabContentImpl;

            if (impl == null)
            {
                throw new InvalidOperationException();
            }
            var g = GetTabGroup(impl);

            if (g == null)
            {
                throw new InvalidOperationException();
            }
            g.Close(impl);
        }
Example #27
0
        static ListView FindListView(IFileTab tab)
        {
            var o = tab.UIContext.UIObject as DependencyObject;

            while (o != null)
            {
                var lv = o as ListView;
                if (lv != null && InitDataTemplateAP.GetInitialize(lv))
                {
                    return(lv);
                }
                var children = UIUtils.GetChildren(o).ToArray();
                if (children.Length != 1)
                {
                    return(null);
                }
                o = children[0];
            }

            return(null);
        }
Example #28
0
        bool GoTo(IFileTab tab, MethodDef method, uint ilOffset)
        {
            var uiContext = tab.TryGetTextEditorUIContext();

            if (uiContext == null || method == null)
            {
                return(false);
            }
            var cm      = uiContext.GetCodeMappings();
            var mapping = cm.Find(method, ilOffset);

            if (mapping == null)
            {
                return(false);
            }

            var location = mapping.StartPosition;

            uiContext.ScrollAndMoveCaretTo(location.Line, location.Column);
            return(true);
        }
Example #29
0
        public static BamlTabSaver TryCreate(IFileTab tab, IMessageBoxManager messageBoxManager)
        {
            var uiContext = tab.UIContext as IDocumentViewer;

            if (uiContext == null)
            {
                return(null);
            }
            var nodes = tab.Content.Nodes.ToArray();

            if (nodes.Length != 1)
            {
                return(null);
            }
            var bamlNode = nodes[0] as BamlResourceElementNode;

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

            return(new BamlTabSaver(tab, bamlNode, uiContext, messageBoxManager));
        }
Example #30
0
		public static SerializedTab TryCreate(IFileTabContentFactoryManager creator, IFileTab tab) {
			var contentSect = new SettingsSection(CONTENT_SECTION);
			var guid = creator.Serialize(tab.Content, contentSect);
			if (guid == null)
				return null;
			contentSect.Attribute(CONTENT_GUID_ATTR, guid.Value);

			var uiSect = new SettingsSection(UI_SECTION);
			tab.UIContext.SaveSerialized(uiSect, tab.UIContext.Serialize());

			var tabUISect = new SettingsSection(TAB_UI_SECTION);
			tab.SerializeUI(tabUISect);

			var paths = new List<SerializedPath>();
			foreach (var node in tab.Content.Nodes)
				paths.Add(SerializedPath.Create(node));

			var autoLoadedFiles = new List<DnSpyFileInfo>();
			foreach (var f in GetAutoLoadedFiles(tab.Content.Nodes))
				autoLoadedFiles.Add(f);

			return new SerializedTab(contentSect, tabUISect, uiSect, paths, autoLoadedFiles);
		}
Example #31
0
        public static NodeTabSaver TryCreate(IFileTreeNodeDecompiler fileTreeNodeDecompiler, IFileTab tab, IMessageBoxManager messageBoxManager)
        {
            if (tab.IsAsyncExecInProgress)
            {
                return(null);
            }
            var uiContext = tab.UIContext as IDocumentViewer;

            if (uiContext == null)
            {
                return(null);
            }
            var decompiler = (tab.Content as IDecompilerTabContent)?.Decompiler;

            if (decompiler == null)
            {
                return(null);
            }
            var nodes = tab.Content.Nodes.ToArray();

            if (nodes.Length == 0)
            {
                return(null);
            }
            return(new NodeTabSaver(messageBoxManager, tab, fileTreeNodeDecompiler, decompiler, uiContext, nodes));
        }
Example #32
0
 public ITabSaver Create(IFileTab tab) => NodeTabSaver.TryCreate(fileTreeNodeDecompiler, tab, messageBoxManager);
Example #33
0
		bool GoTo(IFileTab tab, MethodDef method, uint ilOffset) {
			var uiContext = tab.TryGetTextEditorUIContext();
			if (uiContext == null || method == null)
				return false;
			var cm = uiContext.GetCodeMappings();
			var mapping = cm.Find(method, ilOffset);
			if (mapping == null)
				return false;

			var location = mapping.StartPosition;
			uiContext.ScrollAndMoveCaretTo(location.Line, location.Column);
			return true;
		}
Example #34
0
 /// <summary>
 /// Returns the tab's <see cref="IDocumentViewer"/> or null if it's not visible
 /// </summary>
 /// <param name="tab">Tab</param>
 /// <returns></returns>
 public static IDocumentViewer TryGetDocumentViewer(this IFileTab tab) => tab?.UIContext as IDocumentViewer;
Example #35
0
		public ITabSaver Create(IFileTab tab) {
			return BamlTabSaver.TryCreate(tab, messageBoxManager);
		}
Example #36
0
		void JumpToCurrentStatement(IFileTab tab, bool canRefreshMethods) {
			if (tab == null)
				return;
			if (currentMethod == null)
				return;

			// The file could've been added lazily to the list so add a short delay before we select it
			Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
				tab.FollowReference(currentMethod, false, e => {
					Debug.Assert(e.Tab == tab);
					Debug.Assert(e.Tab.UIContext is ITextEditorUIContext);
					if (e.Success && !e.HasMovedCaret) {
						MoveCaretToCurrentStatement(e.Tab.UIContext as ITextEditorUIContext, canRefreshMethods);
						e.HasMovedCaret = true;
					}
				});
			}));
		}
Example #37
0
 public ITabSaver Create(IFileTab tab) => HexTabSaver.TryCreate(documentSaver, tab);
Example #38
0
		public void JumpToCurrentStatement(IFileTab tab) {
			JumpToCurrentStatement(tab, true);
		}
Example #39
0
 public static NodeTabSaver TryCreate(IFileTreeNodeDecompiler fileTreeNodeDecompiler, IFileTab tab, IMessageBoxManager messageBoxManager)
 {
     if (tab.IsAsyncExecInProgress)
         return null;
     var uiContext = tab.UIContext as ITextEditorUIContext;
     if (uiContext == null)
         return null;
     var langContent = tab.Content as ILanguageTabContent;
     var lang = langContent == null ? null : langContent.Language;
     if (lang == null)
         return null;
     var nodes = tab.Content.Nodes.ToArray();
     if (nodes.Length == 0)
         return null;
     return new NodeTabSaver(messageBoxManager, tab, fileTreeNodeDecompiler, lang, uiContext, nodes);
 }
Example #40
0
		BamlTabSaver(IFileTab tab, BamlResourceElementNode bamlNode, ITextEditorUIContext uiContext, IMessageBoxManager messageBoxManager) {
			this.tab = tab;
			this.bamlNode = bamlNode;
			this.uiContext = uiContext;
			this.messageBoxManager = messageBoxManager;
		}
Example #41
0
 public ITabSaver Create(IFileTab tab)
 {
     return NodeTabSaver.TryCreate(fileTreeNodeDecompiler, tab, messageBoxManager);
 }
Example #42
0
		public ITabSaver Create(IFileTab tab) {
			return HexTabSaver.TryCreate(documentSaver, tab);
		}
Example #43
0
 static ITokenResolver GetResolver(IFileTabManager fileTabManager, out IFileTab tab)
 {
     tab = fileTabManager.ActiveTab;
     if (tab == null)
         return null;
     return tab.Content.Nodes.FirstOrDefault().GetModule();
 }
Example #44
0
		bool GoTo(IFileTab tab, MethodDef method, uint? ilOffset, object @ref) {
			if (method == null || ilOffset == null)
				return false;
			var uiContext = tab.TryGetTextEditorUIContext();
			if (uiContext == null)
				return false;
			var cm = uiContext.GetCodeMappings();
			var mapping = cm.Find(method, ilOffset.Value);
			if (mapping == null)
				return false;

			var location = mapping.StartPosition;
			var loc = FindLocation(uiContext.GetCodeReferences(location.Line, location.Column), mapping.EndPosition, @ref);
			if (loc == null)
				loc = new TextEditorLocation(location.Line, location.Column);

			uiContext.ScrollAndMoveCaretTo(loc.Value.Line, loc.Value.Column);
			return true;
		}
Example #45
0
 public ITabSaver Create(IFileTab tab) => BamlTabSaver.TryCreate(tab, messageBoxManager);
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="success">See <see cref="Success"/></param>
		/// <param name="tab">Tab</param>
		public ShowTabContentEventArgs(bool success, IFileTab tab) {
			this.Success = success;
			this.HasMovedCaret = false;
			this.Tab = tab;
		}
Example #47
0
 public bool CanSave(IFileTab tab)
 {
     var ts = GetTabSaver(tab);
     return ts != null && ts.CanSave;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="success">See <see cref="Success"/></param>
 /// <param name="tab">Tab</param>
 public ShowTabContentEventArgs(bool success, IFileTab tab)
 {
     this.Success       = success;
     this.HasMovedCaret = false;
     this.Tab           = tab;
 }
Example #49
0
 public string GetMenuHeader(IFileTab tab)
 {
     var ts = GetTabSaver(tab);
     return (ts == null ? null : ts.MenuHeader) ?? dnSpy_Resources.Button_Save;
 }
Example #50
0
        public static SerializedTab TryCreate(IFileTabContentFactoryManager creator, IFileTab tab)
        {
            var contentSect = new SettingsSection(CONTENT_SECTION);
            var guid = creator.Serialize(tab.Content, contentSect);
            if (guid == null)
                return null;
            contentSect.Attribute(CONTENT_GUID_ATTR, guid.Value);

            var uiSect = new SettingsSection(UI_SECTION);
            tab.UIContext.SaveSerialized(uiSect, tab.UIContext.Serialize());

            var tabUISect = new SettingsSection(TAB_UI_SECTION);
            tab.SerializeUI(tabUISect);

            var paths = new List<SerializedPath>();
            foreach (var node in tab.Content.Nodes)
                paths.Add(SerializedPath.Create(node));

            var autoLoadedFiles = new List<DnSpyFileInfo>();
            foreach (var f in GetAutoLoadedFiles(tab.Content.Nodes))
                autoLoadedFiles.Add(f);

            return new SerializedTab(contentSect, tabUISect, uiSect, paths, autoLoadedFiles);
        }