修改了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);
|
||||
// }
|
||||
// }
|
||||
// =============================================
|
||||
// 项目路径选择方法
|
||||
// =============================================
|
||||
|
||||
Reference in New Issue
Block a user