0
0

暂时添加了合并功能,但是存在很多BUG

This commit is contained in:
xubing
2025-11-27 20:10:09 +08:00
parent 9f44664b0b
commit 97c897962f
6 changed files with 1151 additions and 199 deletions

View File

@@ -62,6 +62,7 @@ class ConfigPanel {
this.containers = []; this.containers = [];
this.configs = []; this.configs = [];
this.gitRepos = []; // Git 仓库数据 this.gitRepos = []; // Git 仓库数据
this.mergedFolders = [];
// Git 文件树 // Git 文件树
this.currentRepoFileTree = []; this.currentRepoFileTree = [];
// 项目存储路径映射 // 项目存储路径映射
@@ -211,6 +212,18 @@ class ConfigPanel {
case 'openConfigFileInVSCode': case 'openConfigFileInVSCode':
await this.openConfigFileInVSCode(data.configId); await this.openConfigFileInVSCode(data.configId);
break; 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) { catch (error) {
@@ -669,18 +682,20 @@ class ConfigPanel {
const currentProjectContainers = this.containers.filter(c => currentAircraftIds.includes(c.aircraftId)); const currentProjectContainers = this.containers.filter(c => currentAircraftIds.includes(c.aircraftId));
const currentContainerIds = currentProjectContainers.map(c => c.id); const currentContainerIds = currentProjectContainers.map(c => c.id);
const currentProjectConfigs = this.configs.filter(cfg => currentContainerIds.includes(cfg.containerId)); const currentProjectConfigs = this.configs.filter(cfg => currentContainerIds.includes(cfg.containerId));
// 只保存与当前项目容器相关的 Git 仓库 // 只保存与当前项目容器相关的 Git 仓库和合并文件夹
const currentProjectGitRepos = this.gitRepos.filter(repo => currentContainerIds.includes(repo.containerId)); const currentProjectGitRepos = this.gitRepos.filter(repo => currentContainerIds.includes(repo.containerId));
const currentProjectMergedFolders = this.mergedFolders.filter(folder => currentContainerIds.includes(folder.containerId));
const data = { const data = {
projects: this.projects.filter(p => p.id === this.currentProjectId), projects: this.projects.filter(p => p.id === this.currentProjectId),
aircrafts: currentProjectAircrafts, aircrafts: currentProjectAircrafts,
containers: currentProjectContainers, containers: currentProjectContainers,
configs: currentProjectConfigs, configs: currentProjectConfigs,
gitRepos: currentProjectGitRepos // 保存 Git 仓库数据 gitRepos: currentProjectGitRepos,
mergedFolders: currentProjectMergedFolders // 保存合并文件夹数据
}; };
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2)); const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
await vscode.workspace.fs.writeFile(dataUri, uint8Array); await vscode.workspace.fs.writeFile(dataUri, uint8Array);
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库'); console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库和', currentProjectMergedFolders.length, '个合并文件夹');
} }
catch (error) { catch (error) {
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`); vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
@@ -709,7 +724,8 @@ class ConfigPanel {
this.aircrafts = []; this.aircrafts = [];
this.containers = []; this.containers = [];
this.configs = []; this.configs = [];
this.gitRepos = []; // 清空 Git 仓库数据 this.gitRepos = [];
this.mergedFolders = []; // 清空合并文件夹数据
// 验证数据格式并加载 // 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) { if (data.projects && Array.isArray(data.projects)) {
this.projects = data.projects; this.projects = data.projects;
@@ -724,7 +740,10 @@ class ConfigPanel {
this.configs = data.configs; this.configs = data.configs;
} }
if (data.gitRepos && Array.isArray(data.gitRepos)) { 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) { if (this.projects.length > 0) {
@@ -732,7 +751,7 @@ class ConfigPanel {
this.projectPaths.set(this.currentProjectId, projectPath); this.projectPaths.set(this.currentProjectId, projectPath);
this.currentView = 'aircrafts'; this.currentView = 'aircrafts';
} }
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库`); vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库${this.mergedFolders.length} 个合并文件夹`);
this.updateWebview(); this.updateWebview();
return true; return true;
} }
@@ -1236,15 +1255,17 @@ class ConfigPanel {
const currentContainer = this.containers.find(c => c.id === this.currentContainerId); const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId); const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId); const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId);
// 获取当前容器的 Git 仓库 // 获取当前容器的 Git 仓库和合并文件夹
const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId); const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId);
const containerMergedFolders = this.mergedFolders.filter(folder => folder.containerId === this.currentContainerId);
return this.configView.render({ return this.configView.render({
container: currentContainer, container: currentContainer,
configs: containerConfigs, configs: containerConfigs,
gitRepos: containerGitRepos, gitRepos: containerGitRepos,
currentGitRepo: currentRepo, currentGitRepo: currentRepo,
gitFileTree: this.currentRepoFileTree, gitFileTree: this.currentRepoFileTree,
gitLoading: false gitLoading: false,
mergedFolders: containerMergedFolders // 传递合并文件夹数据
}); });
default: default:
return this.projectView.render({ return this.projectView.render({
@@ -1326,6 +1347,195 @@ class ConfigPanel {
vscode.window.showErrorMessage(`打开配置文件失败: ${error}`); 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; exports.ConfigPanel = ConfigPanel;
//# sourceMappingURL=ConfigPanel.js.map //# sourceMappingURL=ConfigPanel.js.map

File diff suppressed because one or more lines are too long

View File

@@ -12,10 +12,12 @@ class ConfigView extends BaseView_1.BaseView {
const gitLoading = data?.gitLoading || false; const gitLoading = data?.gitLoading || false;
const gitBranches = data?.gitBranches || []; const gitBranches = data?.gitBranches || [];
const gitRepoUrl = data?.gitRepoUrl || ''; const gitRepoUrl = data?.gitRepoUrl || '';
const mergedFolders = data?.mergedFolders || [];
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库 // 生成配置列表的 HTML - 包含配置文件和 Git 仓库
const configsHtml = configs.map((config) => ` const configsHtml = configs.map((config) => `
<tr> <tr>
<td> <td>
<input type="checkbox" class="config-checkbox" data-id="${config.id}" data-type="config">
<span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span> <span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span>
</td> </td>
<td> <td>
@@ -26,7 +28,24 @@ class ConfigView extends BaseView_1.BaseView {
</td> </td>
</tr> </tr>
`).join(''); `).join('');
// 生成 Git 仓库列表的 HTML - 修改显示方式 // 生成合并文件夹的 HTML - 显示在配置列表中
const mergedFoldersHtml = mergedFolders.map((folder) => `
<tr>
<td>
<span class="editable">📁 ${folder.displayName}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
包含 ${folder.fileCount} 个文件
</div>
</td>
<td>
<span class="clickable" onclick="loadMergedFolder('${folder.id}')">${folder.folderName}</span>
</td>
<td>
<button class="btn-delete" onclick="deleteMergedFolder('${folder.id}')">删除</button>
</td>
</tr>
`).join('');
// 生成 Git 仓库列表的 HTML - 修改显示方式Git 仓库不可勾选
const gitReposHtml = gitRepos.map(repo => { const gitReposHtml = gitRepos.map(repo => {
// 提取仓库名称从URL中获取或使用name // 提取仓库名称从URL中获取或使用name
const repoName = repo.name.split(' (')[0]; // 移除分支名部分 const repoName = repo.name.split(' (')[0]; // 移除分支名部分
@@ -152,6 +171,69 @@ class ConfigView extends BaseView_1.BaseView {
.branch-tree-title { .branch-tree-title {
font-size: 1.2em; font-size: 1.2em;
} }
/* 复选框样式 */
.config-checkbox {
margin-right: 8px;
}
/* 操作按钮样式 */
.action-buttons {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.btn-merge {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
.btn-merge:hover {
background: var(--vscode-button-hoverBackground);
}
.btn-merge:disabled {
background: var(--vscode-button-secondaryBackground);
color: var(--vscode-button-secondaryForeground);
cursor: not-allowed;
}
/* 合并弹窗样式 */
.merge-dialog-content {
display: flex;
gap: 15px;
margin: 15px 0;
}
.merge-input-section {
flex: 1;
}
.merge-input-label {
font-weight: bold;
margin-bottom: 8px;
display: block;
}
.merge-input-field {
width: 100%;
padding: 8px;
background: var(--vscode-input-background);
color: var(--vscode-input-foreground);
border: 1px solid var(--vscode-input-border);
border-radius: 4px;
margin-bottom: 5px;
}
.merge-input-help {
font-size: 12px;
color: var(--vscode-descriptionForeground);
}
</style> </style>
</head> </head>
<body> <body>
@@ -163,6 +245,13 @@ class ConfigView extends BaseView_1.BaseView {
<!-- 配置文件管理部分 --> <!-- 配置文件管理部分 -->
<div class="config-section"> <div class="config-section">
<h3 class="section-title">📋 配置文件管理</h3> <h3 class="section-title">📋 配置文件管理</h3>
<!-- 操作按钮区域 -->
<div class="action-buttons">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
<button class="btn-merge" id="mergeButton" onclick="mergeSelectedConfigs()" disabled>合并选中配置</button>
</div>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
@@ -173,12 +262,8 @@ class ConfigView extends BaseView_1.BaseView {
</thead> </thead>
<tbody> <tbody>
${configsHtml} ${configsHtml}
${mergedFoldersHtml}
${gitReposHtml} ${gitReposHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -210,6 +295,7 @@ class ConfigView extends BaseView_1.BaseView {
let selectedBranches = new Set(); let selectedBranches = new Set();
let currentRepoUrl = ''; let currentRepoUrl = '';
let branchTreeData = []; let branchTreeData = [];
let selectedConfigs = new Set();
// 配置管理功能 // 配置管理功能
function editConfigName(configId, currentName) { function editConfigName(configId, currentName) {
@@ -238,6 +324,24 @@ class ConfigView extends BaseView_1.BaseView {
}); });
} }
// 新功能:加载合并文件夹(与 Git 仓库行为一致)
function loadMergedFolder(folderId) {
console.log('📂 加载合并文件夹:', folderId);
vscode.postMessage({
type: 'loadMergedFolder',
folderId: folderId
});
}
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库文件选择器:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function createNewConfig() { function createNewConfig() {
showPromptDialog( showPromptDialog(
'新建配置', '新建配置',
@@ -272,6 +376,27 @@ class ConfigView extends BaseView_1.BaseView {
); );
} }
// 删除合并文件夹功能
function deleteMergedFolder(folderId) {
console.log('🗑️ 尝试删除合并文件夹:', folderId);
showConfirmDialog(
'确认删除合并文件夹',
'确定删除这个合并文件夹吗?这将删除文件夹及其所有内容。',
function() {
console.log('✅ 用户确认删除合并文件夹:', folderId);
vscode.postMessage({
type: 'deleteMergedFolder',
folderId: folderId
});
},
function() {
// 用户取消删除
console.log('❌ 用户取消删除合并文件夹');
}
);
}
// Git 仓库删除功能 // Git 仓库删除功能
function deleteGitRepo(repoId) { function deleteGitRepo(repoId) {
console.log('🗑️ 尝试删除 Git 仓库:', repoId); console.log('🗑️ 尝试删除 Git 仓库:', repoId);
@@ -293,15 +418,6 @@ class ConfigView extends BaseView_1.BaseView {
); );
} }
// 新功能:在 VSCode 中打开 Git 仓库
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function goBackToContainers() { function goBackToContainers() {
vscode.postMessage({ type: 'goBackToContainers' }); vscode.postMessage({ type: 'goBackToContainers' });
} }
@@ -376,14 +492,6 @@ class ConfigView extends BaseView_1.BaseView {
}); });
} }
function loadGitRepo(repoId) {
console.log('📂 加载仓库:', repoId);
vscode.postMessage({
type: 'loadGitRepo',
repoId: repoId
});
}
function syncGitRepo(repoId) { function syncGitRepo(repoId) {
console.log('🔄 同步仓库:', repoId); console.log('🔄 同步仓库:', repoId);
vscode.postMessage({ vscode.postMessage({
@@ -392,6 +500,123 @@ class ConfigView extends BaseView_1.BaseView {
}); });
} }
// 配置文件合并功能
function toggleConfigSelection(configId) {
const checkbox = document.querySelector('.config-checkbox[data-id="' + configId + '"]');
if (checkbox.checked) {
selectedConfigs.add(configId);
} else {
selectedConfigs.delete(configId);
}
// 更新合并按钮状态
updateMergeButtonState();
console.log('选中的配置文件:', Array.from(selectedConfigs));
}
function updateMergeButtonState() {
const mergeButton = document.getElementById('mergeButton');
if (mergeButton) {
mergeButton.disabled = selectedConfigs.size < 2;
}
}
function mergeSelectedConfigs() {
if (selectedConfigs.size < 2) {
alert('请至少选择两个配置文件进行合并');
return;
}
console.log('🔄 开始合并选中的配置文件:', Array.from(selectedConfigs));
// 弹出新的合并对话框
showMergeDialog();
}
// 新的合并对话框函数
function showMergeDialog() {
const overlay = document.createElement('div');
overlay.className = 'modal-overlay';
overlay.id = 'mergeModal';
overlay.innerHTML = \`
<div class="modal-dialog" style="width: 500px;">
<div class="modal-title">合并配置文件</div>
<div class="merge-dialog-content">
<div class="merge-input-section">
<label class="merge-input-label">配置显示名称</label>
<input type="text" id="displayNameInput" class="merge-input-field"
placeholder="在配置栏显示的名称" value="合并配置">
<div class="merge-input-help">在左侧配置栏显示的名称</div>
</div>
<div class="merge-input-section">
<label class="merge-input-label">文件夹名称</label>
<input type="text" id="folderNameInput" class="merge-input-field"
placeholder="文件夹的实际名称" value="merged-config">
<div class="merge-input-help">磁盘上的实际文件夹名称</div>
</div>
</div>
<div class="modal-buttons">
<button class="modal-btn modal-btn-secondary" onclick="closeMergeDialog()">取消</button>
<button class="modal-btn modal-btn-primary" onclick="confirmMerge()">确定合并</button>
</div>
</div>
\`;
document.body.appendChild(overlay);
// 自动聚焦到第一个输入框
setTimeout(() => {
const displayNameInput = document.getElementById('displayNameInput');
if (displayNameInput) {
displayNameInput.focus();
displayNameInput.select();
}
}, 100);
}
function confirmMerge() {
const displayNameInput = document.getElementById('displayNameInput');
const folderNameInput = document.getElementById('folderNameInput');
const displayName = displayNameInput.value.trim();
const folderName = folderNameInput.value.trim();
if (!displayName) {
alert('请输入配置显示名称');
return;
}
if (!folderName) {
alert('请输入文件夹名称');
return;
}
if (displayName && folderName) {
vscode.postMessage({
type: 'mergeConfigs',
configIds: Array.from(selectedConfigs),
displayName: displayName,
folderName: folderName
});
// 重置选择
selectedConfigs.clear();
const checkboxes = document.querySelectorAll('.config-checkbox');
checkboxes.forEach(checkbox => checkbox.checked = false);
updateMergeButtonState();
closeMergeDialog();
}
}
function closeMergeDialog() {
const modal = document.getElementById('mergeModal');
if (modal) {
modal.remove();
}
}
// 树状分支功能 // 树状分支功能
function toggleBranchNode(nodeId) { function toggleBranchNode(nodeId) {
const node = findNodeById(branchTreeData, nodeId); const node = findNodeById(branchTreeData, nodeId);
@@ -608,6 +833,14 @@ class ConfigView extends BaseView_1.BaseView {
// 初始化 // 初始化
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成'); console.log('📄 ConfigView 页面加载完成');
// 为所有配置复选框添加事件监听
document.addEventListener('change', function(event) {
if (event.target.classList.contains('config-checkbox')) {
const configId = event.target.getAttribute('data-id');
toggleConfigSelection(configId);
}
});
}); });
</script> </script>
</body> </body>

File diff suppressed because one or more lines are too long

View File

@@ -52,14 +52,6 @@ interface GitFileTree {
children?: GitFileTree[]; children?: GitFileTree[];
} }
interface ProjectData {
projects: Project[];
aircrafts: Aircraft[];
containers: Container[];
configs: Config[];
gitRepos: GitRepo[]; // Git 仓库数据整合到项目数据中
}
// Git 分支接口 // Git 分支接口
interface GitBranch { interface GitBranch {
name: string; name: string;
@@ -67,6 +59,27 @@ interface GitBranch {
selected?: boolean; selected?: boolean;
} }
interface MergedFolder {
id: string;
displayName: string; // 配置栏显示的名称
folderName: string; // 实际文件夹名称
path: string;
fileCount: number;
containerId: string;
originalConfigIds: string[];
createdAt: string;
}
// 修改 ProjectData 接口,添加 mergedFolders
interface ProjectData {
projects: Project[];
aircrafts: Aircraft[];
containers: Container[];
configs: Config[];
gitRepos: GitRepo[];
mergedFolders: MergedFolder[]; // 新增合并文件夹数据
}
export class ConfigPanel { export class ConfigPanel {
public static currentPanel: ConfigPanel | undefined; public static currentPanel: ConfigPanel | undefined;
public readonly panel: vscode.WebviewPanel; public readonly panel: vscode.WebviewPanel;
@@ -84,6 +97,7 @@ export class ConfigPanel {
private containers: Container[] = []; private containers: Container[] = [];
private configs: Config[] = []; private configs: Config[] = [];
private gitRepos: GitRepo[] = []; // Git 仓库数据 private gitRepos: GitRepo[] = []; // Git 仓库数据
private mergedFolders: MergedFolder[] = [];
// Git 文件树 // Git 文件树
private currentRepoFileTree: GitFileTree[] = []; private currentRepoFileTree: GitFileTree[] = [];
@@ -300,6 +314,22 @@ export class ConfigPanel {
case 'openConfigFileInVSCode': case 'openConfigFileInVSCode':
await this.openConfigFileInVSCode(data.configId); await this.openConfigFileInVSCode(data.configId);
break; 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) { } catch (error) {
console.error('处理 Webview 消息时出错:', error); console.error('处理 Webview 消息时出错:', error);
@@ -813,108 +843,116 @@ export class ConfigPanel {
* 保存当前项目数据到项目路径 * 保存当前项目数据到项目路径
*/ */
private async saveCurrentProjectData(): Promise<void> { private async saveCurrentProjectData(): Promise<void> {
try { try {
if (!this.currentProjectId) { if (!this.currentProjectId) {
console.warn('未找到当前项目,数据将不会保存'); console.warn('未找到当前项目,数据将不会保存');
return; return;
}
const projectPath = this.projectPaths.get(this.currentProjectId);
if (!projectPath) {
console.warn('未找到项目存储路径,数据将不会保存');
return;
}
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
// 只保存与当前项目相关的数据
const currentProjectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
const currentAircraftIds = currentProjectAircrafts.map(a => a.id);
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 仓库
const currentProjectGitRepos = this.gitRepos.filter(repo =>
currentContainerIds.includes(repo.containerId)
);
const data: ProjectData = {
projects: this.projects.filter(p => p.id === this.currentProjectId),
aircrafts: currentProjectAircrafts,
containers: currentProjectContainers,
configs: currentProjectConfigs,
gitRepos: currentProjectGitRepos // 保存 Git 仓库数据
};
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库');
} catch (error) {
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
} }
const projectPath = this.projectPaths.get(this.currentProjectId);
if (!projectPath) {
console.warn('未找到项目存储路径,数据将不会保存');
return;
}
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
// 只保存与当前项目相关的数据
const currentProjectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
const currentAircraftIds = currentProjectAircrafts.map(a => a.id);
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 仓库和合并文件夹
const currentProjectGitRepos = this.gitRepos.filter(repo =>
currentContainerIds.includes(repo.containerId)
);
const currentProjectMergedFolders = this.mergedFolders.filter(folder =>
currentContainerIds.includes(folder.containerId)
);
const data: ProjectData = {
projects: this.projects.filter(p => p.id === this.currentProjectId),
aircrafts: currentProjectAircrafts,
containers: currentProjectContainers,
configs: currentProjectConfigs,
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 仓库和', currentProjectMergedFolders.length, '个合并文件夹');
} catch (error) {
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
} }
}
/** /**
* 从项目路径加载数据 * 从项目路径加载数据
*/ */
private async loadProjectData(projectPath: string): Promise<boolean> { private async loadProjectData(projectPath: string): Promise<boolean> {
try {
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
// 检查数据文件是否存在
try { try {
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json'); await vscode.workspace.fs.stat(dataUri);
} catch {
// 检查数据文件是否存在 vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
try {
await vscode.workspace.fs.stat(dataUri);
} catch {
vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
return false;
}
// 读取数据文件
const fileData = await vscode.workspace.fs.readFile(dataUri);
const dataStr = new TextDecoder().decode(fileData);
const data: ProjectData = JSON.parse(dataStr);
// 清空现有数据
this.projects = [];
this.aircrafts = [];
this.containers = [];
this.configs = [];
this.gitRepos = []; // 清空 Git 仓库数据
// 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) {
this.projects = data.projects;
}
if (data.aircrafts && Array.isArray(data.aircrafts)) {
this.aircrafts = data.aircrafts;
}
if (data.containers && Array.isArray(data.containers)) {
this.containers = data.containers;
}
if (data.configs && Array.isArray(data.configs)) {
this.configs = data.configs;
}
if (data.gitRepos && Array.isArray(data.gitRepos)) {
this.gitRepos = data.gitRepos; // 加载 Git 仓库数据
}
// 设置当前项目为第一个项目(如果有的话)
if (this.projects.length > 0) {
this.currentProjectId = this.projects[0].id;
this.projectPaths.set(this.currentProjectId, projectPath);
this.currentView = 'aircrafts';
}
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库`);
this.updateWebview();
return true;
} catch (error) {
vscode.window.showErrorMessage(`加载项目数据失败: ${error}`);
return false; return false;
} }
// 读取数据文件
const fileData = await vscode.workspace.fs.readFile(dataUri);
const dataStr = new TextDecoder().decode(fileData);
const data: ProjectData = JSON.parse(dataStr);
// 清空现有数据
this.projects = [];
this.aircrafts = [];
this.containers = [];
this.configs = [];
this.gitRepos = [];
this.mergedFolders = []; // 清空合并文件夹数据
// 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) {
this.projects = data.projects;
}
if (data.aircrafts && Array.isArray(data.aircrafts)) {
this.aircrafts = data.aircrafts;
}
if (data.containers && Array.isArray(data.containers)) {
this.containers = data.containers;
}
if (data.configs && Array.isArray(data.configs)) {
this.configs = data.configs;
}
if (data.gitRepos && Array.isArray(data.gitRepos)) {
this.gitRepos = data.gitRepos;
}
if (data.mergedFolders && Array.isArray(data.mergedFolders)) {
this.mergedFolders = data.mergedFolders; // 加载合并文件夹数据
}
// 设置当前项目为第一个项目(如果有的话)
if (this.projects.length > 0) {
this.currentProjectId = this.projects[0].id;
this.projectPaths.set(this.currentProjectId, projectPath);
this.currentView = 'aircrafts';
}
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库和 ${this.mergedFolders.length} 个合并文件夹`);
this.updateWebview();
return true;
} catch (error) {
vscode.window.showErrorMessage(`加载项目数据失败: ${error}`);
return false;
} }
}
/** /**
* 检查项目路径是否已存在数据 * 检查项目路径是否已存在数据
@@ -1480,50 +1518,52 @@ private buildBranchTree(branches: GitBranch[]): any[] {
} }
private getWebviewContent(): string { private getWebviewContent(): string {
switch (this.currentView) { switch (this.currentView) {
case 'projects': case 'projects':
return this.projectView.render({ return this.projectView.render({
projects: this.projects, projects: this.projects,
projectPaths: this.projectPaths projectPaths: this.projectPaths
}); });
case 'aircrafts': case 'aircrafts':
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId); const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
return this.aircraftView.render({ return this.aircraftView.render({
aircrafts: projectAircrafts aircrafts: projectAircrafts
}); });
case 'containers': case 'containers':
const currentProject = this.projects.find(p => p.id === this.currentProjectId); const currentProject = this.projects.find(p => p.id === this.currentProjectId);
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId); const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId); const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
return this.containerView.render({ return this.containerView.render({
project: currentProject, project: currentProject,
aircraft: currentAircraft, aircraft: currentAircraft,
containers: projectContainers containers: projectContainers
}); });
case 'configs': case 'configs':
const currentContainer = this.containers.find(c => c.id === this.currentContainerId); const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId); const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId); const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId);
// 获取当前容器的 Git 仓库 // 获取当前容器的 Git 仓库和合并文件夹
const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId); 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, return this.configView.render({
configs: containerConfigs, container: currentContainer,
gitRepos: containerGitRepos, // 只显示当前容器的 Git 仓库 configs: containerConfigs,
currentGitRepo: currentRepo, gitRepos: containerGitRepos,
gitFileTree: this.currentRepoFileTree, currentGitRepo: currentRepo,
gitLoading: false gitFileTree: this.currentRepoFileTree,
}); gitLoading: false,
default: mergedFolders: containerMergedFolders // 传递合并文件夹数据
return this.projectView.render({ });
projects: this.projects, default:
projectPaths: this.projectPaths return this.projectView.render({
}); projects: this.projects,
} projectPaths: this.projectPaths
});
} }
}
private async openGitRepoInVSCode(repoId: string): Promise<void> { private async openGitRepoInVSCode(repoId: string): Promise<void> {
const repo = this.gitRepos.find(r => r.id === repoId); const repo = this.gitRepos.find(r => r.id === repoId);
@@ -1608,4 +1648,226 @@ private buildBranchTree(branches: GitBranch[]): any[] {
vscode.window.showErrorMessage(`打开配置文件失败: ${error}`); vscode.window.showErrorMessage(`打开配置文件失败: ${error}`);
} }
} }
private async mergeConfigs(configIds: string[], displayName: string, folderName: string): Promise<void> {
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: string[] = [];
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: MergedFolder = {
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}`);
}
}
/**
* 内部删除配置文件方法(不显示确认对话框)
*/
private async deleteConfigInternal(configId: string): Promise<void> {
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}`);
}
}
/**
* 删除合并文件夹
*/
private async deleteMergedFolder(folderId: string): Promise<void> {
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 中打开合并文件夹
*/
private async openMergedFolderInVSCode(folderId: string): Promise<void> {
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}`);
}
}
private async loadMergedFolder(folderId: string): Promise<void> {
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}`);
}
}
} }

View File

@@ -37,6 +37,18 @@ interface GitRepo {
containerId: string; containerId: string;
} }
// 合并文件夹接口
interface MergedFolder {
id: string;
displayName: string; // 配置栏显示的名称
folderName: string; // 实际文件夹名称
path: string;
fileCount: number;
containerId: string;
originalConfigIds: string[];
createdAt: string;
}
// 树状分支节点接口 // 树状分支节点接口
interface BranchTreeNode { interface BranchTreeNode {
name: string; name: string;
@@ -56,6 +68,7 @@ export class ConfigView extends BaseView {
gitLoading?: boolean; gitLoading?: boolean;
gitBranches?: GitBranch[]; gitBranches?: GitBranch[];
gitRepoUrl?: string; gitRepoUrl?: string;
mergedFolders?: MergedFolder[];
}): string { }): string {
const container = data?.container; const container = data?.container;
const configs = data?.configs || []; const configs = data?.configs || [];
@@ -65,11 +78,13 @@ export class ConfigView extends BaseView {
const gitLoading = data?.gitLoading || false; const gitLoading = data?.gitLoading || false;
const gitBranches = data?.gitBranches || []; const gitBranches = data?.gitBranches || [];
const gitRepoUrl = data?.gitRepoUrl || ''; const gitRepoUrl = data?.gitRepoUrl || '';
const mergedFolders = data?.mergedFolders || [];
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库 // 生成配置列表的 HTML - 包含配置文件和 Git 仓库
const configsHtml = configs.map((config: ConfigViewData) => ` const configsHtml = configs.map((config: ConfigViewData) => `
<tr> <tr>
<td> <td>
<input type="checkbox" class="config-checkbox" data-id="${config.id}" data-type="config">
<span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span> <span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span>
</td> </td>
<td> <td>
@@ -81,7 +96,25 @@ export class ConfigView extends BaseView {
</tr> </tr>
`).join(''); `).join('');
// 生成 Git 仓库列表的 HTML - 修改显示方式 // 生成合并文件夹的 HTML - 显示在配置列表中
const mergedFoldersHtml = mergedFolders.map((folder: MergedFolder) => `
<tr>
<td>
<span class="editable">📁 ${folder.displayName}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
包含 ${folder.fileCount} 个文件
</div>
</td>
<td>
<span class="clickable" onclick="loadMergedFolder('${folder.id}')">${folder.folderName}</span>
</td>
<td>
<button class="btn-delete" onclick="deleteMergedFolder('${folder.id}')">删除</button>
</td>
</tr>
`).join('');
// 生成 Git 仓库列表的 HTML - 修改显示方式Git 仓库不可勾选
const gitReposHtml = gitRepos.map(repo => { const gitReposHtml = gitRepos.map(repo => {
// 提取仓库名称从URL中获取或使用name // 提取仓库名称从URL中获取或使用name
const repoName = repo.name.split(' (')[0]; // 移除分支名部分 const repoName = repo.name.split(' (')[0]; // 移除分支名部分
@@ -210,6 +243,69 @@ export class ConfigView extends BaseView {
.branch-tree-title { .branch-tree-title {
font-size: 1.2em; font-size: 1.2em;
} }
/* 复选框样式 */
.config-checkbox {
margin-right: 8px;
}
/* 操作按钮样式 */
.action-buttons {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.btn-merge {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
.btn-merge:hover {
background: var(--vscode-button-hoverBackground);
}
.btn-merge:disabled {
background: var(--vscode-button-secondaryBackground);
color: var(--vscode-button-secondaryForeground);
cursor: not-allowed;
}
/* 合并弹窗样式 */
.merge-dialog-content {
display: flex;
gap: 15px;
margin: 15px 0;
}
.merge-input-section {
flex: 1;
}
.merge-input-label {
font-weight: bold;
margin-bottom: 8px;
display: block;
}
.merge-input-field {
width: 100%;
padding: 8px;
background: var(--vscode-input-background);
color: var(--vscode-input-foreground);
border: 1px solid var(--vscode-input-border);
border-radius: 4px;
margin-bottom: 5px;
}
.merge-input-help {
font-size: 12px;
color: var(--vscode-descriptionForeground);
}
</style> </style>
</head> </head>
<body> <body>
@@ -221,6 +317,13 @@ export class ConfigView extends BaseView {
<!-- 配置文件管理部分 --> <!-- 配置文件管理部分 -->
<div class="config-section"> <div class="config-section">
<h3 class="section-title">📋 配置文件管理</h3> <h3 class="section-title">📋 配置文件管理</h3>
<!-- 操作按钮区域 -->
<div class="action-buttons">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
<button class="btn-merge" id="mergeButton" onclick="mergeSelectedConfigs()" disabled>合并选中配置</button>
</div>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
@@ -231,12 +334,8 @@ export class ConfigView extends BaseView {
</thead> </thead>
<tbody> <tbody>
${configsHtml} ${configsHtml}
${mergedFoldersHtml}
${gitReposHtml} ${gitReposHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -268,6 +367,7 @@ export class ConfigView extends BaseView {
let selectedBranches = new Set(); let selectedBranches = new Set();
let currentRepoUrl = ''; let currentRepoUrl = '';
let branchTreeData = []; let branchTreeData = [];
let selectedConfigs = new Set();
// 配置管理功能 // 配置管理功能
function editConfigName(configId, currentName) { function editConfigName(configId, currentName) {
@@ -296,6 +396,24 @@ export class ConfigView extends BaseView {
}); });
} }
// 新功能:加载合并文件夹(与 Git 仓库行为一致)
function loadMergedFolder(folderId) {
console.log('📂 加载合并文件夹:', folderId);
vscode.postMessage({
type: 'loadMergedFolder',
folderId: folderId
});
}
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库文件选择器:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function createNewConfig() { function createNewConfig() {
showPromptDialog( showPromptDialog(
'新建配置', '新建配置',
@@ -330,6 +448,27 @@ export class ConfigView extends BaseView {
); );
} }
// 删除合并文件夹功能
function deleteMergedFolder(folderId) {
console.log('🗑️ 尝试删除合并文件夹:', folderId);
showConfirmDialog(
'确认删除合并文件夹',
'确定删除这个合并文件夹吗?这将删除文件夹及其所有内容。',
function() {
console.log('✅ 用户确认删除合并文件夹:', folderId);
vscode.postMessage({
type: 'deleteMergedFolder',
folderId: folderId
});
},
function() {
// 用户取消删除
console.log('❌ 用户取消删除合并文件夹');
}
);
}
// Git 仓库删除功能 // Git 仓库删除功能
function deleteGitRepo(repoId) { function deleteGitRepo(repoId) {
console.log('🗑️ 尝试删除 Git 仓库:', repoId); console.log('🗑️ 尝试删除 Git 仓库:', repoId);
@@ -351,15 +490,6 @@ export class ConfigView extends BaseView {
); );
} }
// 新功能:在 VSCode 中打开 Git 仓库
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function goBackToContainers() { function goBackToContainers() {
vscode.postMessage({ type: 'goBackToContainers' }); vscode.postMessage({ type: 'goBackToContainers' });
} }
@@ -434,14 +564,6 @@ export class ConfigView extends BaseView {
}); });
} }
function loadGitRepo(repoId) {
console.log('📂 加载仓库:', repoId);
vscode.postMessage({
type: 'loadGitRepo',
repoId: repoId
});
}
function syncGitRepo(repoId) { function syncGitRepo(repoId) {
console.log('🔄 同步仓库:', repoId); console.log('🔄 同步仓库:', repoId);
vscode.postMessage({ vscode.postMessage({
@@ -450,6 +572,123 @@ export class ConfigView extends BaseView {
}); });
} }
// 配置文件合并功能
function toggleConfigSelection(configId) {
const checkbox = document.querySelector('.config-checkbox[data-id="' + configId + '"]');
if (checkbox.checked) {
selectedConfigs.add(configId);
} else {
selectedConfigs.delete(configId);
}
// 更新合并按钮状态
updateMergeButtonState();
console.log('选中的配置文件:', Array.from(selectedConfigs));
}
function updateMergeButtonState() {
const mergeButton = document.getElementById('mergeButton');
if (mergeButton) {
mergeButton.disabled = selectedConfigs.size < 2;
}
}
function mergeSelectedConfigs() {
if (selectedConfigs.size < 2) {
alert('请至少选择两个配置文件进行合并');
return;
}
console.log('🔄 开始合并选中的配置文件:', Array.from(selectedConfigs));
// 弹出新的合并对话框
showMergeDialog();
}
// 新的合并对话框函数
function showMergeDialog() {
const overlay = document.createElement('div');
overlay.className = 'modal-overlay';
overlay.id = 'mergeModal';
overlay.innerHTML = \`
<div class="modal-dialog" style="width: 500px;">
<div class="modal-title">合并配置文件</div>
<div class="merge-dialog-content">
<div class="merge-input-section">
<label class="merge-input-label">配置显示名称</label>
<input type="text" id="displayNameInput" class="merge-input-field"
placeholder="在配置栏显示的名称" value="合并配置">
<div class="merge-input-help">在左侧配置栏显示的名称</div>
</div>
<div class="merge-input-section">
<label class="merge-input-label">文件夹名称</label>
<input type="text" id="folderNameInput" class="merge-input-field"
placeholder="文件夹的实际名称" value="merged-config">
<div class="merge-input-help">磁盘上的实际文件夹名称</div>
</div>
</div>
<div class="modal-buttons">
<button class="modal-btn modal-btn-secondary" onclick="closeMergeDialog()">取消</button>
<button class="modal-btn modal-btn-primary" onclick="confirmMerge()">确定合并</button>
</div>
</div>
\`;
document.body.appendChild(overlay);
// 自动聚焦到第一个输入框
setTimeout(() => {
const displayNameInput = document.getElementById('displayNameInput');
if (displayNameInput) {
displayNameInput.focus();
displayNameInput.select();
}
}, 100);
}
function confirmMerge() {
const displayNameInput = document.getElementById('displayNameInput');
const folderNameInput = document.getElementById('folderNameInput');
const displayName = displayNameInput.value.trim();
const folderName = folderNameInput.value.trim();
if (!displayName) {
alert('请输入配置显示名称');
return;
}
if (!folderName) {
alert('请输入文件夹名称');
return;
}
if (displayName && folderName) {
vscode.postMessage({
type: 'mergeConfigs',
configIds: Array.from(selectedConfigs),
displayName: displayName,
folderName: folderName
});
// 重置选择
selectedConfigs.clear();
const checkboxes = document.querySelectorAll('.config-checkbox');
checkboxes.forEach(checkbox => checkbox.checked = false);
updateMergeButtonState();
closeMergeDialog();
}
}
function closeMergeDialog() {
const modal = document.getElementById('mergeModal');
if (modal) {
modal.remove();
}
}
// 树状分支功能 // 树状分支功能
function toggleBranchNode(nodeId) { function toggleBranchNode(nodeId) {
const node = findNodeById(branchTreeData, nodeId); const node = findNodeById(branchTreeData, nodeId);
@@ -666,6 +905,14 @@ export class ConfigView extends BaseView {
// 初始化 // 初始化
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成'); console.log('📄 ConfigView 页面加载完成');
// 为所有配置复选框添加事件监听
document.addEventListener('change', function(event) {
if (event.target.classList.contains('config-checkbox')) {
const configId = event.target.getAttribute('data-id');
toggleConfigSelection(configId);
}
});
}); });
</script> </script>
</body> </body>
@@ -792,4 +1039,4 @@ export class ConfigView extends BaseView {
}); });
return count; return count;
} }
} }