Skip to content

Commit 66e85df

Browse files
committed
add copyPath context menu in explorer
1 parent 8bd0cfe commit 66e85df

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,14 @@
804804
"command": "_cl.eide.project.source.folder.modify.extraArgs",
805805
"title": "%eide.explorer.folder.modify.extraArgs%"
806806
},
807+
{
808+
"command": "_cl.eide.project.source.copyPath",
809+
"title": "%eide.explorer.copyPath%"
810+
},
811+
{
812+
"command": "_cl.eide.project.source.copyRelativePath",
813+
"title": "%eide.explorer.copyRelativePath%"
814+
},
807815
{
808816
"command": "_cl.eide.project.refresh",
809817
"title": "%eide.project.refresh%",
@@ -1497,6 +1505,16 @@
14971505
"when": "viewItem == FILE_ITEM || viewItem == V_FILE_ITEM && view == cl.eide.view.projects",
14981506
"group": "1_file@0"
14991507
},
1508+
{
1509+
"command": "_cl.eide.project.source.copyPath",
1510+
"when": "viewItem == FOLDER_ROOT || viewItem == FOLDER || viewItem == EXCFOLDER || viewItem == FILE_ITEM || viewItem == EXCFILE_ITEM || viewItem == V_FILE_ITEM || viewItem == V_EXCFILE_ITEM || viewItem == OUTPUT_FILE_ITEM || viewItem == V_FOLDER || viewItem == V_FOLDER_ROOT || viewItem == V_EXCFOLDER && view == cl.eide.view.projects",
1511+
"group": "2_file@0"
1512+
},
1513+
{
1514+
"command": "_cl.eide.project.source.copyRelativePath",
1515+
"when": "viewItem == FOLDER_ROOT || viewItem == FOLDER || viewItem == EXCFOLDER || viewItem == FILE_ITEM || viewItem == EXCFILE_ITEM || viewItem == V_FILE_ITEM || viewItem == V_EXCFILE_ITEM || viewItem == OUTPUT_FILE_ITEM && view == cl.eide.view.projects",
1516+
"group": "2_file@1"
1517+
},
15001518
{
15011519
"command": "_cl.eide.project.source.file.modify.extraArgs",
15021520
"when": "viewItem == FILE_ITEM || viewItem == V_FILE_ITEM && view == cl.eide.view.projects",

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"eide.explorer.file.compile": "Compile",
7575
"eide.explorer.file.modify.extraArgs": "Show/Modify Compiler Options",
7676
"eide.explorer.folder.modify.extraArgs": "Show/Modify Compiler Options",
77+
"eide.explorer.copyPath": "Copy Path",
78+
"eide.explorer.copyRelativePath": "Copy Relative Path",
7779

7880
"eide.source.show_cmsis_config_wizard": "CMSIS Configuration Wizard",
7981
"eide.source.show.disassembly": "Show Disassembly",

package.nls.zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"eide.explorer.file.compile": "编译",
7575
"eide.explorer.file.modify.extraArgs": "查看/修改此文件的编译选项",
7676
"eide.explorer.folder.modify.extraArgs": "查看/修改此文件夹的编译选项",
77+
"eide.explorer.copyPath": "复制路径",
78+
"eide.explorer.copyRelativePath": "复制相对路径",
7779

7880
"eide.source.show_cmsis_config_wizard": "CMSIS Configuration Wizard",
7981
"eide.source.show.disassembly": "查看反汇编",

src/EIDEProjectExplorer.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,48 @@ export class ProjectExplorer implements CustomConfigurationProvider {
54105410
}
54115411
}
54125412

5413+
async copyPath(type: 'abs' | 'relative', item: ProjTreeItem) {
5414+
5415+
const project = this.getProjectByTreeItem(item);
5416+
let copiedPath: string | undefined;
5417+
5418+
if (item.type === TreeItemType.FOLDER ||
5419+
item.type === TreeItemType.FOLDER_ROOT ||
5420+
item.type === TreeItemType.EXCFOLDER) {
5421+
const dir = <File>item.val.obj;
5422+
if (type === 'abs') {
5423+
copiedPath = dir.path;
5424+
} else {
5425+
copiedPath = project?.toRelativePath(dir.path) || dir.path;
5426+
}
5427+
}
5428+
else if (item.type === TreeItemType.V_FOLDER ||
5429+
item.type === TreeItemType.V_FOLDER_ROOT ||
5430+
item.type === TreeItemType.V_EXCFOLDER) {
5431+
const vinfo = <VirtualFolderInfo>item.val.obj;
5432+
copiedPath = vinfo.path;
5433+
}
5434+
else if (item.type === TreeItemType.V_FILE_ITEM ||
5435+
item.type === TreeItemType.V_EXCFILE_ITEM) {
5436+
const vinfo = <VirtualFileInfo>item.val.obj;
5437+
if (type === 'abs') {
5438+
copiedPath = project?.toAbsolutePath(vinfo.vFile.path) || vinfo.vFile.path;
5439+
} else {
5440+
copiedPath = vinfo.path;
5441+
}
5442+
}
5443+
else if (item.val.value instanceof File) { // if value is a file, use it
5444+
if (type === 'abs') {
5445+
copiedPath = item.val.value.path;
5446+
} else {
5447+
copiedPath = project?.toRelativePath(item.val.value.path) || item.val.value.path;
5448+
}
5449+
}
5450+
5451+
if (copiedPath)
5452+
vscode.env.clipboard.writeText(copiedPath);
5453+
}
5454+
54135455
private async showDisassemblyForElf(elfPath: string, prj: AbstractProject) {
54145456

54155457
try {

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ export async function activate(context: vscode.ExtensionContext) {
210210
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.source.file.modify.extraArgs', (item) => projectExplorer.modifyExtraCompilerArgs('file', item)));
211211
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.source.file.compile', (item) => projectExplorer.compileSingleFile(item)));
212212
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.source.folder.modify.extraArgs', (item) => projectExplorer.modifyExtraCompilerArgs('folder', item)));
213+
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.source.copyPath', (item) => projectExplorer.copyPath('abs', item)));
214+
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.source.copyRelativePath', (item) => projectExplorer.copyPath('relative', item)));
213215

214216
// file other operations
215217
subscriptions.push(vscode.commands.registerCommand('_cl.eide.project.excludeSource', (item, items) => projectExplorer.ExcludeSourceFile(item, items)));

0 commit comments

Comments
 (0)