暂时添加了合并功能,但是存在很多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
|
||||
File diff suppressed because one or more lines are too long
@@ -12,10 +12,12 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
const gitLoading = data?.gitLoading || false;
|
||||
const gitBranches = data?.gitBranches || [];
|
||||
const gitRepoUrl = data?.gitRepoUrl || '';
|
||||
const mergedFolders = data?.mergedFolders || [];
|
||||
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库
|
||||
const configsHtml = configs.map((config) => `
|
||||
<tr>
|
||||
<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>
|
||||
</td>
|
||||
<td>
|
||||
@@ -26,7 +28,24 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
</td>
|
||||
</tr>
|
||||
`).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 => {
|
||||
// 提取仓库名称(从URL中获取或使用name)
|
||||
const repoName = repo.name.split(' (')[0]; // 移除分支名部分
|
||||
@@ -152,6 +171,69 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
.branch-tree-title {
|
||||
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>
|
||||
</head>
|
||||
<body>
|
||||
@@ -163,6 +245,13 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
<!-- 配置文件管理部分 -->
|
||||
<div class="config-section">
|
||||
<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">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -173,12 +262,8 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
</thead>
|
||||
<tbody>
|
||||
${configsHtml}
|
||||
${mergedFoldersHtml}
|
||||
${gitReposHtml}
|
||||
<tr>
|
||||
<td colspan="3" style="text-align: center; padding: 20px;">
|
||||
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -210,6 +295,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
let selectedBranches = new Set();
|
||||
let currentRepoUrl = '';
|
||||
let branchTreeData = [];
|
||||
let selectedConfigs = new Set();
|
||||
|
||||
// 配置管理功能
|
||||
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() {
|
||||
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 仓库删除功能
|
||||
function deleteGitRepo(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() {
|
||||
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) {
|
||||
console.log('🔄 同步仓库:', repoId);
|
||||
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) {
|
||||
const node = findNodeById(branchTreeData, nodeId);
|
||||
@@ -608,6 +833,14 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
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>
|
||||
</body>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user