Skip to content

Commit dec9514

Browse files
fix winform control complie (#420)
Co-authored-by: ElektroKill <[email protected]>
1 parent ba46f03 commit dec9514

26 files changed

+241
-57
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Copyright (C) 2026 ElektroKill
3+
4+
This file is part of dnSpy
5+
6+
dnSpy is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
dnSpy is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
using System;
21+
using System.Collections.Generic;
22+
using System.ComponentModel.Composition;
23+
using System.Diagnostics;
24+
using System.Linq;
25+
using dnlib.DotNet;
26+
using dnSpy.AsmEditor.Commands;
27+
using dnSpy.Contracts.Documents.TreeView;
28+
using dnSpy.Contracts.Menus;
29+
30+
namespace dnSpy.AsmEditor.Compiler {
31+
sealed class LoadDependenciesCommands {
32+
[ExportMenuItem(Header = "res:LoadDependenciesCommand", Group = MenuConstants.GROUP_CTX_DOCUMENTS_ASMED_ILED, Order = 28.999)]
33+
sealed class DocumentsCommand : DocumentsContextMenuHandler {
34+
public override bool IsVisible(AsmEditorContext context) => LoadDependenciesCommands.CanExecute(context.Nodes);
35+
public override void Execute(AsmEditorContext context) => LoadDependenciesCommands.Execute(context.Nodes, false);
36+
}
37+
38+
[ExportMenuItem(OwnerGuid = MenuConstants.APP_MENU_EDIT_GUID, Header = "res:LoadDependenciesCommand", Group = MenuConstants.GROUP_APP_MENU_EDIT_ASMED_SETTINGS, Order = 58.999)]
39+
sealed class EditMenuCommand : EditMenuHandler {
40+
[ImportingConstructor]
41+
EditMenuCommand(IAppService appService) : base(appService.DocumentTreeView) { }
42+
43+
public override bool IsVisible(AsmEditorContext context) => LoadDependenciesCommands.CanExecute(context.Nodes);
44+
public override void Execute(AsmEditorContext context) => LoadDependenciesCommands.Execute(context.Nodes, false);
45+
}
46+
47+
[ExportMenuItem(Header = "res:LoadDependenciesRecursiveCommand", Group = MenuConstants.GROUP_CTX_DOCUMENTS_ASMED_ILED, Order = 29.999)]
48+
sealed class RecursiveDocumentsCommand : DocumentsContextMenuHandler {
49+
public override bool IsVisible(AsmEditorContext context) => LoadDependenciesCommands.CanExecute(context.Nodes);
50+
public override void Execute(AsmEditorContext context) => LoadDependenciesCommands.Execute(context.Nodes, true);
51+
}
52+
53+
[ExportMenuItem(OwnerGuid = MenuConstants.APP_MENU_EDIT_GUID, Header = "res:LoadDependenciesRecursiveCommand", Group = MenuConstants.GROUP_APP_MENU_EDIT_ASMED_SETTINGS, Order = 59.999)]
54+
sealed class RecursiveEditMenuCommand : EditMenuHandler {
55+
[ImportingConstructor]
56+
RecursiveEditMenuCommand(IAppService appService) : base(appService.DocumentTreeView) { }
57+
58+
public override bool IsVisible(AsmEditorContext context) => LoadDependenciesCommands.CanExecute(context.Nodes);
59+
public override void Execute(AsmEditorContext context) => LoadDependenciesCommands.Execute(context.Nodes, true);
60+
}
61+
62+
static bool CanExecute(DocumentTreeNodeData[] nodes) => nodes.Length == 1 && GetModuleNode(nodes[0]) is not null;
63+
64+
static ModuleDocumentNode? GetModuleNode(DocumentTreeNodeData node) {
65+
if (node is AssemblyDocumentNode asmNode) {
66+
asmNode.TreeNode.EnsureChildrenLoaded();
67+
return asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode;
68+
}
69+
70+
return node.GetModuleNode();
71+
}
72+
73+
static void Execute(DocumentTreeNodeData[] nodes, bool recursive) {
74+
if (!CanExecute(nodes))
75+
return;
76+
77+
var modNode = GetModuleNode(nodes[0]);
78+
Debug2.Assert(modNode is not null);
79+
if (modNode is null)
80+
return;
81+
82+
var module = modNode.Document.ModuleDef;
83+
Debug2.Assert(module is not null);
84+
if (module is null)
85+
throw new InvalidOperationException();
86+
87+
var documentService = modNode.Context.DocumentTreeView.DocumentService;
88+
89+
if (!recursive) {
90+
foreach (var assemblyRef in module.GetAssemblyRefs())
91+
documentService.Resolve(assemblyRef, module);
92+
}
93+
else {
94+
var processedModules = new HashSet<ModuleDef>();
95+
96+
var queue = new Stack<ModuleDef>();
97+
queue.Push(module);
98+
99+
while (queue.Count > 0) {
100+
var mod = queue.Pop();
101+
if (!processedModules.Add(mod))
102+
continue;
103+
104+
foreach (var assemblyRef in mod.GetAssemblyRefs()) {
105+
var asm = documentService.Resolve(assemblyRef, mod);
106+
if (asm?.ModuleDef is null)
107+
continue;
108+
queue.Push(asm.ModuleDef);
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.cs.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@
950950
<value>Opravdu chcete zrušit ukládání?</value>
951951
</data>
952952
<data name="AskCancelSaveCloseWindow" xml:space="preserve">
953-
<value>Ukládání se právě stornuje.
953+
<value>Ukládání se právě stornuje.
954954
Opravdu chcete zavřít okno?</value>
955955
</data>
956956
<data name="AskDeleteField" xml:space="preserve">

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.de.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.es-ES.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.fa.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.fr.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.hu.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.it.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

Extensions/dnSpy.AsmEditor/Properties/dnSpy.AsmEditor.Resources.pt-BR.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema

0 commit comments

Comments
 (0)