删除组件操作的支持
This commit is contained in:
parent
6b39670e88
commit
6f8c6ae450
11
package.json
11
package.json
|
|
@ -52,6 +52,12 @@
|
||||||
{
|
{
|
||||||
"command": "oak-assistant.reload",
|
"command": "oak-assistant.reload",
|
||||||
"title": "重新加载oak-assistant"
|
"title": "重新加载oak-assistant"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "oak-entities.deleteComponent",
|
||||||
|
"title": "删除组件",
|
||||||
|
"when": "view == oak-entities && viewItem == componentItem",
|
||||||
|
"group": "navigation"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"menus": {
|
"menus": {
|
||||||
|
|
@ -77,6 +83,11 @@
|
||||||
"command": "oak-assistant.create-oak-component",
|
"command": "oak-assistant.create-oak-component",
|
||||||
"when": "view == oak-entities && viewItem == componentsItem",
|
"when": "view == oak-entities && viewItem == componentsItem",
|
||||||
"group": "navigation"
|
"group": "navigation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "oak-entities.deleteComponent",
|
||||||
|
"when": "view == oak-entities && viewItem == componentItem",
|
||||||
|
"group": "navigation"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,10 @@ export class ComponentsItem extends TreeItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ComponentItem extends TreeItem {
|
export class ComponentItem extends TreeItem {
|
||||||
|
private readonly componentPath: string;
|
||||||
|
getComponentPath() {
|
||||||
|
return this.componentPath;
|
||||||
|
}
|
||||||
constructor(public readonly entity: string, public readonly path: string) {
|
constructor(public readonly entity: string, public readonly path: string) {
|
||||||
// 只保留最后两个\\后面的内容
|
// 只保留最后两个\\后面的内容
|
||||||
const label = path.split('\\').slice(-2).join('\\');
|
const label = path.split('\\').slice(-2).join('\\');
|
||||||
|
|
@ -134,6 +138,7 @@ export class ComponentItem extends TreeItem {
|
||||||
title: 'Open',
|
title: 'Open',
|
||||||
arguments: [vscode.Uri.file(join(path, 'index.ts'))],
|
arguments: [vscode.Uri.file(join(path, 'index.ts'))],
|
||||||
};
|
};
|
||||||
|
this.componentPath = path;
|
||||||
this.contextValue = 'componentItem'; // 添加这行,用于识别右键菜单项
|
this.contextValue = 'componentItem'; // 添加这行,用于识别右键菜单项
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { pathConfig } from '../utils/paths';
|
import { pathConfig } from '../utils/paths';
|
||||||
import { EntityItem } from './oakTreePanel';
|
import { ComponentItem, EntityItem } from './oakTreePanel';
|
||||||
import { findEntityDefFile } from '../utils/entities';
|
import { findEntityDefFile } from '../utils/entities';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { toUpperFirst } from '../utils/stringUtils';
|
import { toUpperFirst } from '../utils/stringUtils';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const pushToEntityDefinition = vscode.commands.registerCommand(
|
const pushToEntityDefinition = vscode.commands.registerCommand(
|
||||||
'oak-entities.jumpToDefinition',
|
'oak-entities.jumpToDefinition',
|
||||||
|
|
@ -65,4 +66,29 @@ const pushToEntitySchema = vscode.commands.registerCommand(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const treePanelCommands = [pushToEntityDefinition, pushToEntitySchema];
|
const deleteComponent = vscode.commands.registerCommand(
|
||||||
|
'oak-entities.deleteComponent',
|
||||||
|
async (item: ComponentItem) => {
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const componentPath = item.getComponentPath();
|
||||||
|
// 弹出提示,确认是否删除
|
||||||
|
const result = await vscode.window.showInformationMessage(
|
||||||
|
`确定要删除组件: ${item.label} 吗?`,
|
||||||
|
{ modal: true },
|
||||||
|
'确定'
|
||||||
|
);
|
||||||
|
if (result !== '确定') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 删除文件夹
|
||||||
|
fs.rmSync(componentPath, { recursive: true });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const treePanelCommands = [
|
||||||
|
pushToEntityDefinition,
|
||||||
|
pushToEntitySchema,
|
||||||
|
deleteComponent,
|
||||||
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue