暂时添加了合并功能,但是存在很多BUG
This commit is contained in:
@@ -62,6 +62,7 @@ class ConfigPanel {
|
||||
this.containers = [];
|
||||
this.configs = [];
|
||||
this.gitRepos = []; // Git 仓库数据
|
||||
this.mergedFolders = [];
|
||||
// Git 文件树
|
||||
this.currentRepoFileTree = [];
|
||||
// 项目存储路径映射
|
||||
@@ -211,6 +212,18 @@ class ConfigPanel {
|
||||
case 'openConfigFileInVSCode':
|
||||
await this.openConfigFileInVSCode(data.configId);
|
||||
break;
|
||||
case 'mergeConfigs':
|
||||
await this.mergeConfigs(data.configIds, data.displayName, data.folderName);
|
||||
break;
|
||||
case 'deleteMergedFolder':
|
||||
await this.deleteMergedFolder(data.folderId);
|
||||
break;
|
||||
case 'openMergedFolderInVSCode':
|
||||
await this.openMergedFolderInVSCode(data.folderId);
|
||||
break;
|
||||
case 'loadMergedFolder':
|
||||
await this.loadMergedFolder(data.folderId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -669,18 +682,20 @@ class ConfigPanel {
|
||||
const currentProjectContainers = this.containers.filter(c => currentAircraftIds.includes(c.aircraftId));
|
||||
const currentContainerIds = currentProjectContainers.map(c => c.id);
|
||||
const currentProjectConfigs = this.configs.filter(cfg => currentContainerIds.includes(cfg.containerId));
|
||||
// 只保存与当前项目容器相关的 Git 仓库
|
||||
// 只保存与当前项目容器相关的 Git 仓库和合并文件夹
|
||||
const currentProjectGitRepos = this.gitRepos.filter(repo => currentContainerIds.includes(repo.containerId));
|
||||
const currentProjectMergedFolders = this.mergedFolders.filter(folder => currentContainerIds.includes(folder.containerId));
|
||||
const data = {
|
||||
projects: this.projects.filter(p => p.id === this.currentProjectId),
|
||||
aircrafts: currentProjectAircrafts,
|
||||
containers: currentProjectContainers,
|
||||
configs: currentProjectConfigs,
|
||||
gitRepos: currentProjectGitRepos // 保存 Git 仓库数据
|
||||
gitRepos: currentProjectGitRepos,
|
||||
mergedFolders: currentProjectMergedFolders // 保存合并文件夹数据
|
||||
};
|
||||
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
|
||||
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
|
||||
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库');
|
||||
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库和', currentProjectMergedFolders.length, '个合并文件夹');
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
|
||||
@@ -709,7 +724,8 @@ class ConfigPanel {
|
||||
this.aircrafts = [];
|
||||
this.containers = [];
|
||||
this.configs = [];
|
||||
this.gitRepos = []; // 清空 Git 仓库数据
|
||||
this.gitRepos = [];
|
||||
this.mergedFolders = []; // 清空合并文件夹数据
|
||||
// 验证数据格式并加载
|
||||
if (data.projects && Array.isArray(data.projects)) {
|
||||
this.projects = data.projects;
|
||||
@@ -724,7 +740,10 @@ class ConfigPanel {
|
||||
this.configs = data.configs;
|
||||
}
|
||||
if (data.gitRepos && Array.isArray(data.gitRepos)) {
|
||||
this.gitRepos = data.gitRepos; // 加载 Git 仓库数据
|
||||
this.gitRepos = data.gitRepos;
|
||||
}
|
||||
if (data.mergedFolders && Array.isArray(data.mergedFolders)) {
|
||||
this.mergedFolders = data.mergedFolders; // 加载合并文件夹数据
|
||||
}
|
||||
// 设置当前项目为第一个项目(如果有的话)
|
||||
if (this.projects.length > 0) {
|
||||
@@ -732,7 +751,7 @@ class ConfigPanel {
|
||||
this.projectPaths.set(this.currentProjectId, projectPath);
|
||||
this.currentView = 'aircrafts';
|
||||
}
|
||||
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库`);
|
||||
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库和 ${this.mergedFolders.length} 个合并文件夹`);
|
||||
this.updateWebview();
|
||||
return true;
|
||||
}
|
||||
@@ -1236,15 +1255,17 @@ class ConfigPanel {
|
||||
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
||||
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||
const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId);
|
||||
// 获取当前容器的 Git 仓库
|
||||
// 获取当前容器的 Git 仓库和合并文件夹
|
||||
const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId);
|
||||
const containerMergedFolders = this.mergedFolders.filter(folder => folder.containerId === this.currentContainerId);
|
||||
return this.configView.render({
|
||||
container: currentContainer,
|
||||
configs: containerConfigs,
|
||||
gitRepos: containerGitRepos,
|
||||
currentGitRepo: currentRepo,
|
||||
gitFileTree: this.currentRepoFileTree,
|
||||
gitLoading: false
|
||||
gitLoading: false,
|
||||
mergedFolders: containerMergedFolders // 传递合并文件夹数据
|
||||
});
|
||||
default:
|
||||
return this.projectView.render({
|
||||
@@ -1326,6 +1347,195 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage(`打开配置文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
async mergeConfigs(configIds, displayName, folderName) {
|
||||
try {
|
||||
if (!this.currentContainerId) {
|
||||
vscode.window.showErrorMessage('未找到当前容器');
|
||||
return;
|
||||
}
|
||||
if (configIds.length < 2) {
|
||||
vscode.window.showErrorMessage('请至少选择两个配置文件进行合并');
|
||||
return;
|
||||
}
|
||||
const container = this.containers.find(c => c.id === this.currentContainerId);
|
||||
if (!container) {
|
||||
vscode.window.showErrorMessage('未找到容器');
|
||||
return;
|
||||
}
|
||||
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
||||
if (!aircraft) {
|
||||
vscode.window.showErrorMessage('未找到飞行器');
|
||||
return;
|
||||
}
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (!projectPath) {
|
||||
vscode.window.showErrorMessage('未设置项目存储路径');
|
||||
return;
|
||||
}
|
||||
// 获取选中的配置文件
|
||||
const selectedConfigs = this.configs.filter(config => configIds.includes(config.id));
|
||||
if (selectedConfigs.length !== configIds.length) {
|
||||
vscode.window.showErrorMessage('部分配置文件未找到');
|
||||
return;
|
||||
}
|
||||
// 创建合并文件夹
|
||||
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
||||
// 将选中的配置文件复制到合并文件夹中
|
||||
const copiedFiles = [];
|
||||
for (const config of selectedConfigs) {
|
||||
const sourcePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
||||
const targetPath = path.join(mergeFolderPath, config.fileName);
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
await fs.promises.copyFile(sourcePath, targetPath);
|
||||
copiedFiles.push(config.fileName);
|
||||
console.log(`✅ 已复制配置文件: ${config.fileName}`);
|
||||
}
|
||||
else {
|
||||
// 如果源文件不存在,创建新文件
|
||||
await fs.promises.writeFile(targetPath, config.content || '');
|
||||
copiedFiles.push(config.fileName);
|
||||
console.log(`✅ 已创建配置文件: ${config.fileName}`);
|
||||
}
|
||||
}
|
||||
// 创建合并文件夹记录
|
||||
const newFolder = {
|
||||
id: 'merged-' + Date.now(),
|
||||
displayName: displayName,
|
||||
folderName: folderName,
|
||||
path: mergeFolderPath,
|
||||
fileCount: copiedFiles.length,
|
||||
containerId: this.currentContainerId,
|
||||
originalConfigIds: configIds,
|
||||
createdAt: new Date().toLocaleString()
|
||||
};
|
||||
// 添加到合并文件夹列表
|
||||
this.mergedFolders.push(newFolder);
|
||||
// 删除原始配置文件
|
||||
for (const configId of configIds) {
|
||||
await this.deleteConfigInternal(configId);
|
||||
}
|
||||
// 保存数据
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`成功合并 ${selectedConfigs.length} 个配置文件到文件夹: ${folderName}`);
|
||||
// 更新UI(不自动打开文件夹)
|
||||
this.updateWebview();
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ 合并配置文件失败:', error);
|
||||
vscode.window.showErrorMessage(`合并配置文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 内部删除配置文件方法(不显示确认对话框)
|
||||
*/
|
||||
async deleteConfigInternal(configId) {
|
||||
try {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (!config)
|
||||
return;
|
||||
// 从内存中删除配置
|
||||
this.configs = this.configs.filter(c => c.id !== configId);
|
||||
// 删除磁盘上的配置文件
|
||||
const container = this.containers.find(c => c.id === config.containerId);
|
||||
if (container) {
|
||||
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
||||
if (aircraft) {
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (projectPath) {
|
||||
const filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
||||
// 检查文件是否存在,如果存在则删除
|
||||
if (fs.existsSync(filePath)) {
|
||||
await fs.promises.unlink(filePath);
|
||||
console.log(`✅ 已删除配置文件: ${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(`✅ 内部删除配置: ${config.name}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`删除配置文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除合并文件夹
|
||||
*/
|
||||
async deleteMergedFolder(folderId) {
|
||||
const folder = this.mergedFolders.find(f => f.id === folderId);
|
||||
if (!folder)
|
||||
return;
|
||||
const confirm = await vscode.window.showWarningMessage(`确定要删除合并文件夹 "${folder.displayName}" 吗?这将删除文件夹及其所有内容。`, { modal: true }, '确定删除', '取消');
|
||||
if (confirm === '确定删除') {
|
||||
try {
|
||||
// 删除文件夹及其所有内容
|
||||
await fs.promises.rm(folder.path, { recursive: true, force: true });
|
||||
// 从列表中移除
|
||||
this.mergedFolders = this.mergedFolders.filter(f => f.id !== folderId);
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`合并文件夹已删除: ${folder.displayName}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`删除合并文件夹失败: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 在 VSCode 中打开合并文件夹
|
||||
*/
|
||||
async openMergedFolderInVSCode(folderId) {
|
||||
const folder = this.mergedFolders.find(f => f.id === folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到指定的合并文件夹');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 检查文件夹是否存在
|
||||
if (!fs.existsSync(folder.path)) {
|
||||
vscode.window.showErrorMessage('合并文件夹不存在');
|
||||
return;
|
||||
}
|
||||
// 使用 VSCode 打开文件夹
|
||||
const folderUri = vscode.Uri.file(folder.path);
|
||||
vscode.commands.executeCommand('vscode.openFolder', folderUri, { forceNewWindow: false });
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`打开合并文件夹失败: ${error}`);
|
||||
}
|
||||
}
|
||||
async loadMergedFolder(folderId) {
|
||||
const folder = this.mergedFolders.find(f => f.id === folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到指定的合并文件夹');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 检查文件夹是否存在
|
||||
if (!fs.existsSync(folder.path)) {
|
||||
vscode.window.showErrorMessage('合并文件夹目录不存在');
|
||||
return;
|
||||
}
|
||||
// 使用 VSCode 的文件选择器让用户选择要打开的文件
|
||||
const fileUri = await vscode.window.showOpenDialog({
|
||||
defaultUri: vscode.Uri.file(folder.path),
|
||||
canSelectFiles: true,
|
||||
canSelectFolders: false,
|
||||
canSelectMany: false,
|
||||
openLabel: '选择要打开的文件',
|
||||
title: `在合并文件夹 ${folder.displayName} 中选择文件`
|
||||
});
|
||||
if (fileUri && fileUri.length > 0) {
|
||||
// 打开选中的文件
|
||||
const document = await vscode.workspace.openTextDocument(fileUri[0]);
|
||||
await vscode.window.showTextDocument(document);
|
||||
vscode.window.showInformationMessage(`已打开文件: ${path.basename(fileUri[0].fsPath)}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`打开合并文件夹文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ConfigPanel = ConfigPanel;
|
||||
//# sourceMappingURL=ConfigPanel.js.map
|
||||
Reference in New Issue
Block a user