修改了configview页面的命名逻辑
This commit is contained in:
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigPanel = void 0;
|
||||
// src/panels/ConfigPanel.ts
|
||||
const vscode = __importStar(require("vscode"));
|
||||
const path = __importStar(require("path"));
|
||||
const ProjectView_1 = require("./views/ProjectView");
|
||||
@@ -287,7 +288,8 @@ class ConfigPanel {
|
||||
'createContainer': (data) => this.createContainer(data.name),
|
||||
'deleteContainer': (data) => this.deleteContainer(data.containerId),
|
||||
// 配置管理
|
||||
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name),
|
||||
// [修改] 接收新的文件名
|
||||
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name, data.fileName),
|
||||
'createConfig': (data) => this.createConfig(data.name),
|
||||
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||
@@ -309,7 +311,8 @@ class ConfigPanel {
|
||||
'deleteModuleFolder': (data) => this.deleteModuleFolder(data.folderId),
|
||||
'importGitFile': (data) => this.importGitFile(data.filePath),
|
||||
'openTheModuleFolder': (data) => this.openTheModuleFolder(data.moduleType, data.id),
|
||||
'renameModuleFolder': (data) => this.renameModuleFolder(data.folderId, data.newName),
|
||||
// [修改] 接收新的显示名称和磁盘文件夹名称
|
||||
'renameModuleFolder': (data) => this.renameModuleFolder(data.folderId, data.newName, data.newFolderName),
|
||||
// 模块上传功能 (原逻辑)
|
||||
'uploadGitModuleFolder': (data) => this.uploadGitModuleFolder(data.folderId, data.username, data.password),
|
||||
'openRepoSelectForUpload': (data) => this.openUploadRepoSelect(data.folderId, 'local'),
|
||||
@@ -597,11 +600,25 @@ class ConfigPanel {
|
||||
// =============================================
|
||||
// 配置管理方法
|
||||
// =============================================
|
||||
async updateConfigName(configId, newName) {
|
||||
if (this.projectService.updateConfigName(configId, newName)) {
|
||||
vscode.window.showInformationMessage(`配置名称更新: ${newName}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
/**
|
||||
* [修改] 同时更新配置显示名称和文件名,并处理磁盘文件重命名
|
||||
*/
|
||||
async updateConfigName(configId, newName, newFileName) {
|
||||
const config = this.projectService.getConfig(configId);
|
||||
if (!config)
|
||||
return;
|
||||
try {
|
||||
// 1. 重命名磁盘文件
|
||||
await this.projectService.renameConfigFileOnDisk(configId, newFileName);
|
||||
// 2. 更新内存数据
|
||||
if (this.projectService.updateConfigName(configId, newName, newFileName)) {
|
||||
vscode.window.showInformationMessage(`✅ 配置/文件名已更新: ${newName} / ${newFileName}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`❌ 重命名磁盘文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
async createConfig(name) {
|
||||
@@ -1131,6 +1148,44 @@ class ConfigPanel {
|
||||
// =============================================
|
||||
// 模块文件夹管理方法
|
||||
// =============================================
|
||||
/**
|
||||
* [修改] 同时处理显示名称和磁盘文件夹名称的重命名
|
||||
*/
|
||||
async renameModuleFolder(folderId, newName, newFolderName) {
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
return;
|
||||
}
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath) {
|
||||
vscode.window.showErrorMessage('无法获取模块文件夹路径');
|
||||
return;
|
||||
}
|
||||
const oldFolderName = folder.localPath.split('/').pop();
|
||||
if (!oldFolderName)
|
||||
return;
|
||||
const newFullPath = path.join(path.dirname(fullPath), newFolderName);
|
||||
const isDiskRenameNeeded = oldFolderName !== newFolderName;
|
||||
try {
|
||||
if (isDiskRenameNeeded) {
|
||||
// 1. 重命名磁盘文件夹
|
||||
await this.projectService.renameDirectoryOnDisk(fullPath, newFullPath);
|
||||
}
|
||||
// 2. 更新内存数据:显示名和 localPath
|
||||
const newLocalPath = folder.localPath.replace(new RegExp(`/${oldFolderName}$`), '/' + newFolderName);
|
||||
this.projectService.updateModuleFolder(folderId, {
|
||||
name: newName,
|
||||
localPath: newLocalPath
|
||||
});
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`✅ 已重命名文件夹: ${oldFolderName} → ${newFolderName} (显示名: ${newName})`);
|
||||
this.updateWebview();
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
}
|
||||
}
|
||||
async loadModuleFolder(folderId) {
|
||||
this.currentModuleFolderId = folderId;
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
@@ -1509,31 +1564,29 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage(`打开模块文件夹文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
async renameModuleFolder(folderId, newName) {
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
return;
|
||||
}
|
||||
const oldName = folder.localPath.split('/').pop();
|
||||
if (!oldName)
|
||||
return;
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath)
|
||||
return;
|
||||
const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
try {
|
||||
const fs = require('fs');
|
||||
await fs.promises.rename(fullPath, newFullPath);
|
||||
this.projectService.renameModuleFolder(folderId, newName);
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
}
|
||||
}
|
||||
// [删除] 此方法已被上面的 renameModuleFolder 替换
|
||||
// private async renameModuleFolder(folderId: string, newName: string): Promise<void> {
|
||||
// const folder = this.projectService.getModuleFolder(folderId);
|
||||
// if (!folder) {
|
||||
// vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
// return;
|
||||
// }
|
||||
// const oldName = folder.localPath.split('/').pop();
|
||||
// if (!oldName) return;
|
||||
// const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
// if (!fullPath) return;
|
||||
// const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
// try {
|
||||
// const fs = require('fs');
|
||||
// await fs.promises.rename(fullPath, newFullPath);
|
||||
// this.projectService.renameModuleFolder(folderId, newName);
|
||||
// await this.saveCurrentProjectData();
|
||||
// vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
||||
// this.updateWebview();
|
||||
// } catch (error) {
|
||||
// vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
// }
|
||||
// }
|
||||
// =============================================
|
||||
// 项目路径选择方法
|
||||
// =============================================
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -48,6 +48,22 @@ class ProjectService {
|
||||
const randomPart = `${Date.now().toString(36)}${Math.random().toString(36).substring(2, 8)}`;
|
||||
return `${prefix}${randomPart}`;
|
||||
}
|
||||
/**
|
||||
* [新增] 文件名/文件夹名净化:只允许中文、字母、数字、-、_
|
||||
*/
|
||||
sanitizeFileName(name) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
let fileName = name.trim().toLowerCase();
|
||||
// 1. 替换所有空格为下划线
|
||||
fileName = fileName.replace(/\s+/g, '_');
|
||||
// 2. 移除所有不被允许的特殊字符(只保留中文、字母、数字、-、_)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-z0-9_-]/g, '');
|
||||
// 3. 确保不为空
|
||||
if (fileName.length === 0) {
|
||||
return 'config_file';
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
// =============== 项目相关方法 ===============
|
||||
getProjects() {
|
||||
return this.projects;
|
||||
@@ -294,20 +310,26 @@ class ProjectService {
|
||||
}
|
||||
async createConfig(name, containerId) {
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
// 使用新增的 sanitizeFileName 方法来处理文件名
|
||||
const newFileName = this.sanitizeFileName(name);
|
||||
const newConfig = {
|
||||
id: newId,
|
||||
name: name,
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
||||
fileName: newFileName,
|
||||
containerId: containerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
await this.ensureContainerDirectoryExists(containerId);
|
||||
return newId;
|
||||
}
|
||||
updateConfigName(configId, newName) {
|
||||
/**
|
||||
* [修改] 同时更新配置显示名称和文件名称
|
||||
*/
|
||||
updateConfigName(configId, newName, newFileName) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
config.name = newName;
|
||||
config.fileName = newFileName;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -319,6 +341,37 @@ class ProjectService {
|
||||
this.configs = this.configs.filter(c => c.id !== configId);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* [新增] 重命名磁盘上的配置文件
|
||||
*/
|
||||
async renameConfigFileOnDisk(configId, newFileName) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (!config)
|
||||
return false;
|
||||
const oldFilePath = this.getConfigFilePath(configId);
|
||||
// 为了计算新路径,临时使用新的文件名
|
||||
const oldFileName = config.fileName;
|
||||
config.fileName = newFileName;
|
||||
const newFilePath = this.getConfigFilePath(configId);
|
||||
// 恢复旧的文件名,因为 ProjectService.updateConfigName 会在 ConfigPanel 中调用
|
||||
config.fileName = oldFileName;
|
||||
if (!oldFilePath || !newFilePath) {
|
||||
return false;
|
||||
}
|
||||
if (!fs.existsSync(oldFilePath)) {
|
||||
console.warn(`旧配置文件不存在,跳过磁盘重命名: ${oldFilePath}`);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await fs.promises.rename(oldFilePath, newFilePath);
|
||||
console.log(`✅ 已重命名配置文件: ${oldFilePath} -> ${newFilePath}`);
|
||||
return true;
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`重命名配置文件失败: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// =============== 模块文件夹相关方法 ===============
|
||||
getModuleFoldersByContainer(containerId) {
|
||||
return this.moduleFolders.filter(folder => folder.containerId === containerId);
|
||||
@@ -346,14 +399,17 @@ class ProjectService {
|
||||
this.moduleFolders = this.moduleFolders.filter(f => f.id !== folderId);
|
||||
return true;
|
||||
}
|
||||
renameModuleFolder(folderId, newName) {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder)
|
||||
return false;
|
||||
const oldName = folder.localPath.split('/').pop() || '';
|
||||
folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* [删除] 此方法已被 ConfigPanel 中的 updateModuleFolder 替换,以支持同步磁盘操作。
|
||||
*/
|
||||
// renameModuleFolder(folderId: string, newName: string): boolean {
|
||||
// const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
// if (!folder) return false;
|
||||
//
|
||||
// const oldName = folder.localPath.split('/').pop() || '';
|
||||
// folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
// return true;
|
||||
// }
|
||||
// =============== 文件系统操作 (新增/修改) ===============
|
||||
/**
|
||||
* 获取项目目录重命名所需的旧路径和新路径(新增)
|
||||
@@ -633,6 +689,7 @@ class ProjectService {
|
||||
const pathParts = folder.localPath.split('/').filter(part => part);
|
||||
if (pathParts.length < 4)
|
||||
return null;
|
||||
// 路径的最后一部分是文件夹的名称
|
||||
const folderName = pathParts[pathParts.length - 1];
|
||||
return path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -60,7 +60,6 @@ class AircraftView extends BaseView_1.BaseView {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
/* ❌ 原来这里有 margin: 0 auto; 已去掉,避免“获取仓库”按钮被居中 */
|
||||
}
|
||||
.btn-new:hover {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
@@ -74,10 +73,7 @@ class AircraftView extends BaseView_1.BaseView {
|
||||
.aircraft-name:hover {
|
||||
background: var(--vscode-input-background);
|
||||
}
|
||||
.new-button-container {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
/* 移除冗余的 .new-button-container 样式 */
|
||||
|
||||
/* 仓库 + 分支树公共样式 */
|
||||
.config-section {
|
||||
@@ -172,7 +168,7 @@ class AircraftView extends BaseView_1.BaseView {
|
||||
<tbody>
|
||||
${aircraftsHtml}
|
||||
<tr>
|
||||
<td colspan="3" class="new-button-container">
|
||||
<td colspan="3" style="text-align: center; padding: 20px;">
|
||||
<button class="btn-new" onclick="createNewAircraft()">+ 新建飞行器</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"AircraftView.js","sourceRoot":"","sources":["../../../src/panels/views/AircraftView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,MAAa,YAAa,SAAQ,mBAAQ;IACtC,MAAM,CAAC,IAAwC;QAC3C,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,EAAE,CAAC;QAExC,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;;oEAGY,QAAQ,CAAC,EAAE,QAAQ,QAAQ,CAAC,IAAI;;;2EAGzB,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,SAAS;;;0EAGrC,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,IAAI;0EAC/B,QAAQ,CAAC,EAAE;;;SAG5E,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;MAChB,IAAI,CAAC,mBAAmB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgJlB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAqRnB,CAAC;IACL,CAAC;CACJ;AAjcD,oCAicC"}
|
||||
{"version":3,"file":"AircraftView.js","sourceRoot":"","sources":["../../../src/panels/views/AircraftView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,MAAa,YAAa,SAAQ,mBAAQ;IACtC,MAAM,CAAC,IAAwC;QAC3C,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,EAAE,CAAC;QAExC,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;;oEAGY,QAAQ,CAAC,EAAE,QAAQ,QAAQ,CAAC,IAAI;;;2EAGzB,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,SAAS;;;0EAGrC,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,IAAI;0EAC/B,QAAQ,CAAC,EAAE;;;SAG5E,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;MAChB,IAAI,CAAC,mBAAmB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4IlB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAqRnB,CAAC;IACL,CAAC;CACJ;AA7bD,oCA6bC"}
|
||||
@@ -16,11 +16,14 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
<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>
|
||||
<span class="editable"
|
||||
onclick="editConfigName('${config.id}', '${config.name.replace(/'/g, '\\\'')}', '${config.fileName.replace(/'/g, '\\\'')}')">
|
||||
🔧 ${config.name}
|
||||
</span>
|
||||
</td>
|
||||
<td>local</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openConfigFileInVSCode('${config.id}')">📄 ${config.fileName}</span>
|
||||
<span class="clickable config-file-name" data-filename="${config.fileName}" onclick="openConfigFileInVSCode('${config.id}')">📄 ${config.fileName}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-delete" onclick="deleteConfig('${config.id}')">删除</button>
|
||||
@@ -34,17 +37,20 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
if (folder.uploaded) {
|
||||
category += '(已上传)';
|
||||
}
|
||||
// 确保文件名被正确提取和转义
|
||||
const fileName = folder.localPath.split('/').pop() || '';
|
||||
const escapedFolderName = folder.name.replace(/'/g, '\\\'');
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable clickable" onclick="renameModuleFolder('${folder.id}', '${folder.name}')">
|
||||
<span class="editable clickable module-folder-name" data-folder-id="${folder.id}"
|
||||
onclick="renameModuleFolder('${folder.id}', '${escapedFolderName}')">
|
||||
${icon} ${folder.name}
|
||||
</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable"
|
||||
<span class="clickable module-disk-path" data-disk-name="${fileName}"
|
||||
onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">
|
||||
📄 ${fileName}
|
||||
</span>
|
||||
@@ -259,11 +265,9 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
|
||||
</div>
|
||||
|
||||
<!-- 配置文件管理部分 -->
|
||||
<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>
|
||||
@@ -285,11 +289,9 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 模块文件夹管理部分 -->
|
||||
<div class="config-section">
|
||||
<h3 class="section-title">📚 模块云仓库</h3>
|
||||
|
||||
<!-- 仓库选择区域 -->
|
||||
<div class="url-input-section">
|
||||
<h4>🔗 获取仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||
@@ -311,41 +313,229 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
let branchTreeData = [];
|
||||
let selectedConfigs = new Set();
|
||||
|
||||
// 只负责"改名"的函数
|
||||
function renameModuleFolder(folderId, oldName) {
|
||||
showPromptDialog(
|
||||
'重命名模块文件夹',
|
||||
'请输入新的名称:',
|
||||
oldName || '',
|
||||
function(newName) {
|
||||
if (newName && newName.trim() && newName !== oldName) {
|
||||
vscode.postMessage({
|
||||
type: 'renameModuleFolder',
|
||||
folderId: folderId,
|
||||
newName: newName.trim()
|
||||
});
|
||||
}
|
||||
// [新增] 配置文件重命名弹窗
|
||||
function showConfigRenameDialog(configId, currentName, currentFileName) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'configRenameModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog" style="width: 450px;">
|
||||
<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="configDisplayNameInput" class="merge-input-field"
|
||||
placeholder="在配置栏显示的名称" value="\${currentName}">
|
||||
<div class="merge-input-help">在左侧配置栏显示的名称</div>
|
||||
</div>
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">文件名称 (将同步修改磁盘文件)</label>
|
||||
<input type="text" id="configFileNameInput" class="merge-input-field"
|
||||
placeholder="磁盘上的实际文件名" value="\${currentFileName}">
|
||||
<div class="merge-input-help">请使用英文、数字、中文、-、_,不要使用空格和/</div>
|
||||
</div>
|
||||
<div id="fileNameValidationMessage" style="color: var(--vscode-inputValidation-errorForeground); font-size: 12px; margin-top: 5px;"></div>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeConfigRenameDialog()">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" id="configRenameConfirmBtn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
const displayNameInput = document.getElementById('configDisplayNameInput');
|
||||
const fileNameInput = document.getElementById('configFileNameInput');
|
||||
const confirmBtn = document.getElementById('configRenameConfirmBtn');
|
||||
const validationMessage = document.getElementById('fileNameValidationMessage');
|
||||
|
||||
function validateFileName(input) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
|
||||
if (!input.trim()) {
|
||||
validationMessage.textContent = '文件名不能为空';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
if (input.includes('/') || input.includes(' ')) {
|
||||
validationMessage.textContent = '文件名不能包含空格和/,请使用-或_代替';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
validationMessage.textContent = '';
|
||||
confirmBtn.disabled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fileNameInput) {
|
||||
fileNameInput.addEventListener('input', (e) => {
|
||||
validateFileName(e.target.value);
|
||||
});
|
||||
validateFileName(fileNameInput.value);
|
||||
}
|
||||
|
||||
confirmBtn.addEventListener('click', function() {
|
||||
const newName = displayNameInput.value.trim();
|
||||
const newFileName = fileNameInput.value.trim();
|
||||
|
||||
if (!validateFileName(newFileName)) {
|
||||
alert(validationMessage.textContent || '请修复文件名错误');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName && newFileName && (newName !== currentName || newFileName !== currentFileName)) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigName',
|
||||
configId: configId,
|
||||
name: newName,
|
||||
fileName: newFileName
|
||||
});
|
||||
}
|
||||
closeConfigRenameDialog();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
if (displayNameInput) {
|
||||
displayNameInput.focus();
|
||||
displayNameInput.select();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closeConfigRenameDialog() {
|
||||
const modal = document.getElementById('configRenameModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// [修改] editConfigName:使用新的双输入弹窗
|
||||
function editConfigName(configId, currentName, currentFileName) {
|
||||
// currentFileName 现在已从模板传入
|
||||
showConfigRenameDialog(configId, currentName, currentFileName);
|
||||
}
|
||||
|
||||
// [新增] 模块文件夹重命名双输入弹窗
|
||||
function showModuleFolderRenameDialog(folderId, currentName, currentFolderName) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'moduleRenameModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog" style="width: 450px;">
|
||||
<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="moduleDisplayNameInput" class="merge-input-field"
|
||||
placeholder="在配置栏显示的名称" value="\${currentName}">
|
||||
<div class="merge-input-help">在左侧配置栏显示的名称</div>
|
||||
</div>
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">磁盘文件夹名称 (将同步修改磁盘目录)</label>
|
||||
<input type="text" id="moduleFolderNameInput" class="merge-input-field"
|
||||
placeholder="磁盘上的实际文件夹名" value="\${currentFolderName}">
|
||||
<div class="merge-input-help">请使用英文、数字、中文、-、_,不要使用空格和/</div>
|
||||
</div>
|
||||
<div id="moduleFolderNameValidationMessage" style="color: var(--vscode-inputValidation-errorForeground); font-size: 12px; margin-top: 5px;"></div>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeModuleFolderRenameDialog()">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" id="moduleRenameConfirmBtn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
const displayNameInput = document.getElementById('moduleDisplayNameInput');
|
||||
const folderNameInput = document.getElementById('moduleFolderNameInput');
|
||||
const confirmBtn = document.getElementById('moduleRenameConfirmBtn');
|
||||
const validationMessage = document.getElementById('moduleFolderNameValidationMessage');
|
||||
|
||||
function validateFolderName(input) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
|
||||
if (!input.trim()) {
|
||||
validationMessage.textContent = '文件夹名不能为空';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.includes('/') || input.includes(' ')) {
|
||||
validationMessage.textContent = '文件夹名不能包含空格和/,请使用-或_代替';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
validationMessage.textContent = '';
|
||||
confirmBtn.disabled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (folderNameInput) {
|
||||
folderNameInput.addEventListener('input', (e) => {
|
||||
validateFolderName(e.target.value);
|
||||
});
|
||||
validateFolderName(folderNameInput.value);
|
||||
}
|
||||
|
||||
confirmBtn.addEventListener('click', function() {
|
||||
const newName = displayNameInput.value.trim();
|
||||
const newFolderName = folderNameInput.value.trim();
|
||||
|
||||
if (!validateFolderName(newFolderName)) {
|
||||
alert(validationMessage.textContent || '请修复文件夹名错误');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName && newFolderName && (newName !== currentName || newFolderName !== currentFolderName)) {
|
||||
vscode.postMessage({
|
||||
type: 'renameModuleFolder',
|
||||
folderId: folderId,
|
||||
newName: newName,
|
||||
newFolderName: newFolderName
|
||||
});
|
||||
}
|
||||
closeModuleFolderRenameDialog();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
if (displayNameInput) {
|
||||
displayNameInput.focus();
|
||||
displayNameInput.select();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closeModuleFolderRenameDialog() {
|
||||
const modal = document.getElementById('moduleRenameModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// [修改] renameModuleFolder:获取磁盘文件夹名并使用双输入弹窗
|
||||
function renameModuleFolder(folderId, currentName) {
|
||||
// 通过 data-folder-id 找到模块文件夹的行
|
||||
// 修复:避免在 JS 字符串中使用内嵌模板字符串,改用拼接以解决编译问题
|
||||
const editableSpan = document.querySelector('.module-folder-name[data-folder-id="' + folderId + '"]');
|
||||
if (!editableSpan) return;
|
||||
|
||||
const folderRow = editableSpan.closest('tr');
|
||||
// 从第三列的 data-disk-name 属性中获取当前的磁盘文件夹名称
|
||||
const fileNameSpan = folderRow.cells[2].querySelector('.module-disk-path');
|
||||
const currentFolderName = fileNameSpan.getAttribute('data-disk-name');
|
||||
|
||||
showModuleFolderRenameDialog(folderId, currentName, currentFolderName);
|
||||
}
|
||||
|
||||
// 配置管理功能
|
||||
function editConfigName(configId, currentName) {
|
||||
showPromptDialog(
|
||||
'修改配置名称',
|
||||
'请输入新的配置名称:',
|
||||
currentName,
|
||||
function(newName) {
|
||||
if (newName && newName !== currentName) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigName',
|
||||
configId: configId,
|
||||
name: newName
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
// 原始的 editConfigName 已被修改为接受三个参数
|
||||
|
||||
// 在 VSCode 中打开配置文件
|
||||
function openConfigFileInVSCode(configId) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -58,7 +58,6 @@ class ContainerView extends BaseView_1.BaseView {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
/* ❌ 原来这里有 margin: 0 auto; 已去掉,避免“获取仓库”按钮被居中 */
|
||||
}
|
||||
.btn-new:hover {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"ContainerView.js","sourceRoot":"","sources":["../../../src/panels/views/ContainerView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,MAAa,aAAc,SAAQ,mBAAQ;IACvC,MAAM,CAAC,IAAyB;QAC5B,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC;QAE1C,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAA4B,EAAE,EAAE,CAAC;;;yEAGP,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC,IAAI,UAAU,SAAS,CAAC,IAAI;;;4EAGtD,SAAS,CAAC,EAAE;;;2EAGb,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC,IAAI;2EACjC,SAAS,CAAC,EAAE;;;SAG9E,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;MAChB,IAAI,CAAC,mBAAmB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gFAkHgD,QAAQ,EAAE,IAAI,IAAI,OAAO;;;;;;;;;;;;;cAa3F,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmQpB,CAAC;IACL,CAAC;CACJ;AAhaD,sCAgaC"}
|
||||
{"version":3,"file":"ContainerView.js","sourceRoot":"","sources":["../../../src/panels/views/ContainerView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,MAAa,aAAc,SAAQ,mBAAQ;IACvC,MAAM,CAAC,IAAyB;QAC5B,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC;QAE1C,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAA4B,EAAE,EAAE,CAAC;;;yEAGP,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC,IAAI,UAAU,SAAS,CAAC,IAAI;;;4EAGtD,SAAS,CAAC,EAAE;;;2EAGb,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC,IAAI;2EACjC,SAAS,CAAC,EAAE;;;SAG9E,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;MAChB,IAAI,CAAC,mBAAmB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gFAiHgD,QAAQ,EAAE,IAAI,IAAI,OAAO;;;;;;;;;;;;;cAa3F,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmQpB,CAAC;IACL,CAAC;CACJ;AA/ZD,sCA+ZC"}
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/panels/ConfigPanel.ts
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { ProjectView } from './views/ProjectView';
|
||||
@@ -353,22 +354,23 @@ export class ConfigPanel {
|
||||
'goBackToContainers': () => this.handleGoBackToContainers(),
|
||||
|
||||
// 项目管理 (MODIFIED)
|
||||
'updateProjectName': (data) => this.updateProjectName(data.projectId, data.name), // <-- MODIFIED
|
||||
'updateProjectName': (data) => this.updateProjectName(data.projectId, data.name),
|
||||
'createProject': (data) => this.createProject(data.name),
|
||||
'deleteProject': (data) => this.deleteProject(data.projectId),
|
||||
|
||||
// 飞行器管理 (MODIFIED)
|
||||
'updateAircraftName': (data) => this.updateAircraftName(data.aircraftId, data.name), // <-- MODIFIED
|
||||
'updateAircraftName': (data) => this.updateAircraftName(data.aircraftId, data.name),
|
||||
'createAircraft': (data) => this.createAircraft(data.name),
|
||||
'deleteAircraft': (data) => this.deleteAircraft(data.aircraftId),
|
||||
|
||||
// 容器管理 (MODIFIED)
|
||||
'updateContainerName': (data) => this.updateContainerName(data.containerId, data.name), // <-- MODIFIED
|
||||
'updateContainerName': (data) => this.updateContainerName(data.containerId, data.name),
|
||||
'createContainer': (data) => this.createContainer(data.name),
|
||||
'deleteContainer': (data) => this.deleteContainer(data.containerId),
|
||||
|
||||
// 配置管理
|
||||
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name),
|
||||
// [修改] 接收新的文件名
|
||||
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name, data.fileName),
|
||||
'createConfig': (data) => this.createConfig(data.name),
|
||||
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||
@@ -393,7 +395,8 @@ export class ConfigPanel {
|
||||
'deleteModuleFolder': (data) => this.deleteModuleFolder(data.folderId),
|
||||
'importGitFile': (data) => this.importGitFile(data.filePath),
|
||||
'openTheModuleFolder': (data) => this.openTheModuleFolder(data.moduleType, data.id),
|
||||
'renameModuleFolder': (data) => this.renameModuleFolder(data.folderId, data.newName),
|
||||
// [修改] 接收新的显示名称和磁盘文件夹名称
|
||||
'renameModuleFolder': (data) => this.renameModuleFolder(data.folderId, data.newName, data.newFolderName),
|
||||
|
||||
// 模块上传功能 (原逻辑)
|
||||
'uploadGitModuleFolder': (data) => this.uploadGitModuleFolder(data.folderId, data.username, data.password),
|
||||
@@ -749,11 +752,25 @@ export class ConfigPanel {
|
||||
// 配置管理方法
|
||||
// =============================================
|
||||
|
||||
private async updateConfigName(configId: string, newName: string): Promise<void> {
|
||||
if (this.projectService.updateConfigName(configId, newName)) {
|
||||
vscode.window.showInformationMessage(`配置名称更新: ${newName}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
/**
|
||||
* [修改] 同时更新配置显示名称和文件名,并处理磁盘文件重命名
|
||||
*/
|
||||
private async updateConfigName(configId: string, newName: string, newFileName: string): Promise<void> {
|
||||
const config = this.projectService.getConfig(configId);
|
||||
if (!config) return;
|
||||
|
||||
try {
|
||||
// 1. 重命名磁盘文件
|
||||
await this.projectService.renameConfigFileOnDisk(configId, newFileName);
|
||||
|
||||
// 2. 更新内存数据
|
||||
if (this.projectService.updateConfigName(configId, newName, newFileName)) {
|
||||
vscode.window.showInformationMessage(`✅ 配置/文件名已更新: ${newName} / ${newFileName}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(`❌ 重命名磁盘文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1421,7 +1438,52 @@ export class ConfigPanel {
|
||||
// =============================================
|
||||
// 模块文件夹管理方法
|
||||
// =============================================
|
||||
|
||||
/**
|
||||
* [修改] 同时处理显示名称和磁盘文件夹名称的重命名
|
||||
*/
|
||||
private async renameModuleFolder(folderId: string, newName: string, newFolderName: string): Promise<void> {
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
return;
|
||||
}
|
||||
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath) {
|
||||
vscode.window.showErrorMessage('无法获取模块文件夹路径');
|
||||
return;
|
||||
}
|
||||
|
||||
const oldFolderName = folder.localPath.split('/').pop();
|
||||
if (!oldFolderName) return;
|
||||
|
||||
const newFullPath = path.join(path.dirname(fullPath), newFolderName);
|
||||
const isDiskRenameNeeded = oldFolderName !== newFolderName;
|
||||
|
||||
try {
|
||||
if (isDiskRenameNeeded) {
|
||||
// 1. 重命名磁盘文件夹
|
||||
await this.projectService.renameDirectoryOnDisk(fullPath, newFullPath);
|
||||
}
|
||||
|
||||
// 2. 更新内存数据:显示名和 localPath
|
||||
const newLocalPath = folder.localPath.replace(new RegExp(`/${oldFolderName}$`), '/' + newFolderName);
|
||||
|
||||
this.projectService.updateModuleFolder(folderId, {
|
||||
name: newName,
|
||||
localPath: newLocalPath
|
||||
});
|
||||
|
||||
await this.saveCurrentProjectData();
|
||||
|
||||
vscode.window.showInformationMessage(`✅ 已重命名文件夹: ${oldFolderName} → ${newFolderName} (显示名: ${newName})`);
|
||||
this.updateWebview();
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
}
|
||||
}
|
||||
|
||||
private async loadModuleFolder(folderId: string): Promise<void> {
|
||||
this.currentModuleFolderId = folderId;
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
@@ -1878,34 +1940,35 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private async renameModuleFolder(folderId: string, newName: string): Promise<void> {
|
||||
const folder = this.projectService.getModuleFolder(folderId);
|
||||
if (!folder) {
|
||||
vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
return;
|
||||
}
|
||||
// [删除] 此方法已被上面的 renameModuleFolder 替换
|
||||
// private async renameModuleFolder(folderId: string, newName: string): Promise<void> {
|
||||
// const folder = this.projectService.getModuleFolder(folderId);
|
||||
// if (!folder) {
|
||||
// vscode.window.showErrorMessage('未找到模块文件夹');
|
||||
// return;
|
||||
// }
|
||||
|
||||
const oldName = folder.localPath.split('/').pop();
|
||||
if (!oldName) return;
|
||||
// const oldName = folder.localPath.split('/').pop();
|
||||
// if (!oldName) return;
|
||||
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath) return;
|
||||
// const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
// if (!fullPath) return;
|
||||
|
||||
const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
// const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
|
||||
try {
|
||||
const fs = require('fs');
|
||||
await fs.promises.rename(fullPath, newFullPath);
|
||||
// try {
|
||||
// const fs = require('fs');
|
||||
// await fs.promises.rename(fullPath, newFullPath);
|
||||
|
||||
this.projectService.renameModuleFolder(folderId, newName);
|
||||
await this.saveCurrentProjectData();
|
||||
// this.projectService.renameModuleFolder(folderId, newName);
|
||||
// await this.saveCurrentProjectData();
|
||||
|
||||
vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
||||
this.updateWebview();
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
}
|
||||
}
|
||||
// vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
||||
// this.updateWebview();
|
||||
// } catch (error) {
|
||||
// vscode.window.showErrorMessage('重命名失败: ' + error);
|
||||
// }
|
||||
// }
|
||||
|
||||
// =============================================
|
||||
// 项目路径选择方法
|
||||
|
||||
@@ -29,6 +29,23 @@ export class ProjectService {
|
||||
const randomPart = `${Date.now().toString(36)}${Math.random().toString(36).substring(2, 8)}`;
|
||||
return `${prefix}${randomPart}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* [新增] 文件名/文件夹名净化:只允许中文、字母、数字、-、_
|
||||
*/
|
||||
public sanitizeFileName(name: string): string {
|
||||
// 允许中文、字母、数字、-、_
|
||||
let fileName = name.trim().toLowerCase();
|
||||
// 1. 替换所有空格为下划线
|
||||
fileName = fileName.replace(/\s+/g, '_');
|
||||
// 2. 移除所有不被允许的特殊字符(只保留中文、字母、数字、-、_)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-z0-9_-]/g, '');
|
||||
// 3. 确保不为空
|
||||
if (fileName.length === 0) {
|
||||
return 'config_file';
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// =============== 项目相关方法 ===============
|
||||
|
||||
@@ -325,10 +342,13 @@ export class ProjectService {
|
||||
|
||||
async createConfig(name: string, containerId: string): Promise<string> {
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
// 使用新增的 sanitizeFileName 方法来处理文件名
|
||||
const newFileName = this.sanitizeFileName(name);
|
||||
|
||||
const newConfig: Config = {
|
||||
id: newId,
|
||||
name: name,
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
||||
fileName: newFileName,
|
||||
containerId: containerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
@@ -337,10 +357,14 @@ export class ProjectService {
|
||||
return newId;
|
||||
}
|
||||
|
||||
updateConfigName(configId: string, newName: string): boolean {
|
||||
/**
|
||||
* [修改] 同时更新配置显示名称和文件名称
|
||||
*/
|
||||
updateConfigName(configId: string, newName: string, newFileName: string): boolean {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
config.name = newName;
|
||||
config.fileName = newFileName;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -353,6 +377,41 @@ export class ProjectService {
|
||||
this.configs = this.configs.filter(c => c.id !== configId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [新增] 重命名磁盘上的配置文件
|
||||
*/
|
||||
async renameConfigFileOnDisk(configId: string, newFileName: string): Promise<boolean> {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (!config) return false;
|
||||
|
||||
const oldFilePath = this.getConfigFilePath(configId);
|
||||
// 为了计算新路径,临时使用新的文件名
|
||||
const oldFileName = config.fileName;
|
||||
config.fileName = newFileName;
|
||||
const newFilePath = this.getConfigFilePath(configId);
|
||||
// 恢复旧的文件名,因为 ProjectService.updateConfigName 会在 ConfigPanel 中调用
|
||||
config.fileName = oldFileName;
|
||||
|
||||
if (!oldFilePath || !newFilePath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(oldFilePath)) {
|
||||
console.warn(`旧配置文件不存在,跳过磁盘重命名: ${oldFilePath}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.promises.rename(oldFilePath, newFilePath);
|
||||
console.log(`✅ 已重命名配置文件: ${oldFilePath} -> ${newFilePath}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`重命名配置文件失败: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =============== 模块文件夹相关方法 ===============
|
||||
|
||||
@@ -387,14 +446,17 @@ export class ProjectService {
|
||||
return true;
|
||||
}
|
||||
|
||||
renameModuleFolder(folderId: string, newName: string): boolean {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder) return false;
|
||||
|
||||
const oldName = folder.localPath.split('/').pop() || '';
|
||||
folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* [删除] 此方法已被 ConfigPanel 中的 updateModuleFolder 替换,以支持同步磁盘操作。
|
||||
*/
|
||||
// renameModuleFolder(folderId: string, newName: string): boolean {
|
||||
// const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
// if (!folder) return false;
|
||||
//
|
||||
// const oldName = folder.localPath.split('/').pop() || '';
|
||||
// folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// =============== 文件系统操作 (新增/修改) ===============
|
||||
|
||||
@@ -707,6 +769,7 @@ export class ProjectService {
|
||||
const pathParts = folder.localPath.split('/').filter(part => part);
|
||||
if (pathParts.length < 4) return null;
|
||||
|
||||
// 路径的最后一部分是文件夹的名称
|
||||
const folderName = pathParts[pathParts.length - 1];
|
||||
return path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ export class AircraftView extends BaseView {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
/* ❌ 原来这里有 margin: 0 auto; 已去掉,避免“获取仓库”按钮被居中 */
|
||||
}
|
||||
.btn-new:hover {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
@@ -75,10 +74,7 @@ export class AircraftView extends BaseView {
|
||||
.aircraft-name:hover {
|
||||
background: var(--vscode-input-background);
|
||||
}
|
||||
.new-button-container {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
/* 移除冗余的 .new-button-container 样式 */
|
||||
|
||||
/* 仓库 + 分支树公共样式 */
|
||||
.config-section {
|
||||
@@ -173,7 +169,7 @@ export class AircraftView extends BaseView {
|
||||
<tbody>
|
||||
${aircraftsHtml}
|
||||
<tr>
|
||||
<td colspan="3" class="new-button-container">
|
||||
<td colspan="3" style="text-align: center; padding: 20px;">
|
||||
<button class="btn-new" onclick="createNewAircraft()">+ 新建飞行器</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -39,11 +39,14 @@ export class ConfigView extends BaseView {
|
||||
<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>
|
||||
<span class="editable"
|
||||
onclick="editConfigName('${config.id}', '${config.name.replace(/'/g, '\\\'')}', '${config.fileName.replace(/'/g, '\\\'')}')">
|
||||
🔧 ${config.name}
|
||||
</span>
|
||||
</td>
|
||||
<td>local</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openConfigFileInVSCode('${config.id}')">📄 ${config.fileName}</span>
|
||||
<span class="clickable config-file-name" data-filename="${config.fileName}" onclick="openConfigFileInVSCode('${config.id}')">📄 ${config.fileName}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-delete" onclick="deleteConfig('${config.id}')">删除</button>
|
||||
@@ -59,18 +62,21 @@ export class ConfigView extends BaseView {
|
||||
category += '(已上传)';
|
||||
}
|
||||
|
||||
// 确保文件名被正确提取和转义
|
||||
const fileName = folder.localPath.split('/').pop() || '';
|
||||
|
||||
const escapedFolderName = folder.name.replace(/'/g, '\\\'');
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable clickable" onclick="renameModuleFolder('${folder.id}', '${folder.name}')">
|
||||
<span class="editable clickable module-folder-name" data-folder-id="${folder.id}"
|
||||
onclick="renameModuleFolder('${folder.id}', '${escapedFolderName}')">
|
||||
${icon} ${folder.name}
|
||||
</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable"
|
||||
<span class="clickable module-disk-path" data-disk-name="${fileName}"
|
||||
onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">
|
||||
📄 ${fileName}
|
||||
</span>
|
||||
@@ -287,11 +293,9 @@ export class ConfigView extends BaseView {
|
||||
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
|
||||
</div>
|
||||
|
||||
<!-- 配置文件管理部分 -->
|
||||
<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>
|
||||
@@ -313,11 +317,9 @@ export class ConfigView extends BaseView {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 模块文件夹管理部分 -->
|
||||
<div class="config-section">
|
||||
<h3 class="section-title">📚 模块云仓库</h3>
|
||||
|
||||
<!-- 仓库选择区域 -->
|
||||
<div class="url-input-section">
|
||||
<h4>🔗 获取仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||
@@ -339,41 +341,229 @@ export class ConfigView extends BaseView {
|
||||
let branchTreeData = [];
|
||||
let selectedConfigs = new Set();
|
||||
|
||||
// 只负责"改名"的函数
|
||||
function renameModuleFolder(folderId, oldName) {
|
||||
showPromptDialog(
|
||||
'重命名模块文件夹',
|
||||
'请输入新的名称:',
|
||||
oldName || '',
|
||||
function(newName) {
|
||||
if (newName && newName.trim() && newName !== oldName) {
|
||||
vscode.postMessage({
|
||||
type: 'renameModuleFolder',
|
||||
folderId: folderId,
|
||||
newName: newName.trim()
|
||||
});
|
||||
}
|
||||
// [新增] 配置文件重命名弹窗
|
||||
function showConfigRenameDialog(configId, currentName, currentFileName) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'configRenameModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog" style="width: 450px;">
|
||||
<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="configDisplayNameInput" class="merge-input-field"
|
||||
placeholder="在配置栏显示的名称" value="\${currentName}">
|
||||
<div class="merge-input-help">在左侧配置栏显示的名称</div>
|
||||
</div>
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">文件名称 (将同步修改磁盘文件)</label>
|
||||
<input type="text" id="configFileNameInput" class="merge-input-field"
|
||||
placeholder="磁盘上的实际文件名" value="\${currentFileName}">
|
||||
<div class="merge-input-help">请使用英文、数字、中文、-、_,不要使用空格和/</div>
|
||||
</div>
|
||||
<div id="fileNameValidationMessage" style="color: var(--vscode-inputValidation-errorForeground); font-size: 12px; margin-top: 5px;"></div>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeConfigRenameDialog()">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" id="configRenameConfirmBtn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
const displayNameInput = document.getElementById('configDisplayNameInput');
|
||||
const fileNameInput = document.getElementById('configFileNameInput');
|
||||
const confirmBtn = document.getElementById('configRenameConfirmBtn');
|
||||
const validationMessage = document.getElementById('fileNameValidationMessage');
|
||||
|
||||
function validateFileName(input) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
|
||||
if (!input.trim()) {
|
||||
validationMessage.textContent = '文件名不能为空';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
if (input.includes('/') || input.includes(' ')) {
|
||||
validationMessage.textContent = '文件名不能包含空格和/,请使用-或_代替';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
validationMessage.textContent = '';
|
||||
confirmBtn.disabled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fileNameInput) {
|
||||
fileNameInput.addEventListener('input', (e) => {
|
||||
validateFileName(e.target.value);
|
||||
});
|
||||
validateFileName(fileNameInput.value);
|
||||
}
|
||||
|
||||
confirmBtn.addEventListener('click', function() {
|
||||
const newName = displayNameInput.value.trim();
|
||||
const newFileName = fileNameInput.value.trim();
|
||||
|
||||
if (!validateFileName(newFileName)) {
|
||||
alert(validationMessage.textContent || '请修复文件名错误');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName && newFileName && (newName !== currentName || newFileName !== currentFileName)) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigName',
|
||||
configId: configId,
|
||||
name: newName,
|
||||
fileName: newFileName
|
||||
});
|
||||
}
|
||||
closeConfigRenameDialog();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
if (displayNameInput) {
|
||||
displayNameInput.focus();
|
||||
displayNameInput.select();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closeConfigRenameDialog() {
|
||||
const modal = document.getElementById('configRenameModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// [修改] editConfigName:使用新的双输入弹窗
|
||||
function editConfigName(configId, currentName, currentFileName) {
|
||||
// currentFileName 现在已从模板传入
|
||||
showConfigRenameDialog(configId, currentName, currentFileName);
|
||||
}
|
||||
|
||||
// [新增] 模块文件夹重命名双输入弹窗
|
||||
function showModuleFolderRenameDialog(folderId, currentName, currentFolderName) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'moduleRenameModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog" style="width: 450px;">
|
||||
<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="moduleDisplayNameInput" class="merge-input-field"
|
||||
placeholder="在配置栏显示的名称" value="\${currentName}">
|
||||
<div class="merge-input-help">在左侧配置栏显示的名称</div>
|
||||
</div>
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">磁盘文件夹名称 (将同步修改磁盘目录)</label>
|
||||
<input type="text" id="moduleFolderNameInput" class="merge-input-field"
|
||||
placeholder="磁盘上的实际文件夹名" value="\${currentFolderName}">
|
||||
<div class="merge-input-help">请使用英文、数字、中文、-、_,不要使用空格和/</div>
|
||||
</div>
|
||||
<div id="moduleFolderNameValidationMessage" style="color: var(--vscode-inputValidation-errorForeground); font-size: 12px; margin-top: 5px;"></div>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeModuleFolderRenameDialog()">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" id="moduleRenameConfirmBtn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
const displayNameInput = document.getElementById('moduleDisplayNameInput');
|
||||
const folderNameInput = document.getElementById('moduleFolderNameInput');
|
||||
const confirmBtn = document.getElementById('moduleRenameConfirmBtn');
|
||||
const validationMessage = document.getElementById('moduleFolderNameValidationMessage');
|
||||
|
||||
function validateFolderName(input) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
|
||||
if (!input.trim()) {
|
||||
validationMessage.textContent = '文件夹名不能为空';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.includes('/') || input.includes(' ')) {
|
||||
validationMessage.textContent = '文件夹名不能包含空格和/,请使用-或_代替';
|
||||
confirmBtn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
validationMessage.textContent = '';
|
||||
confirmBtn.disabled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (folderNameInput) {
|
||||
folderNameInput.addEventListener('input', (e) => {
|
||||
validateFolderName(e.target.value);
|
||||
});
|
||||
validateFolderName(folderNameInput.value);
|
||||
}
|
||||
|
||||
confirmBtn.addEventListener('click', function() {
|
||||
const newName = displayNameInput.value.trim();
|
||||
const newFolderName = folderNameInput.value.trim();
|
||||
|
||||
if (!validateFolderName(newFolderName)) {
|
||||
alert(validationMessage.textContent || '请修复文件夹名错误');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName && newFolderName && (newName !== currentName || newFolderName !== currentFolderName)) {
|
||||
vscode.postMessage({
|
||||
type: 'renameModuleFolder',
|
||||
folderId: folderId,
|
||||
newName: newName,
|
||||
newFolderName: newFolderName
|
||||
});
|
||||
}
|
||||
closeModuleFolderRenameDialog();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
if (displayNameInput) {
|
||||
displayNameInput.focus();
|
||||
displayNameInput.select();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closeModuleFolderRenameDialog() {
|
||||
const modal = document.getElementById('moduleRenameModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// [修改] renameModuleFolder:获取磁盘文件夹名并使用双输入弹窗
|
||||
function renameModuleFolder(folderId, currentName) {
|
||||
// 通过 data-folder-id 找到模块文件夹的行
|
||||
// 修复:避免在 JS 字符串中使用内嵌模板字符串,改用拼接以解决编译问题
|
||||
const editableSpan = document.querySelector('.module-folder-name[data-folder-id="' + folderId + '"]');
|
||||
if (!editableSpan) return;
|
||||
|
||||
const folderRow = editableSpan.closest('tr');
|
||||
// 从第三列的 data-disk-name 属性中获取当前的磁盘文件夹名称
|
||||
const fileNameSpan = folderRow.cells[2].querySelector('.module-disk-path');
|
||||
const currentFolderName = fileNameSpan.getAttribute('data-disk-name');
|
||||
|
||||
showModuleFolderRenameDialog(folderId, currentName, currentFolderName);
|
||||
}
|
||||
|
||||
// 配置管理功能
|
||||
function editConfigName(configId, currentName) {
|
||||
showPromptDialog(
|
||||
'修改配置名称',
|
||||
'请输入新的配置名称:',
|
||||
currentName,
|
||||
function(newName) {
|
||||
if (newName && newName !== currentName) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigName',
|
||||
configId: configId,
|
||||
name: newName
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
// 原始的 editConfigName 已被修改为接受三个参数
|
||||
|
||||
// 在 VSCode 中打开配置文件
|
||||
function openConfigFileInVSCode(configId) {
|
||||
@@ -838,4 +1028,4 @@ export class ConfigView extends BaseView {
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@ export class ContainerView extends BaseView {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
/* ❌ 原来这里有 margin: 0 auto; 已去掉,避免“获取仓库”按钮被居中 */
|
||||
}
|
||||
.btn-new:hover {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
|
||||
Reference in New Issue
Block a user