1、将每个代码仓库进行了隔离。2、优化了每个页面的ui对齐。3、增加了飞行器页面的所属项目显示。4、切换页面时对项目进行扫描,实时更新项目的结构,避免复制导致ui不显示的bug
This commit is contained in:
@@ -24,7 +24,6 @@ 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");
|
||||
@@ -97,15 +96,12 @@ class ConfigPanel {
|
||||
async openRepoSelectForScope(scope) {
|
||||
this.currentCloneScope = scope;
|
||||
await this.loadRepoConfigs();
|
||||
if (this.repoConfigs.length === 0) {
|
||||
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 "仓库配置" 按钮编辑 dcsp-repos.json。');
|
||||
return;
|
||||
}
|
||||
const repos = this.getRepoConfigsForScope(scope);
|
||||
if (this.isWebviewDisposed)
|
||||
return;
|
||||
this.panel.webview.postMessage({
|
||||
type: 'showRepoSelect',
|
||||
repos: this.repoConfigs.map(r => ({ name: r.name }))
|
||||
repos: repos.map(r => ({ name: r.name }))
|
||||
});
|
||||
}
|
||||
async openRepoSelect() {
|
||||
@@ -113,30 +109,24 @@ class ConfigPanel {
|
||||
}
|
||||
async openUploadRepoSelect(folderId, folderType) {
|
||||
await this.loadRepoConfigs();
|
||||
if (this.repoConfigs.length === 0) {
|
||||
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 "仓库配置" 按钮编辑 dcsp-repos.json。');
|
||||
return;
|
||||
}
|
||||
if (this.isWebviewDisposed)
|
||||
return;
|
||||
const repos = this.getRepoConfigsForScope('config');
|
||||
this.panel.webview.postMessage({
|
||||
type: 'showUploadRepoSelect',
|
||||
repos: this.repoConfigs.map(r => ({ name: r.name })),
|
||||
repos: repos.map(r => ({ name: r.name })),
|
||||
folderId,
|
||||
folderType
|
||||
});
|
||||
}
|
||||
async openUploadRepoSelectForScope(scope, id) {
|
||||
await this.loadRepoConfigs();
|
||||
if (this.repoConfigs.length === 0) {
|
||||
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 "仓库配置" 按钮编辑 dcsp-repos.json。');
|
||||
return;
|
||||
}
|
||||
const repos = this.getRepoConfigsForScope(scope);
|
||||
if (this.isWebviewDisposed)
|
||||
return;
|
||||
this.panel.webview.postMessage({
|
||||
type: 'showUploadRepoSelect',
|
||||
repos: this.repoConfigs.map(r => ({ name: r.name })),
|
||||
repos: repos.map(r => ({ name: r.name })),
|
||||
folderId: id,
|
||||
folderType: scope
|
||||
});
|
||||
@@ -298,7 +288,7 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
async handleOpenProject(data) {
|
||||
// [新增] 在进入视图前,主动扫描磁盘同步数据
|
||||
// 在进入视图前,主动扫描磁盘同步数据
|
||||
const changed = await this.projectService.refreshProjectContent(data.projectId);
|
||||
if (changed) {
|
||||
await this.saveCurrentProjectData(); // 如果有变动,立即保存
|
||||
@@ -308,7 +298,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
async handleOpenAircraftConfig(data) {
|
||||
// [新增] 进入飞行器详情前,主动同步容器列表
|
||||
// 进入飞行器详情前,主动同步容器列表
|
||||
const changed = await this.projectService.refreshAircraftContent(data.aircraftId);
|
||||
if (changed) {
|
||||
await this.saveCurrentProjectData();
|
||||
@@ -319,7 +309,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
async handleOpenContainerConfig(data) {
|
||||
// [新增] 进入容器详情前,主动同步配置和模块
|
||||
// 进入容器详情前,主动同步配置和模块
|
||||
const changed = await this.projectService.refreshContainerContent(data.containerId);
|
||||
if (changed) {
|
||||
await this.saveCurrentProjectData();
|
||||
@@ -517,7 +507,7 @@ class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
const containerId = await this.projectService.createContainer(name, this.currentAircraftId);
|
||||
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
||||
vscode.window.showInformationMessage(`新建容器: ${name}`);
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
@@ -1500,7 +1490,7 @@ class ConfigPanel {
|
||||
if (projectId) {
|
||||
this.currentProjectId = projectId;
|
||||
this.currentView = 'aircrafts';
|
||||
// [新增] 项目加载成功后,启动文件监听
|
||||
// 项目加载成功后,启动文件监听
|
||||
this.setupFileWatcher(projectPath, projectId);
|
||||
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载`);
|
||||
this.updateWebview();
|
||||
@@ -1514,15 +1504,14 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
setupFileWatcher(projectPath, projectId) {
|
||||
// 1. 如果已有监听器,先销毁
|
||||
// 如果已有监听器,先销毁
|
||||
if (this.fileWatcher) {
|
||||
this.fileWatcher.dispose();
|
||||
}
|
||||
// 2. 创建新的监听器:监听项目目录下的所有变化
|
||||
// Pattern: /path/to/project/**/*
|
||||
// 创建新的监听器:监听项目目录下的所有变化
|
||||
const pattern = new vscode.RelativePattern(projectPath, '**/*');
|
||||
this.fileWatcher = vscode.workspace.createFileSystemWatcher(pattern, false, true, false); // 忽略 onChange,只监听 Create/Delete
|
||||
// 3. 定义处理逻辑(使用防抖,避免连续创建文件导致多次刷新)
|
||||
// 定义处理逻辑(使用防抖,避免连续创建文件导致多次刷新)
|
||||
const handleCreate = async (uri) => {
|
||||
if (this.isWebviewDisposed)
|
||||
return;
|
||||
@@ -1535,7 +1524,6 @@ class ConfigPanel {
|
||||
let dataChanged = false;
|
||||
// 层级 1: 飞行器 (Folder)
|
||||
if (parts.length === 1) {
|
||||
// 检查是文件还是文件夹
|
||||
const stat = await vscode.workspace.fs.stat(uri);
|
||||
if ((stat.type & vscode.FileType.Directory) === vscode.FileType.Directory) {
|
||||
await this.projectService.importAircraftFromExistingFolder(projectId, parts[0]);
|
||||
@@ -1588,7 +1576,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
};
|
||||
// 4. 绑定事件 (防抖建议设为 500ms 左右)
|
||||
// 绑定事件 (防抖建议设为 500ms 左右)
|
||||
const debouncedCreate = debounce(handleCreate, 500);
|
||||
const debouncedDelete = debounce(handleDelete, 500);
|
||||
this.fileWatcher.onDidCreate(uri => debouncedCreate(uri));
|
||||
@@ -1608,6 +1596,9 @@ class ConfigPanel {
|
||||
}
|
||||
catch (error) { }
|
||||
}
|
||||
getRepoConfigsForScope(scope) {
|
||||
return (this.repoConfigs || []).filter(r => Array.isArray(r.scopes) && r.scopes.includes(scope));
|
||||
}
|
||||
getWebviewContent() {
|
||||
switch (this.currentView) {
|
||||
case 'projects':
|
||||
@@ -1615,12 +1606,18 @@ class ConfigPanel {
|
||||
projects: this.projectService.getProjects(),
|
||||
projectPaths: this.projectService.getProjectPaths()
|
||||
});
|
||||
case 'aircrafts':
|
||||
const projectAircrafts = this.projectService.getAircraftsByProject(this.currentProjectId);
|
||||
case 'aircrafts': {
|
||||
const project = this.projectService.getProjects()
|
||||
.find(p => p.id === this.currentProjectId);
|
||||
const projectAircrafts = this.projectService
|
||||
.getAircraftsByProject(this.currentProjectId)
|
||||
.filter(a => a.name !== '.git');
|
||||
return this.aircraftView.render({
|
||||
project: project,
|
||||
aircrafts: projectAircrafts
|
||||
});
|
||||
case 'containers':
|
||||
}
|
||||
case 'containers': {
|
||||
const project = this.projectService.getProjects().find(p => p.id === this.currentProjectId);
|
||||
const currentAircraft = this.projectService.getAircraftsByProject(this.currentProjectId)
|
||||
.find(a => a.id === this.currentAircraftId);
|
||||
@@ -1632,7 +1629,8 @@ class ConfigPanel {
|
||||
aircraft: currentAircraft,
|
||||
containers: projectContainers
|
||||
});
|
||||
case 'configs':
|
||||
}
|
||||
case 'configs': {
|
||||
const currentContainer = this.projectService.getContainersByAircraft(this.currentAircraftId)
|
||||
.find(c => c.id === this.currentContainerId);
|
||||
const currentModuleFolder = this.projectService.getModuleFolder(this.currentModuleFolderId);
|
||||
@@ -1646,6 +1644,7 @@ class ConfigPanel {
|
||||
moduleFolderFileTree: this.currentModuleFolderFileTree,
|
||||
moduleFolderLoading: false
|
||||
});
|
||||
}
|
||||
default:
|
||||
return this.projectView.render({
|
||||
projects: this.projectService.getProjects(),
|
||||
|
||||
Reference in New Issue
Block a user