修改了保存的BUG
This commit is contained in:
@@ -760,8 +760,25 @@ class ConfigPanel {
|
||||
name: name
|
||||
};
|
||||
this.projects.push(newProject);
|
||||
// 关键修复:设置当前项目ID
|
||||
this.currentProjectId = newId;
|
||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||
this.updateWebview();
|
||||
// 关键修复:立即要求用户选择项目存储路径
|
||||
const selectedPath = await this.selectProjectPath(newId, name);
|
||||
if (selectedPath) {
|
||||
// 保存初始项目数据
|
||||
await this.saveCurrentProjectData();
|
||||
// 自动切换到飞行器视图
|
||||
this.currentView = 'aircrafts';
|
||||
this.updateWebview();
|
||||
}
|
||||
else {
|
||||
// 如果用户取消选择路径,移除刚创建的项目
|
||||
this.projects = this.projects.filter(p => p.id !== newId);
|
||||
this.currentProjectId = '';
|
||||
vscode.window.showWarningMessage('项目创建已取消');
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 删除项目
|
||||
async deleteProject(projectId) {
|
||||
@@ -807,10 +824,29 @@ class ConfigPanel {
|
||||
projectId: this.currentProjectId
|
||||
};
|
||||
this.aircrafts.push(newAircraft);
|
||||
// 新增:创建飞行器目录
|
||||
await this.createAircraftDirectory(newAircraft);
|
||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
async createAircraftDirectory(aircraft) {
|
||||
try {
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (!projectPath) {
|
||||
console.warn('未找到项目路径,跳过创建飞行器目录');
|
||||
return;
|
||||
}
|
||||
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
||||
// 创建飞行器目录
|
||||
await vscode.workspace.fs.createDirectory(aircraftDir);
|
||||
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`创建飞行器目录失败: ${error}`);
|
||||
vscode.window.showWarningMessage(`创建飞行器目录失败: ${error}`);
|
||||
}
|
||||
}
|
||||
// 删除飞行器
|
||||
async deleteAircraft(aircraftId) {
|
||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||
@@ -849,6 +885,8 @@ class ConfigPanel {
|
||||
aircraftId: this.currentAircraftId
|
||||
};
|
||||
this.containers.push(newContainer);
|
||||
// 新增:创建容器目录
|
||||
await this.createContainerDirectory(newContainer);
|
||||
// 创建两个默认配置文件
|
||||
const configCount = this.configs.length;
|
||||
// 第一个配置文件
|
||||
@@ -871,6 +909,38 @@ class ConfigPanel {
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
// 新增方法:创建容器目录
|
||||
async createContainerDirectory(container) {
|
||||
try {
|
||||
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
||||
if (!aircraft) {
|
||||
console.warn('未找到对应的飞行器,跳过创建容器目录');
|
||||
return;
|
||||
}
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (!projectPath) {
|
||||
console.warn('未找到项目路径,跳过创建容器目录');
|
||||
return;
|
||||
}
|
||||
// 构建路径:项目路径/飞行器名/容器名
|
||||
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
||||
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
|
||||
// 确保飞行器目录存在
|
||||
try {
|
||||
await vscode.workspace.fs.createDirectory(aircraftDir);
|
||||
}
|
||||
catch (error) {
|
||||
// 目录可能已存在,忽略错误
|
||||
}
|
||||
// 创建容器目录
|
||||
await vscode.workspace.fs.createDirectory(containerDir);
|
||||
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`创建容器目录失败: ${error}`);
|
||||
vscode.window.showWarningMessage(`创建容器目录失败: ${error}`);
|
||||
}
|
||||
}
|
||||
// 删除容器
|
||||
async deleteContainer(containerId) {
|
||||
const container = this.containers.find(c => c.id === containerId);
|
||||
@@ -915,10 +985,34 @@ class ConfigPanel {
|
||||
containerId: this.currentContainerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
// 新增:确保容器目录存在
|
||||
await this.ensureContainerDirectoryExists(this.currentContainerId);
|
||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
// 新增方法:确保容器目录存在
|
||||
async ensureContainerDirectoryExists(containerId) {
|
||||
try {
|
||||
const container = this.containers.find(c => c.id === containerId);
|
||||
if (!container)
|
||||
return;
|
||||
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
||||
if (!aircraft)
|
||||
return;
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (!projectPath)
|
||||
return;
|
||||
// 构建路径并创建目录
|
||||
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
||||
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
|
||||
await vscode.workspace.fs.createDirectory(aircraftDir);
|
||||
await vscode.workspace.fs.createDirectory(containerDir);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`确保容器目录存在失败: ${error}`);
|
||||
}
|
||||
}
|
||||
// 删除配置文件
|
||||
async deleteConfig(configId) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user