internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList<MethodSourceStatement>? statements = null) { if (!CanExecute(editCodeVMCreator, nodes)) return; var methodNode = (MethodNode)nodes[0]; var modNode = methodNode.GetModuleNode(); Debug.Assert(!(modNode is null)); if (modNode is null) throw new InvalidOperationException(); var module = modNode.Document.ModuleDef; Debug.Assert(!(module is null)); if (module is null) throw new InvalidOperationException(); using (var vm = editCodeVMCreator.CreateEditMethodCode(methodNode.MethodDef, statements ?? Array.Empty<MethodSourceStatement>())) { var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = $"{win.Title} - {methodNode.ToString()}"; if (win.ShowDialog() != true) return; Debug.Assert(!(vm.Result is null)); undoCommandService.Value.Add(new EditMethodBodyCodeCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); } }
static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var asmNode = nodes[0] as AssemblyDocumentNode; ModuleDocumentNode modNode; if (asmNode != null) { asmNode.TreeNode.EnsureChildrenLoaded(); modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; } else { modNode = nodes[0] as ModuleDocumentNode; } Debug.Assert(modNode != null); if (modNode == null) { return; } var module = modNode.Document.ModuleDef; Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } if (module.IsManifestModule) { asmNode = modNode.TreeNode.Parent?.Data as AssemblyDocumentNode; } else { asmNode = null; } var vm = editCodeVMCreator.CreateEditAssembly(module); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = $"{dnSpy_AsmEditor_Resources.EditAssemblyCode} - {asmNode?.ToString() ?? modNode.ToString()}"; if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new EditAssemblyCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var modNode = GetModuleNode(nodes[0]); Debug2.Assert(modNode is not null); if (modNode is null) { return; } var module = modNode.Document.ModuleDef; Debug2.Assert(module is not null); if (module is null) { throw new InvalidOperationException(); } AssemblyDocumentNode?asmNode; if (module.IsManifestModule) { asmNode = modNode.TreeNode.Parent?.Data as AssemblyDocumentNode; } else { asmNode = null; } var vm = editCodeVMCreator.CreateAddClass(module); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = $"{dnSpy_AsmEditor_Resources.EditCodeAddClass} - {asmNode?.ToString() ?? modNode.ToString()}"; if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug2.Assert(vm.Result is not null); undoCommandService.Value.Add(new AddClassCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IMethodAnnotations> methodAnnotations, Lazy <IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes, uint[] offsets = null) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var methodNode = (IMethodNode)nodes[0]; var modNode = methodNode.GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) { throw new InvalidOperationException(); } var module = modNode.DnSpyFile.ModuleDef; Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } var vm = editCodeVMCreator.Create(methodNode.MethodDef); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appWindow.MainWindow; win.Title = string.Format("{0} - {1}", win.Title, methodNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandManager.Value.Add(new EditMethodBodyCodeCommand(methodAnnotations, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IMethodAnnotations> methodAnnotations, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList <MethodSourceStatement> statements = null) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var methodNode = (MethodNode)nodes[0]; var modNode = methodNode.GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) { throw new InvalidOperationException(); } var module = modNode.Document.ModuleDef; Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } var vm = editCodeVMCreator.Create(methodNode.MethodDef, statements ?? Array.Empty <MethodSourceStatement>()); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = string.Format("{0} - {1}", win.Title, methodNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new EditMethodBodyCodeCommand(methodAnnotations, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList <MethodSourceStatement> statements = null) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var node = nodes[0]; var tokNode = node as IMDTokenNode; var defToEdit = tokNode?.Reference as IMemberDef; if (defToEdit == null) { return; } TypeNode typeNode = null; for (TreeNodeData n = node; n != null;) { var t = n as TypeNode; if (t != null) { typeNode = t; } n = n.TreeNode.Parent?.Data; } if (typeNode == null) { return; } var asmNode = nodes[0] as AssemblyDocumentNode; ModuleDocumentNode modNode; if (asmNode != null) { asmNode.TreeNode.EnsureChildrenLoaded(); modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; } else { modNode = nodes[0].GetModuleNode(); } Debug.Assert(modNode != null); if (modNode == null) { return; } var vm = editCodeVMCreator.CreateEditClass(defToEdit, statements ?? Array.Empty <MethodSourceStatement>()); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = string.Format("{0} - {1}", dnSpy_AsmEditor_Resources.EditCodeEditClass, typeNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new EditClassCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) { if (!CanExecute(editCodeVMCreator, nodes)) return; var asmNode = nodes[0] as AssemblyDocumentNode; ModuleDocumentNode modNode; if (asmNode != null) { asmNode.TreeNode.EnsureChildrenLoaded(); modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; } else modNode = nodes[0].GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) return; var module = modNode.Document.ModuleDef; Debug.Assert(module != null); if (module == null) throw new InvalidOperationException(); if (module.IsManifestModule) asmNode = modNode.TreeNode.Parent?.Data as AssemblyDocumentNode; else asmNode = null; var vm = editCodeVMCreator.CreateAddClass(module); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = string.Format("{0} - {1}", dnSpy_AsmEditor_Resources.EditCodeAddClass, asmNode?.ToString() ?? modNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new AddClassCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) { if (!CanExecute(editCodeVMCreator, nodes)) { return; } var node = nodes[0]; var tokNode = node as IMDTokenNode; var defToEdit = tokNode?.Reference as IMemberDef; if (defToEdit is null) { return; } TypeNode?typeNode = null; for (TreeNodeData?n = node; n is not null;) { if (n is TypeNode t) { typeNode = t; } n = n.TreeNode.Parent?.Data; } if (typeNode is null) { return; } var asmNode = nodes[0] as AssemblyDocumentNode; ModuleDocumentNode?modNode; if (asmNode is not null) { asmNode.TreeNode.EnsureChildrenLoaded(); modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; } else { modNode = nodes[0].GetModuleNode(); } Debug2.Assert(modNode is not null); if (modNode is null) { return; } var vm = editCodeVMCreator.CreateAddMembers(defToEdit); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = $"{dnSpy_AsmEditor_Resources.EditCodeAddClassMembers} - {typeNode.ToString()}"; if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug2.Assert(vm.Result is not null); undoCommandService.Value.Add(new AddClassMembersCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList<MethodSourceStatement> statements = null) { if (!CanExecute(editCodeVMCreator, nodes)) return; var node = nodes[0]; var tokNode = node as IMDTokenNode; var defToEdit = tokNode?.Reference as IMemberDef; if (defToEdit == null) return; TypeNode typeNode = null; for (TreeNodeData n = node; n != null;) { var t = n as TypeNode; if (t != null) typeNode = t; n = n.TreeNode.Parent?.Data; } if (typeNode == null) return; var asmNode = nodes[0] as AssemblyDocumentNode; ModuleDocumentNode modNode; if (asmNode != null) { asmNode.TreeNode.EnsureChildrenLoaded(); modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; } else modNode = nodes[0].GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) return; var vm = editCodeVMCreator.CreateEditClass(defToEdit, statements ?? Array.Empty<MethodSourceStatement>()); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = string.Format("{0} - {1}", dnSpy_AsmEditor_Resources.EditCodeEditClass, typeNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new EditClassCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }
internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList<MethodSourceStatement> statements = null) { if (!CanExecute(editCodeVMCreator, nodes)) return; var methodNode = (MethodNode)nodes[0]; var modNode = methodNode.GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) throw new InvalidOperationException(); var module = modNode.Document.ModuleDef; Debug.Assert(module != null); if (module == null) throw new InvalidOperationException(); var vm = editCodeVMCreator.CreateEditMethodCode(methodNode.MethodDef, statements ?? Array.Empty<MethodSourceStatement>()); var win = new EditCodeDlg(); win.DataContext = vm; win.Owner = appService.MainWindow; win.Title = string.Format("{0} - {1}", win.Title, methodNode.ToString()); if (win.ShowDialog() != true) { vm.Dispose(); return; } Debug.Assert(vm.Result != null); undoCommandService.Value.Add(new EditMethodBodyCodeCommand(addUpdatedNodesHelperProvider, modNode, vm.Result)); vm.Dispose(); }