public static ITabSaver TryCreate(Lazy<IDocumentSaver> documentSaver, IDocumentTab tab) { var uiContext = tab.UIContext as HexViewDocumentTabUIContext; if (uiContext == null) return null; var buffer = uiContext.HexView.Buffer; return new HexTabSaver(documentSaver, buffer); }
NodeTabSaver(IMessageBoxService messageBoxService, IDocumentTab tab, IDocumentTreeNodeDecompiler documentTreeNodeDecompiler, IDecompiler decompiler, IDocumentViewer documentViewer, DocumentTreeNodeData[] nodes) { this.messageBoxService = messageBoxService; this.tab = tab; this.documentTreeNodeDecompiler = documentTreeNodeDecompiler; this.decompiler = decompiler; this.documentViewer = documentViewer; this.nodes = nodes; }
ITabSaver GetTabSaver(IDocumentTab tab) { if (tab == null) return null; foreach (var provider in tabSaverProviders) { var ts = provider.Create(tab); if (ts != null) return ts; } return null; }
public static ITabSaver TryCreate(Lazy <IDocumentSaver> documentSaver, IDocumentTab tab) { var uiContext = tab.UIContext as HexViewDocumentTabUIContext; if (uiContext == null) { return(null); } var buffer = uiContext.HexView.Buffer; return(new HexTabSaver(documentSaver, buffer)); }
public static BamlTabSaver TryCreate(IDocumentTab tab, IMessageBoxService messageBoxService) { 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, messageBoxService); }
public static NodeTabSaver TryCreate(IDocumentTreeNodeDecompiler documentTreeNodeDecompiler, IDocumentTab tab, IMessageBoxService messageBoxService) { 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(messageBoxService, tab, documentTreeNodeDecompiler, decompiler, uiContext, nodes); }
ITabSaver GetTabSaver(IDocumentTab tab) { if (tab == null) { return(null); } foreach (var provider in tabSaverProviders) { var ts = provider.Create(tab); if (ts != null) { return(ts); } } return(null); }
bool MustRefresh(IDocumentTab tab, IEnumerable <IDsDocument> documents) { var modules = new HashSet <IDsDocument>(documents); if (InModifiedModuleHelper.IsInModifiedModule(modules, tab.Content.Nodes)) { return(true); } var documentViewer = tab.TryGetDocumentViewer(); if (documentViewer != null && InModifiedModuleHelper.IsInModifiedModule(DocumentTreeView.DocumentService, modules, documentViewer.Content.ReferenceCollection.Select(a => a.Data.Reference))) { return(true); } return(false); }
public override void GoToLocation(IDocumentTab tab, MethodDef method, ModuleTokenId module, uint offset, bool newTab) { bool specialIpOffset; if (offset == EPILOG) { specialIpOffset = true; var mod = dbgMetadataService.Value.TryGetMetadata(module.Module, DbgLoadModuleOptions.AutoLoaded); if (mod?.ResolveToken(module.Token) is MethodDef md && md.Body is not null && md.Body.Instructions.Count > 0) { offset = md.Body.Instructions[md.Body.Instructions.Count - 1].Offset; } else { return; } }
static string GetHeader(int i, IDocumentTab 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))); }
public static ITabSaver TryCreate(Lazy <IDocumentSaver> documentSaver, IDocumentTab tab) { var uiContext = tab.UIContext as HexBoxDocumentTabUIContext; 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)); }
static string GetHeader(int i, IDocumentTab tab) { string s; if (i == 10) { s = "1_0"; } else if (i > 10) { s = i.ToString(); } else { s = $"_{i}"; } return($"{s} {GetShortMenuItemHeader(tab.Content.Title)}"); }
void OnNewTabContentShownDelay(IDocumentTab documentTab) { var newNodes = documentTab.Content.Nodes.ToArray(); if (Equals(DocumentTreeView.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 (DocumentTreeView.TreeView.UIObject.IsKeyboardFocusWithin) { focusedElem = null; } bool tabGroupHasFocus = TabGroupService.TabGroups.Any(a => a.IsKeyboardFocusWithin); disableSelectionChangedEventCounter++; try { DocumentTreeView.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 { wpfFocusService.Focus(focusedElem); } } }
internal bool ValidateDocumentTab(IDocumentTab documentTab, IView targetView, DragAction action, DockOperation operation, bool bExecute) { switch (targetView) { case IRootDock targetRoot: { return(DockIntoWindow(documentTab, targetView, action, operation, bExecute)); } case IToolTab targetToolTab: { return(false); } case IDocumentTab targetDocumentTab: { return(DockIntoTab(documentTab, targetDocumentTab, action, operation, bExecute)); } case ILayoutDock targetLayout: { return(false); } case IToolDock targetTool: { return(false); } case IDocumentDock targetTab: { return(DockIntoTab(documentTab, targetTab, action, operation, bExecute)); } default: { #if DEBUG Console.WriteLine($"Not supported type {targetView.GetType()}: {documentTab} -> {targetView}"); #endif return(false); } } }
bool GoTo(IDocumentTab 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); }
public void Close(IDocumentTab tab) { if (tab == null) { throw new ArgumentNullException(nameof(tab)); } var impl = tab as TabContentImpl; if (impl == null) { throw new InvalidOperationException(); } var g = GetTabGroup(impl); if (g == null) { throw new InvalidOperationException(); } g.Close(impl); }
ToggleCreateBreakpointInfoResult GetToggleCreateBookmarkInfo(IDocumentTab tab, VirtualSnapshotPoint?position) { using (var info = GetLocation(tab, position)) { var locRes = info.locRes; var bms = locRes == null?Array.Empty <Bookmark>() : GetBookmarks(locRes.Value); if (bms.Length != 0) { return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.Delete, bms, null)); } else { if (locRes == null || locRes.Value.Location == null) { return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.None, Array.Empty <Bookmark>(), null)); } return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.Add, Array.Empty <Bookmark>(), info.TakeOwnership(locRes.Value.Location))); } } }
static ListView FindListView(IDocumentTab 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); }
public static BamlTabSaver TryCreate(IDocumentTab tab, IMessageBoxService messageBoxService) { if (tab.IsAsyncExecInProgress) { return(null); } if (tab.UIContext is not IDocumentViewer uiContext) { return(null); } var nodes = tab.Content.Nodes.ToArray(); if (nodes.Length != 1) { return(null); } if (nodes[0] is not BamlResourceElementNode bamlNode) { return(null); } return(new BamlTabSaver(tab, bamlNode, uiContext, messageBoxService)); }
public override TextViewBookmarkLocationResult?CreateLocation(IDocumentTab tab, ITextView textView, VirtualSnapshotPoint position) { var documentViewer = tab.TryGetDocumentViewer(); if (documentViewer == null) { return(null); } // A bookmark should be set on the current line if possible, and the current position // isn't necessarily at the start of the line. int startPos = position.Position.GetContainingLine().Start.Position; foreach (var data in documentViewer.ReferenceCollection.FindFrom(startPos)) { if (!data.Data.IsDefinition) { continue; } var def = data.Data.Reference as IMemberDef; if (def == null) { continue; } var span = data.Span; var snapshot = textView.TextSnapshot; if (span.End > snapshot.Length) { return(null); } var moduleId = moduleIdProvider.Create(def.Module); var location = dotNetBookmarkLocationFactory.Value.CreateTokenLocation(moduleId, def.MDToken.Raw); return(new TextViewBookmarkLocationResult(location, new SnapshotSpan(snapshot, span))); } return(null); }
LocationsResult GetLocations(IDocumentTab tab, VirtualSnapshotPoint?position) { var allLocations = new List <DbgCodeLocation>(); var textView = GetTextView(tab); if (textView == null) { return(new LocationsResult(dbgManager, null, allLocations)); } var pos = position ?? textView.Caret.Position.VirtualBufferPosition; if (pos.Position.Snapshot != textView.TextSnapshot) { throw new ArgumentException(); } DbgTextViewBreakpointLocationResult?res = null; foreach (var loc in dbgTextViewCodeLocationService.Value.CreateLocation(tab, textView, pos)) { UpdateResult(allLocations, textView, ref res, loc, useIfSameSpan: false); } SnapshotSpan span; if (res != null) { var resSpan = res.Value.Span.SnapshotSpan; var newStart = Min(pos.Position, resSpan.Start); var newEnd = Max(pos.Position, resSpan.End); span = new SnapshotSpan(newStart, newEnd); } else { span = new SnapshotSpan(pos.Position, new SnapshotPoint(pos.Position.Snapshot, pos.Position.Snapshot.Length)); } // This one has higher priority since it already exists (eg. could be a stack frame BP location) UpdateResult(allLocations, textView, ref res, breakpointMarker.Value.GetLocations(textView, span), useIfSameSpan: true); return(new LocationsResult(dbgManager, res, allLocations)); }
public override DbgTextViewBreakpointLocationResult?CreateLocation(IDocumentTab tab, ITextView textView, VirtualSnapshotPoint position) { var documentViewer = tab.TryGetDocumentViewer(); if (documentViewer == null) { return(null); } var methodDebugService = documentViewer.GetMethodDebugService(); if (methodDebugService == null) { return(null); } var methodStatements = methodDebugService.FindByTextPosition(position.Position, FindByTextPositionOptions.None); if (methodStatements.Count == 0) { return(null); } var textSpan = methodStatements[0].Statement.TextSpan; var snapshot = textView.TextSnapshot; if (textSpan.End > snapshot.Length) { return(null); } var span = new VirtualSnapshotSpan(new SnapshotSpan(snapshot, new Span(textSpan.Start, textSpan.Length))); var locations = new DbgCodeLocation[methodStatements.Count]; for (int i = 0; i < methodStatements.Count; i++) { var statement = methodStatements[i]; var moduleId = moduleIdProvider.Create(statement.Method.Module); locations[i] = dbgDotNetCodeLocationFactory.Value.Create(moduleId, statement.Method.MDToken.Raw, statement.Statement.ILSpan.Start); } return(new DbgTextViewBreakpointLocationResult(locations, span)); }
public override TextViewBookmarkLocationResult?CreateLocation(IDocumentTab tab, ITextView textView, VirtualSnapshotPoint position) { var documentViewer = tab.TryGetDocumentViewer(); if (documentViewer == null) { return(null); } var methodDebugService = documentViewer.GetMethodDebugService(); if (methodDebugService == null) { return(null); } // A bookmark should be set on the current line if possible, and the current position // isn't necessarily at the start of the line. var startPos = position.Position.GetContainingLine().Start; var methodStatements = methodDebugService.FindByTextPosition(startPos, FindByTextPositionOptions.None); if (methodStatements.Count == 0) { return(null); } var textSpan = methodStatements[0].Statement.TextSpan; var snapshot = textView.TextSnapshot; if (textSpan.End > snapshot.Length) { return(null); } var span = new VirtualSnapshotSpan(new SnapshotSpan(snapshot, new Span(textSpan.Start, textSpan.Length))); var statement = methodStatements[0]; var moduleId = moduleIdProvider.Create(statement.Method.Module); var location = dotNetBookmarkLocationFactory.Value.CreateMethodBodyLocation(moduleId, statement.Method.MDToken.Raw, statement.Statement.ILSpan.Start); return(new TextViewBookmarkLocationResult(location, span)); }
public static BamlTabSaver TryCreate(IDocumentTab tab, IMessageBoxService messageBoxService) { 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, messageBoxService)); }
ToggleCreateBreakpointInfoResult GetToggleCreateBreakpointInfo(IDocumentTab tab, VirtualSnapshotPoint?position) { using (var info = GetLocations(tab, position)) { var locRes = info.locRes; var bps = locRes == null?Array.Empty <DbgCodeBreakpoint>() : GetBreakpoints(locRes.Value); if (bps.Length != 0) { if (bps.All(a => a.IsEnabled)) { return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Delete, bps, Array.Empty <DbgCodeLocation>())); } return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Enable, bps, Array.Empty <DbgCodeLocation>())); } else { if (locRes == null || locRes.Value.Locations.Length == 0) { return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.None, Array.Empty <DbgCodeBreakpoint>(), Array.Empty <DbgCodeLocation>())); } return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Add, Array.Empty <DbgCodeBreakpoint>(), locRes.Value.Locations.Select(a => a.Clone()).ToArray())); } } }
LocationsResult GetLocation(IDocumentTab tab, VirtualSnapshotPoint?position) { var allLocations = new List <BookmarkLocation>(); var textView = GetTextView(tab); if (textView == null) { return(new LocationsResult(bookmarksService, null, allLocations)); } var pos = position ?? textView.Caret.Position.VirtualBufferPosition; if (pos.Position.Snapshot != textView.TextSnapshot) { throw new ArgumentException(); } TextViewBookmarkLocationResult?res = null; foreach (var lz in textViewBookmarkLocationProviders) { var result = lz.Value.CreateLocation(tab, textView, pos); if (result?.Location == null) { continue; } allLocations.Add(result.Value.Location); if (result.Value.Span.Snapshot != textView.TextSnapshot) { continue; } if (res == null || result.Value.Span.Start < res.Value.Span.Start) { res = result; } } return(new LocationsResult(bookmarksService, res, allLocations)); }
public string GetMenuHeader(IDocumentTab tab) { var ts = GetTabSaver(tab); return (ts == null ? null : ts.MenuHeader) ?? dnSpy_Resources.Button_Save; }
public bool CanSave(IDocumentTab tab) { var ts = GetTabSaver(tab); return ts != null && ts.CanSave; }
void JumpToCurrentStatement(IDocumentTab 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 IDocumentViewer); if (e.Success && !e.HasMovedCaret) { MoveCaretToCurrentStatement(e.Tab.UIContext as IDocumentViewer, canRefreshMethods); e.HasMovedCaret = true; } }); })); }
public BookmarkDocumentImpl(IDocumentTab tab) => this.tab = tab ?? throw new ArgumentNullException(nameof(tab));
public abstract IEnumerable <DbgTextViewBreakpointLocationResult> CreateLocation(IDocumentTab tab, ITextView textView, VirtualSnapshotPoint position);
public abstract void GoToLocation(IDocumentTab tab, MethodDef method, in ModuleTokenId module, uint offset);
public ITabSaver Create(IDocumentTab tab) => HexTabSaver.TryCreate(documentSaver, tab);
/// <summary> /// Constructor /// </summary> /// <param name="result">Result></param> /// <param name="tab">Tab</param> public ShowTabContentEventArgs(ShowTabContentResult result, IDocumentTab tab) { Result = result; HasMovedCaret = false; Tab = tab; }
public static SerializedTab TryCreate(IDocumentTabContentFactoryService documentTabContentFactoryService, IDocumentTab tab) { var contentSect = new SettingsSection(CONTENT_SECTION); var guid = documentTabContentFactoryService.Serialize(tab.Content, contentSect); if (guid == null) return null; contentSect.Attribute(CONTENT_GUID_ATTR, guid.Value); var uiSect = new SettingsSection(UI_SECTION); tab.UIContext.SerializeUIState(uiSect, tab.UIContext.CreateUIState()); 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 autoLoadedDocuments = new List<DsDocumentInfo>(); foreach (var f in GetAutoLoadedDocuments(tab.Content.Nodes)) autoLoadedDocuments.Add(f); return new SerializedTab(contentSect, tabUISect, uiSect, paths, autoLoadedDocuments); }
public TabVM(TabsVM owner, IDocumentTab tab) { Owner = owner; Tab = tab; var node = tab.Content.Nodes.FirstOrDefault().GetTopNode(); document = node?.Document; }
public void JumpToCurrentStatement(IDocumentTab tab) => JumpToCurrentStatement(tab, true);
public static SerializedTab TryCreate(IDocumentTabContentFactoryService documentTabContentFactoryService, IDocumentTab tab) { var contentSect = new SettingsSection(CONTENT_SECTION); var guid = documentTabContentFactoryService.Serialize(tab.Content, contentSect); if (guid == null) { return(null); } contentSect.Attribute(CONTENT_GUID_ATTR, guid.Value); var uiSect = new SettingsSection(UI_SECTION); tab.UIContext.SerializeUIState(uiSect, tab.UIContext.CreateUIState()); 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 autoLoadedDocuments = new List <DsDocumentInfo>(); foreach (var f in GetAutoLoadedDocuments(tab.Content.Nodes)) { autoLoadedDocuments.Add(f); } return(new SerializedTab(contentSect, tabUISect, uiSect, paths, autoLoadedDocuments)); }
public void Save(IDocumentTab tab) { var ts = GetTabSaver(tab); if (ts == null || !ts.CanSave) return; ts.Save(); }
public ITabSaver Create(IDocumentTab tab) => NodeTabSaver.TryCreate(documentTreeNodeDecompiler, tab, messageBoxService);
public override void GoToLocation(IDocumentTab tab, MethodDef method, in ModuleTokenId module, uint offset)
public static NodeTabSaver TryCreate(IDocumentTreeNodeDecompiler documentTreeNodeDecompiler, IDocumentTab tab, IMessageBoxService messageBoxService) { 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(messageBoxService, tab, documentTreeNodeDecompiler, decompiler, uiContext, nodes)); }
bool GoTo(IDocumentTab 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; }
BamlTabSaver(IDocumentTab tab, BamlResourceElementNode bamlNode, IDocumentViewer documentViewer, IMessageBoxService messageBoxService) { this.tab = tab; this.bamlNode = bamlNode; this.documentViewer = documentViewer; this.messageBoxService = messageBoxService; }
static ITokenResolver GetResolver(IDocumentTabService documentTabService, out IDocumentTab tab) { tab = documentTabService.ActiveTab; if (tab == null) return null; return tab.Content.Nodes.FirstOrDefault().GetModule(); }
ITextView GetTextView(IDocumentTab tab) => (tab?.UIContext as IDocumentViewer)?.TextView;
bool GoTo(IDocumentTab 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; }
public ITabSaver Create(IDocumentTab tab) => BamlTabSaver.TryCreate(tab, messageBoxService);