打开git代码功能完成
This commit is contained in:
@@ -165,18 +165,9 @@ class ConfigPanel {
|
||||
case 'updateConfigName':
|
||||
await this.updateConfigName(data.configId, data.name);
|
||||
break;
|
||||
case 'updateConfigFileName':
|
||||
await this.updateConfigFileName(data.configId, data.fileName);
|
||||
break;
|
||||
case 'createConfig':
|
||||
await this.createConfig(data.name);
|
||||
break;
|
||||
case 'saveConfigFile':
|
||||
await this.saveConfigFileToDisk(data.configId, data.content);
|
||||
break;
|
||||
case 'loadConfigFile':
|
||||
this.loadConfigFile(data.configId);
|
||||
break;
|
||||
case 'deleteProject':
|
||||
await this.deleteProject(data.projectId);
|
||||
break;
|
||||
@@ -217,6 +208,9 @@ class ConfigPanel {
|
||||
case 'openGitRepoInVSCode':
|
||||
await this.openGitRepoInVSCode(data.repoId);
|
||||
break;
|
||||
case 'openConfigFileInVSCode':
|
||||
await this.openConfigFileInVSCode(data.configId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -339,7 +333,7 @@ class ConfigPanel {
|
||||
// 为每个分支创建独立的子目录
|
||||
const branchName = branch || 'main';
|
||||
const branchSafeName = branchName.replace(/[^a-zA-Z0-9-_]/g, '-');
|
||||
const repoDirName = `${name}-${branchSafeName}`;
|
||||
const repoDirName = name;
|
||||
// 路径:项目路径/飞行器名/容器名/仓库名-分支名/
|
||||
const localPath = path.join(projectPath, aircraft.name, container.name, repoDirName);
|
||||
console.log(`📁 Git仓库将保存到: ${localPath}`);
|
||||
@@ -475,8 +469,8 @@ class ConfigPanel {
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 删除 Git 仓库
|
||||
*/
|
||||
* 删除 Git 仓库
|
||||
*/
|
||||
async deleteGitRepo(repoId) {
|
||||
const repo = this.gitRepos.find(r => r.id === repoId);
|
||||
if (!repo)
|
||||
@@ -1015,16 +1009,6 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 更新文件名
|
||||
async updateConfigFileName(configId, fileName) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
config.fileName = fileName;
|
||||
vscode.window.showInformationMessage(`文件名更新: ${fileName}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 创建新配置文件
|
||||
async createConfig(name) {
|
||||
const newId = 'cfg' + (this.configs.length + 1);
|
||||
@@ -1078,95 +1062,6 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage(`删除配置文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
// 保存配置文件到磁盘
|
||||
async saveConfigFileToDisk(configId, content) {
|
||||
try {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (!config) {
|
||||
vscode.window.showErrorMessage('未找到配置文件');
|
||||
return;
|
||||
}
|
||||
const container = this.containers.find(c => c.id === config.containerId);
|
||||
if (!container) {
|
||||
vscode.window.showErrorMessage('未找到容器');
|
||||
return;
|
||||
}
|
||||
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
||||
if (!aircraft) {
|
||||
vscode.window.showErrorMessage('未找到飞行器');
|
||||
return;
|
||||
}
|
||||
const project = this.projects.find(p => p.id === aircraft.projectId);
|
||||
if (!project) {
|
||||
vscode.window.showErrorMessage('未找到项目');
|
||||
return;
|
||||
}
|
||||
const projectPath = this.projectPaths.get(aircraft.projectId);
|
||||
if (!projectPath) {
|
||||
vscode.window.showErrorMessage('未设置项目存储路径,请先配置项目');
|
||||
return;
|
||||
}
|
||||
// 构建文件路径:项目路径/飞行器名/容器名/文件名
|
||||
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
||||
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
|
||||
const fileUri = vscode.Uri.joinPath(containerDir, config.fileName);
|
||||
// 确保飞行器目录存在
|
||||
try {
|
||||
await vscode.workspace.fs.createDirectory(aircraftDir);
|
||||
}
|
||||
catch (error) {
|
||||
// 目录可能已存在,忽略错误
|
||||
}
|
||||
// 确保容器目录存在
|
||||
try {
|
||||
await vscode.workspace.fs.createDirectory(containerDir);
|
||||
}
|
||||
catch (error) {
|
||||
// 目录可能已存在,忽略错误
|
||||
}
|
||||
// 写入文件
|
||||
const uint8Array = new TextEncoder().encode(content);
|
||||
await vscode.workspace.fs.writeFile(fileUri, uint8Array);
|
||||
// 更新配置内容
|
||||
config.content = content;
|
||||
vscode.window.showInformationMessage(`配置文件已保存: ${fileUri.fsPath}`);
|
||||
// 保存数据到JSON文件
|
||||
await this.saveCurrentProjectData();
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`保存文件时出错: ${error}`);
|
||||
}
|
||||
}
|
||||
// 加载配置文件
|
||||
loadConfigFile(configId) {
|
||||
if (this.isWebviewDisposed) {
|
||||
console.log('⚠️ Webview 已被销毁,跳过加载配置文件');
|
||||
return;
|
||||
}
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'configFileLoaded',
|
||||
content: config.content || `# ${config.name} 的配置文件\n# 您可以在此编辑配置内容\n\n`
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.log('⚠️ 无法发送配置文件内容,Webview 可能已被销毁');
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'configFileLoaded',
|
||||
content: `# 这是 ${configId} 的配置文件\n# 您可以在此编辑配置内容\n\napp.name = "示例应用"\napp.port = 8080\napp.debug = true`
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.log('⚠️ 无法发送默认配置文件内容,Webview 可能已被销毁');
|
||||
}
|
||||
}
|
||||
}
|
||||
// === Git 分支管理 ===
|
||||
async fetchBranches(url) {
|
||||
try {
|
||||
@@ -1196,8 +1091,6 @@ class ConfigPanel {
|
||||
if (isRemote) {
|
||||
// 远程分支:移除 refs/remotes/origin/ 前缀
|
||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||
// 可以选择添加远程标识,或者不添加
|
||||
// branchName = `origin/${branchName}`; // 如果需要显示远程标识
|
||||
}
|
||||
else {
|
||||
// 本地分支:移除 refs/heads/ 前缀
|
||||
@@ -1371,6 +1264,47 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage(`打开 Git 仓库文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
async openConfigFileInVSCode(configId) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (!config) {
|
||||
vscode.window.showErrorMessage('未找到配置文件');
|
||||
return;
|
||||
}
|
||||
const container = this.containers.find(c => c.id === config.containerId);
|
||||
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 filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
||||
try {
|
||||
// 检查文件是否存在
|
||||
if (!fs.existsSync(filePath)) {
|
||||
vscode.window.showWarningMessage('配置文件不存在,将创建新文件');
|
||||
// 确保目录存在
|
||||
const dirPath = path.dirname(filePath);
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
// 创建文件
|
||||
await fs.promises.writeFile(filePath, config.content || '');
|
||||
}
|
||||
// 在 VSCode 中打开文件
|
||||
const document = await vscode.workspace.openTextDocument(filePath);
|
||||
await vscode.window.showTextDocument(document);
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`打开配置文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ConfigPanel = ConfigPanel;
|
||||
//# sourceMappingURL=ConfigPanel.js.map
|
||||
Reference in New Issue
Block a user