修改了保存的BUG
This commit is contained in:
@@ -760,9 +760,26 @@ class ConfigPanel {
|
|||||||
name: name
|
name: name
|
||||||
};
|
};
|
||||||
this.projects.push(newProject);
|
this.projects.push(newProject);
|
||||||
|
// 关键修复:设置当前项目ID
|
||||||
|
this.currentProjectId = newId;
|
||||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||||
|
// 关键修复:立即要求用户选择项目存储路径
|
||||||
|
const selectedPath = await this.selectProjectPath(newId, name);
|
||||||
|
if (selectedPath) {
|
||||||
|
// 保存初始项目数据
|
||||||
|
await this.saveCurrentProjectData();
|
||||||
|
// 自动切换到飞行器视图
|
||||||
|
this.currentView = 'aircrafts';
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// 如果用户取消选择路径,移除刚创建的项目
|
||||||
|
this.projects = this.projects.filter(p => p.id !== newId);
|
||||||
|
this.currentProjectId = '';
|
||||||
|
vscode.window.showWarningMessage('项目创建已取消');
|
||||||
|
this.updateWebview();
|
||||||
|
}
|
||||||
|
}
|
||||||
// 删除项目
|
// 删除项目
|
||||||
async deleteProject(projectId) {
|
async deleteProject(projectId) {
|
||||||
const project = this.projects.find(p => p.id === projectId);
|
const project = this.projects.find(p => p.id === projectId);
|
||||||
@@ -807,10 +824,29 @@ class ConfigPanel {
|
|||||||
projectId: this.currentProjectId
|
projectId: this.currentProjectId
|
||||||
};
|
};
|
||||||
this.aircrafts.push(newAircraft);
|
this.aircrafts.push(newAircraft);
|
||||||
|
// 新增:创建飞行器目录
|
||||||
|
await this.createAircraftDirectory(newAircraft);
|
||||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
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) {
|
async deleteAircraft(aircraftId) {
|
||||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||||
@@ -849,6 +885,8 @@ class ConfigPanel {
|
|||||||
aircraftId: this.currentAircraftId
|
aircraftId: this.currentAircraftId
|
||||||
};
|
};
|
||||||
this.containers.push(newContainer);
|
this.containers.push(newContainer);
|
||||||
|
// 新增:创建容器目录
|
||||||
|
await this.createContainerDirectory(newContainer);
|
||||||
// 创建两个默认配置文件
|
// 创建两个默认配置文件
|
||||||
const configCount = this.configs.length;
|
const configCount = this.configs.length;
|
||||||
// 第一个配置文件
|
// 第一个配置文件
|
||||||
@@ -871,6 +909,38 @@ class ConfigPanel {
|
|||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
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) {
|
async deleteContainer(containerId) {
|
||||||
const container = this.containers.find(c => c.id === containerId);
|
const container = this.containers.find(c => c.id === containerId);
|
||||||
@@ -915,10 +985,34 @@ class ConfigPanel {
|
|||||||
containerId: this.currentContainerId
|
containerId: this.currentContainerId
|
||||||
};
|
};
|
||||||
this.configs.push(newConfig);
|
this.configs.push(newConfig);
|
||||||
|
// 新增:确保容器目录存在
|
||||||
|
await this.ensureContainerDirectoryExists(this.currentContainerId);
|
||||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
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) {
|
async deleteConfig(configId) {
|
||||||
const config = this.configs.find(c => c.id === configId);
|
const config = this.configs.find(c => c.id === configId);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -934,9 +934,28 @@ export class ConfigPanel {
|
|||||||
};
|
};
|
||||||
this.projects.push(newProject);
|
this.projects.push(newProject);
|
||||||
|
|
||||||
|
// 关键修复:设置当前项目ID
|
||||||
|
this.currentProjectId = newId;
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||||
|
|
||||||
|
// 关键修复:立即要求用户选择项目存储路径
|
||||||
|
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();
|
this.updateWebview();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除项目
|
// 删除项目
|
||||||
private async deleteProject(projectId: string) {
|
private async deleteProject(projectId: string) {
|
||||||
@@ -987,11 +1006,34 @@ export class ConfigPanel {
|
|||||||
};
|
};
|
||||||
this.aircrafts.push(newAircraft);
|
this.aircrafts.push(newAircraft);
|
||||||
|
|
||||||
|
// 新增:创建飞行器目录
|
||||||
|
await this.createAircraftDirectory(newAircraft);
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async createAircraftDirectory(aircraft: Aircraft): Promise<void> {
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除飞行器
|
// 删除飞行器
|
||||||
private async deleteAircraft(aircraftId: string) {
|
private async deleteAircraft(aircraftId: string) {
|
||||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||||
@@ -1028,7 +1070,6 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newId = 'c' + (this.containers.length + 1);
|
const newId = 'c' + (this.containers.length + 1);
|
||||||
|
|
||||||
const newContainer: Container = {
|
const newContainer: Container = {
|
||||||
id: newId,
|
id: newId,
|
||||||
name: name,
|
name: name,
|
||||||
@@ -1036,6 +1077,9 @@ export class ConfigPanel {
|
|||||||
};
|
};
|
||||||
this.containers.push(newContainer);
|
this.containers.push(newContainer);
|
||||||
|
|
||||||
|
// 新增:创建容器目录
|
||||||
|
await this.createContainerDirectory(newContainer);
|
||||||
|
|
||||||
// 创建两个默认配置文件
|
// 创建两个默认配置文件
|
||||||
const configCount = this.configs.length;
|
const configCount = this.configs.length;
|
||||||
|
|
||||||
@@ -1060,8 +1104,44 @@ export class ConfigPanel {
|
|||||||
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增方法:创建容器目录
|
||||||
|
private async createContainerDirectory(container: Container): Promise<void> {
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除容器
|
// 删除容器
|
||||||
private async deleteContainer(containerId: string) {
|
private async deleteContainer(containerId: string) {
|
||||||
const container = this.containers.find(c => c.id === containerId);
|
const container = this.containers.find(c => c.id === containerId);
|
||||||
@@ -1112,10 +1192,37 @@ export class ConfigPanel {
|
|||||||
};
|
};
|
||||||
this.configs.push(newConfig);
|
this.configs.push(newConfig);
|
||||||
|
|
||||||
|
// 新增:确保容器目录存在
|
||||||
|
await this.ensureContainerDirectoryExists(this.currentContainerId);
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增方法:确保容器目录存在
|
||||||
|
private async ensureContainerDirectoryExists(containerId: string): Promise<void> {
|
||||||
|
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}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除配置文件
|
// 删除配置文件
|
||||||
private async deleteConfig(configId: string) {
|
private async deleteConfig(configId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user