0
0

修复了拉取出现的bug,完善了改名功能

This commit is contained in:
xubing
2025-12-06 18:05:35 +08:00
parent 46c184b920
commit 11c405f79a
10 changed files with 650 additions and 98 deletions

View File

@@ -352,18 +352,18 @@ export class ConfigPanel {
'goBackToAircrafts': () => this.handleGoBackToAircrafts(),
'goBackToContainers': () => this.handleGoBackToContainers(),
// 项目管理
'updateProjectName': (data) => this.updateProjectName(data.projectId, data.name),
// 项目管理 (MODIFIED)
'updateProjectName': (data) => this.updateProjectName(data.projectId, data.name), // <-- MODIFIED
'createProject': (data) => this.createProject(data.name),
'deleteProject': (data) => this.deleteProject(data.projectId),
// 飞行器管理
'updateAircraftName': (data) => this.updateAircraftName(data.aircraftId, data.name),
// 飞行器管理 (MODIFIED)
'updateAircraftName': (data) => this.updateAircraftName(data.aircraftId, data.name), // <-- MODIFIED
'createAircraft': (data) => this.createAircraft(data.name),
'deleteAircraft': (data) => this.deleteAircraft(data.aircraftId),
// 容器管理
'updateContainerName': (data) => this.updateContainerName(data.containerId, data.name),
// 容器管理 (MODIFIED)
'updateContainerName': (data) => this.updateContainerName(data.containerId, data.name), // <-- MODIFIED
'createContainer': (data) => this.createContainer(data.name),
'deleteContainer': (data) => this.deleteContainer(data.containerId),
@@ -483,14 +483,39 @@ export class ConfigPanel {
}
// =============================================
// 项目管理方法
// 项目管理方法 (MODIFIED)
// =============================================
/**
* 重命名项目更新内存数据、重命名磁盘文件夹、更新项目路径MODIFIED
*/
private async updateProjectName(projectId: string, newName: string): Promise<void> {
if (this.projectService.updateProjectName(projectId, newName)) {
vscode.window.showInformationMessage(`项目名称更新: ${newName}`);
await this.saveCurrentProjectData();
this.updateWebview();
const project = this.projectService.getProjects().find(p => p.id === projectId);
if (!project) return;
const paths = this.projectService.getProjectOldAndNewPaths(projectId, newName);
if (!paths) {
vscode.window.showErrorMessage('无法获取项目路径');
return;
}
try {
// 1. 重命名磁盘文件夹
await this.projectService.renameDirectoryOnDisk(paths.oldPath, paths.newPath);
// 2. 更新内存中的项目名称和项目路径
if (this.projectService.updateProjectName(projectId, newName)) {
// 必须更新 projectPaths map
this.projectService.setProjectPath(projectId, paths.newPath);
// 3. 保存数据到新的项目路径下的 .dcsp-data.json
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`✅ 项目名称和文件夹已更新: ${newName}`);
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`❌ 重命名项目文件夹失败: ${error}`);
}
}
@@ -502,27 +527,87 @@ export class ConfigPanel {
this.updateWebview();
}
/**
* 删除项目,同时删除磁盘上的文件夹
*/
private async deleteProject(projectId: string): Promise<void> {
if (this.projectService.deleteProject(projectId)) {
if (this.currentProjectId === projectId) {
this.currentProjectId = '';
this.currentView = 'projects';
const project = this.projectService.getProjects().find(p => p.id === projectId);
// 获取项目存储路径
const projectPath = this.projectService.getProjectPath(projectId);
if (!project) return;
const confirm = await vscode.window.showWarningMessage(
`确定要删除项目 "${project.name}" 吗?这将同时删除磁盘上的文件夹及其所有内容。`,
{ modal: true },
'确定删除',
'取消'
);
if (confirm !== '确定删除') {
return;
}
try {
// 1. 删除磁盘上的文件夹
if (projectPath) {
await this.projectService.deleteDirectoryFromDisk(projectPath);
}
vscode.window.showInformationMessage('项目已删除');
await this.saveCurrentProjectData();
this.updateWebview();
// 2. 从内存中删除 (同时会清理所有子数据)
if (this.projectService.deleteProject(projectId)) {
// 如果删除的是当前正在查看的项目,则返回 Projects 视图
if (this.currentProjectId === projectId) {
this.currentProjectId = '';
this.currentView = 'projects';
}
vscode.window.showInformationMessage(`项目已删除: ${project.name}`);
// 如果还有其他项目在内存中,保存一下最新的数据状态
if (this.currentProjectId) {
await this.saveCurrentProjectData();
}
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`删除项目文件夹失败: ${error}`);
}
}
// =============================================
// 飞行器管理方法
// 飞行器管理方法 (MODIFIED)
// =============================================
/**
* 重命名飞行器更新内存数据、重命名磁盘文件夹MODIFIED
*/
private async updateAircraftName(aircraftId: string, newName: string): Promise<void> {
if (this.projectService.updateAircraftName(aircraftId, newName)) {
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
await this.saveCurrentProjectData();
this.updateWebview();
const aircraft = this.projectService.getAircraft(aircraftId);
if (!aircraft) return;
const paths = this.projectService.getAircraftOldAndNewPaths(aircraftId, newName);
if (!paths) {
vscode.window.showErrorMessage('无法获取飞行器路径');
return;
}
try {
// 1. 重命名磁盘文件夹
await this.projectService.renameDirectoryOnDisk(paths.oldPath, paths.newPath);
// 2. 更新内存中的飞行器名称
if (this.projectService.updateAircraftName(aircraftId, newName)) {
// 3. 保存数据到 .dcsp-data.json
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`✅ 飞行器名称和文件夹已更新: ${newName}`);
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`❌ 重命名飞行器文件夹失败: ${error}`);
}
}
@@ -538,23 +623,75 @@ export class ConfigPanel {
this.updateWebview();
}
/**
* 删除飞行器,同时删除磁盘上的文件夹
*/
private async deleteAircraft(aircraftId: string): Promise<void> {
if (this.projectService.deleteAircraft(aircraftId)) {
vscode.window.showInformationMessage('飞行器已删除');
await this.saveCurrentProjectData();
this.updateWebview();
const aircraft = this.projectService.getAircraftsByProject(this.currentProjectId)
.find(a => a.id === aircraftId);
if (!aircraft) return;
const confirm = await vscode.window.showWarningMessage(
`确定要删除飞行器 "${aircraft.name}" 吗?这将同时删除磁盘上的文件夹。`,
{ modal: true },
'确定删除',
'取消'
);
if (confirm !== '确定删除') {
return;
}
const dirPath = this.projectService.getAircraftDirectoryPath(aircraftId);
try {
// 1. 删除磁盘上的文件夹
if (dirPath) {
await this.projectService.deleteDirectoryFromDisk(dirPath);
}
// 2. 从内存中删除 (同时会清理所有子数据)
if (this.projectService.deleteAircraft(aircraftId)) {
vscode.window.showInformationMessage(`飞行器已删除: ${aircraft.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`删除飞行器文件夹失败: ${error}`);
}
}
// =============================================
// 容器管理方法
// 容器管理方法 (MODIFIED)
// =============================================
/**
* 重命名容器更新内存数据、重命名磁盘文件夹MODIFIED
*/
private async updateContainerName(containerId: string, newName: string): Promise<void> {
if (this.projectService.updateContainerName(containerId, newName)) {
vscode.window.showInformationMessage(`容器名称更新: ${newName}`);
await this.saveCurrentProjectData();
this.updateWebview();
const container = this.projectService.getContainer(containerId);
if (!container) return;
const paths = this.projectService.getContainerOldAndNewPaths(containerId, newName);
if (!paths) {
vscode.window.showErrorMessage('无法获取容器路径');
return;
}
try {
// 1. 重命名磁盘文件夹
await this.projectService.renameDirectoryOnDisk(paths.oldPath, paths.newPath);
// 2. 更新内存中的容器名称
if (this.projectService.updateContainerName(containerId, newName)) {
// 3. 保存数据到 .dcsp-data.json
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`✅ 容器名称和文件夹已更新: ${newName}`);
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`❌ 重命名容器文件夹失败: ${error}`);
}
}
@@ -570,11 +707,41 @@ export class ConfigPanel {
this.updateWebview();
}
/**
* 删除容器,同时删除磁盘上的文件夹
*/
private async deleteContainer(containerId: string): Promise<void> {
if (this.projectService.deleteContainer(containerId)) {
vscode.window.showInformationMessage('容器已删除');
await this.saveCurrentProjectData();
this.updateWebview();
const container = this.projectService.getContainersByAircraft(this.currentAircraftId)
.find(c => c.id === containerId);
if (!container) return;
const confirm = await vscode.window.showWarningMessage(
`确定要删除容器 "${container.name}" 吗?这将同时删除磁盘上的文件夹。`,
{ modal: true },
'确定删除',
'取消'
);
if (confirm !== '确定删除') {
return;
}
const dirPath = this.projectService.getContainerDirectoryPath(containerId);
try {
// 1. 删除磁盘上的文件夹
if (dirPath) {
await this.projectService.deleteDirectoryFromDisk(dirPath);
}
// 2. 从内存中删除 (同时会清理所有子数据)
if (this.projectService.deleteContainer(containerId)) {
vscode.window.showInformationMessage(`容器已删除: ${container.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
}
} catch (error) {
vscode.window.showErrorMessage(`删除容器文件夹失败: ${error}`);
}
}
@@ -1404,16 +1571,13 @@ export class ConfigPanel {
const aircraft = this.projectService.getAircraftsByProject(this.currentProjectId).find(a => a.id === id);
name = aircraft?.name || 'Aircraft';
if (aircraft) {
fullPath = path.join(this.projectService.getProjectPath(aircraft.projectId) || '', aircraft.name);
fullPath = this.projectService.getAircraftDirectoryPath(id);
}
} else if (type === 'container') {
const container = this.projectService.getContainersByAircraft(this.currentAircraftId).find(c => c.id === id);
name = container?.name || 'Container';
if (container) {
const aircraft = this.projectService.getAircraftsByProject(this.currentProjectId).find(a => a.id === container.aircraftId);
if (aircraft) {
fullPath = path.join(this.projectService.getProjectPath(aircraft.projectId) || '', aircraft.name, container.name);
}
fullPath = this.projectService.getContainerDirectoryPath(id);
}
}