Skip to content

Commit a1592c2

Browse files
committed
Merge branch 'assembly-list-dnd'
2 parents ee4259b + 4c71566 commit a1592c2

File tree

6 files changed

+98
-15
lines changed

6 files changed

+98
-15
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*------------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 ICSharpCode
3+
* Licensed under the MIT License. See LICENSE.TXT in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from "vscode";
7+
import { DecompiledTreeProvider } from "../decompiler/DecompiledTreeProvider";
8+
import { addAssemblyFromFilePath } from "./utils";
9+
import Node from "../protocol/Node";
10+
11+
export function registerAddAssemblyByPathCommand(
12+
decompiledTreeProvider: DecompiledTreeProvider,
13+
decompiledTreeView: vscode.TreeView<Node>
14+
) {
15+
return vscode.commands.registerCommand(
16+
"ilspy.addAssemblyByPath",
17+
async (filePath: string) => {
18+
addAssemblyFromFilePath(
19+
filePath,
20+
decompiledTreeProvider,
21+
decompiledTreeView
22+
);
23+
}
24+
);
25+
}

vscode-extension/src/commands/decompileAssemblyViaDialog.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as vscode from "vscode";
77
import { DecompiledTreeProvider } from "../decompiler/DecompiledTreeProvider";
88
import { addAssemblyFromFilePath } from "./utils";
99
import Node from "../protocol/Node";
10+
import { ASSEMBLY_FILE_EXTENSIONS } from "../decompiler/utils";
1011

1112
export function registerDecompileAssemblyViaDialogCommand(
1213
decompiledTreeProvider: DecompiledTreeProvider,
@@ -34,14 +35,7 @@ async function promptForAssemblyFilesPathViaDialog(): Promise<string[]> {
3435
canSelectFolders: false,
3536
canSelectMany: true,
3637
filters: {
37-
".NET Decompilables": [
38-
"dll",
39-
"exe",
40-
"winmd",
41-
"netmodule",
42-
"wasm",
43-
"nupkg",
44-
],
38+
".NET Decompilables": ASSEMBLY_FILE_EXTENSIONS,
4539
},
4640
});
4741

vscode-extension/src/decompiler/DecompiledTreeProvider.ts

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
TreeItemCollapsibleState,
1212
ProviderResult,
1313
window,
14-
ThemeIcon,
1514
ExtensionContext,
1615
commands,
1716
Uri,
18-
MarkdownString,
17+
DataTransfer,
18+
TreeDragAndDropController,
19+
CancellationToken,
1920
} from "vscode";
2021
import IILSpyBackend from "./IILSpyBackend";
2122
import Node from "../protocol/Node";
@@ -28,15 +29,26 @@ import {
2829
} from "./settings";
2930
import { getNodeIcon } from "../icons";
3031
import { NodeFlags } from "../protocol/NodeFlags";
31-
import { createNodeTooltip, getNodeContextValue, hasNodeFlag } from "./utils";
32-
33-
export class DecompiledTreeProvider implements TreeDataProvider<Node> {
32+
import {
33+
ASSEMBLY_FILE_EXTENSIONS,
34+
createNodeTooltip,
35+
getNodeContextValue,
36+
hasNodeFlag,
37+
} from "./utils";
38+
import path = require("path");
39+
import OutputWindowLogger from "../OutputWindowLogger";
40+
import { addAssemblyFromFilePath } from "../commands/utils";
41+
42+
export class DecompiledTreeProvider
43+
implements TreeDataProvider<Node>, TreeDragAndDropController<Node>
44+
{
3445
private _onDidChangeTreeData: EventEmitter<any> = new EventEmitter<any>();
3546
readonly onDidChangeTreeData: Event<any> = this._onDidChangeTreeData.event;
3647

3748
constructor(
3849
private extensionContext: ExtensionContext,
39-
private backend: IILSpyBackend
50+
private backend: IILSpyBackend,
51+
private logger: OutputWindowLogger
4052
) {}
4153

4254
public refresh(): void {
@@ -183,6 +195,43 @@ export class DecompiledTreeProvider implements TreeDataProvider<Node> {
183195
) ?? []
184196
);
185197
}
198+
199+
readonly dropMimeTypes = ["text/uri-list"];
200+
readonly dragMimeTypes = [];
201+
202+
async handleDrop(
203+
target: Node | undefined,
204+
dataTransfer: DataTransfer,
205+
token: CancellationToken
206+
): Promise<void> {
207+
const test = 1;
208+
const uris =
209+
(await dataTransfer.get("text/uri-list")?.asString())?.split("\r\n") ??
210+
[];
211+
uris.forEach((uri) => {
212+
const fileUri = Uri.parse(uri);
213+
const filePath = fileUri.fsPath;
214+
if (this.isValidFile(fileUri.fsPath)) {
215+
this.processDroppedFile(target, filePath);
216+
this.logger.writeLine(
217+
`Dropped assembly file ${filePath}, trying to add to assembly list`
218+
);
219+
} else {
220+
this.logger.writeLine(`Dropped unsupported file ${filePath}!`);
221+
}
222+
});
223+
}
224+
225+
private isValidFile(filePath: string): boolean {
226+
const ext = path.extname(filePath);
227+
return ASSEMBLY_FILE_EXTENSIONS.includes(
228+
path.extname(filePath).substring(1)
229+
);
230+
}
231+
232+
private processDroppedFile(target: Node | undefined, filePath: string): void {
233+
commands.executeCommand("ilspy.addAssemblyByPath", filePath);
234+
}
186235
}
187236

188237
function setTreeWithNodes(treeWithNodes: boolean) {

vscode-extension/src/decompiler/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import Node from "../protocol/Node";
33
import { NodeType } from "../protocol/NodeType";
44
import { NodeFlags } from "../protocol/NodeFlags";
55

6+
export const ASSEMBLY_FILE_EXTENSIONS = [
7+
"dll",
8+
"exe",
9+
"winmd",
10+
"netmodule",
11+
"wasm",
12+
"nupkg",
13+
];
14+
615
export function isTypeNode(nodeType: NodeType) {
716
return (
817
nodeType === NodeType.Class ||

vscode-extension/src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { AnalyzeResultTreeProvider } from "./decompiler/analyze/AnalyzeResultTre
4545
import { registerAnalyzeCommand } from "./commands/analyze";
4646
import { registerRefreshAssemblyListCommand } from "./commands/refreshAssemblyList";
4747
import { AssemblyNodeDecorationProvider } from "./decompiler/AssemblyNodeDecorationProvider";
48+
import { registerAddAssemblyByPathCommand } from "./commands/addAssemblyByPath";
4849

4950
let client: LanguageClient;
5051

@@ -99,7 +100,8 @@ export async function activate(context: ExtensionContext) {
99100
const ilspyBackend = new ILSpyBackend(client);
100101
const decompiledTreeProvider = new DecompiledTreeProvider(
101102
context,
102-
ilspyBackend
103+
ilspyBackend,
104+
logger
103105
);
104106
const decompiledTreeView = createDecompiledTreeView(decompiledTreeProvider);
105107
disposables.push(decompiledTreeView);
@@ -110,6 +112,9 @@ export async function activate(context: ExtensionContext) {
110112
window.registerFileDecorationProvider(assemblyNodeDecorationProvider)
111113
);
112114

115+
disposables.push(
116+
registerAddAssemblyByPathCommand(decompiledTreeProvider, decompiledTreeView)
117+
);
113118
disposables.push(
114119
registerDecompileAssemblyInWorkspaceCommand(
115120
decompiledTreeProvider,

vscode-extension/src/view/treeViews.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function createDecompiledTreeView(
1313
return window.createTreeView("ilspyDecompiledMembers", {
1414
treeDataProvider: decompiledTreeProvider,
1515
showCollapseAll: true,
16+
dragAndDropController: decompiledTreeProvider
1617
});
1718
}
1819

0 commit comments

Comments
 (0)