新增git分支显示功能
This commit is contained in:
@@ -1086,9 +1086,8 @@ class ConfigPanel {
|
|||||||
console.log('🌿 过滤后的分支引用:', branchRefs);
|
console.log('🌿 过滤后的分支引用:', branchRefs);
|
||||||
// 构建分支数据 - 修复分支名称显示
|
// 构建分支数据 - 修复分支名称显示
|
||||||
const branches = branchRefs.map(ref => {
|
const branches = branchRefs.map(ref => {
|
||||||
const isRemote = ref.ref.startsWith('refs/remotes/');
|
|
||||||
let branchName;
|
let branchName;
|
||||||
if (isRemote) {
|
if (ref.ref.startsWith('refs/remotes/')) {
|
||||||
// 远程分支:移除 refs/remotes/origin/ 前缀
|
// 远程分支:移除 refs/remotes/origin/ 前缀
|
||||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||||
}
|
}
|
||||||
@@ -1099,7 +1098,6 @@ class ConfigPanel {
|
|||||||
return {
|
return {
|
||||||
name: branchName,
|
name: branchName,
|
||||||
isCurrent: branchName === 'main' || branchName === 'master',
|
isCurrent: branchName === 'main' || branchName === 'master',
|
||||||
isRemote: isRemote,
|
|
||||||
selected: false // 所有分支默认不选中
|
selected: false // 所有分支默认不选中
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -1108,11 +1106,15 @@ class ConfigPanel {
|
|||||||
throw new Error('未找到任何分支');
|
throw new Error('未找到任何分支');
|
||||||
}
|
}
|
||||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||||
// 发送分支数据到前端
|
// === 新增:构建分支树状结构 ===
|
||||||
|
const branchTree = this.buildBranchTree(branches);
|
||||||
|
console.log('🌳 构建的分支树结构:', branchTree);
|
||||||
|
// 发送分支数据到前端 - 同时包含扁平列表和树状结构
|
||||||
if (!this.isWebviewDisposed) {
|
if (!this.isWebviewDisposed) {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'branchesFetched',
|
type: 'branchesFetched',
|
||||||
branches: branches,
|
branches: branches,
|
||||||
|
branchTree: branchTree,
|
||||||
repoUrl: url
|
repoUrl: url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1130,6 +1132,39 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 构建分支树状结构
|
||||||
|
*/
|
||||||
|
buildBranchTree(branches) {
|
||||||
|
const root = [];
|
||||||
|
branches.forEach(branch => {
|
||||||
|
const parts = branch.name.split('/');
|
||||||
|
let currentLevel = root;
|
||||||
|
for (let i = 0; i < parts.length; i++) {
|
||||||
|
const part = parts[i];
|
||||||
|
const isLeaf = i === parts.length - 1;
|
||||||
|
const fullName = parts.slice(0, i + 1).join('/');
|
||||||
|
let node = currentLevel.find((n) => n.name === part);
|
||||||
|
if (!node) {
|
||||||
|
node = {
|
||||||
|
name: part,
|
||||||
|
fullName: fullName,
|
||||||
|
isLeaf: isLeaf,
|
||||||
|
children: [],
|
||||||
|
level: i,
|
||||||
|
expanded: true // 默认展开
|
||||||
|
};
|
||||||
|
currentLevel.push(node);
|
||||||
|
}
|
||||||
|
if (isLeaf) {
|
||||||
|
// 叶子节点存储分支信息
|
||||||
|
node.branch = branch;
|
||||||
|
}
|
||||||
|
currentLevel = node.children;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return root;
|
||||||
|
}
|
||||||
async cloneBranches(url, branches) {
|
async cloneBranches(url, branches) {
|
||||||
try {
|
try {
|
||||||
console.log('🚀 开始克隆分支:', { url, branches });
|
console.log('🚀 开始克隆分支:', { url, branches });
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -49,8 +49,8 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
// 生成分支选择的 HTML
|
// 生成分支选择的 HTML - 使用树状结构
|
||||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
|
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
@@ -93,6 +93,65 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
background: var(--vscode-inputValidation-errorBackground);
|
background: var(--vscode-inputValidation-errorBackground);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 树状分支样式 */
|
||||||
|
.branch-tree {
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
user-select: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.branch-node {
|
||||||
|
padding: 2px 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
.branch-node:hover {
|
||||||
|
background: var(--vscode-list-hoverBackground);
|
||||||
|
}
|
||||||
|
.branch-icon {
|
||||||
|
margin-right: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.branch-expand {
|
||||||
|
margin-right: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 14px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.branch-checkbox {
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
.branch-name {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.branch-children {
|
||||||
|
margin-left: 16px;
|
||||||
|
border-left: 1px solid var(--vscode-panel-border);
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
.branch-leaf {
|
||||||
|
margin-left: 16px;
|
||||||
|
}
|
||||||
|
.current-branch {
|
||||||
|
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 树图标样式 */
|
||||||
|
.tree-icon {
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 分支树标题样式 */
|
||||||
|
.branch-tree-title {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -150,6 +209,7 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
let currentConfigId = null;
|
let currentConfigId = null;
|
||||||
let selectedBranches = new Set();
|
let selectedBranches = new Set();
|
||||||
let currentRepoUrl = '';
|
let currentRepoUrl = '';
|
||||||
|
let branchTreeData = [];
|
||||||
|
|
||||||
// 配置管理功能
|
// 配置管理功能
|
||||||
function editConfigName(configId, currentName) {
|
function editConfigName(configId, currentName) {
|
||||||
@@ -271,7 +331,7 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggleBranch(branchName) {
|
function toggleBranch(branchName) {
|
||||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9]/g, '-'));
|
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
selectedBranches.add(branchName);
|
selectedBranches.add(branchName);
|
||||||
} else {
|
} else {
|
||||||
@@ -332,35 +392,124 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态渲染分支选择区域
|
// 树状分支功能
|
||||||
function renderBranchSelection(branches, repoUrl) {
|
function toggleBranchNode(nodeId) {
|
||||||
|
const node = findNodeById(branchTreeData, nodeId);
|
||||||
|
if (node && !node.isLeaf) {
|
||||||
|
node.expanded = !node.expanded;
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandAllBranches() {
|
||||||
|
setAllExpanded(branchTreeData, true);
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function collapseAllBranches() {
|
||||||
|
setAllExpanded(branchTreeData, false);
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAllExpanded(nodes, expanded) {
|
||||||
|
nodes.forEach(node => {
|
||||||
|
if (!node.isLeaf) {
|
||||||
|
node.expanded = expanded;
|
||||||
|
if (node.children) {
|
||||||
|
setAllExpanded(node.children, expanded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function findNodeById(nodes, nodeId) {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.fullName === nodeId) return node;
|
||||||
|
if (node.children) {
|
||||||
|
const found = findNodeById(node.children, nodeId);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态渲染树状分支
|
||||||
|
function renderBranchTree(treeData) {
|
||||||
const container = document.getElementById('branchSelectionContainer');
|
const container = document.getElementById('branchSelectionContainer');
|
||||||
|
|
||||||
if (branches.length === 0) {
|
if (!treeData || treeData.length === 0) {
|
||||||
container.innerHTML = '<div style="text-align: center; padding: 10px; color: var(--vscode-descriptionForeground);">未找到分支</div>';
|
container.innerHTML = '<div style="text-align: center; padding: 10px; color: var(--vscode-descriptionForeground);">未找到分支</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let branchesHtml = '<div class="branch-selection" style="margin: 15px 0; padding: 15px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
let html = '<div class="branch-selection" style="margin: 10px 0; padding: 10px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
||||||
branchesHtml += '<h4>🌿 选择要克隆的分支 (共 ' + branches.length + ' 个)</h4>';
|
html += '<h4 class="branch-tree-title" style="margin: 0 0 8px 0;"><span class="tree-icon">🌳</span> 分支树</h4>';
|
||||||
branchesHtml += '<div style="max-height: 200px; overflow-y: auto; margin: 10px 0;">';
|
|
||||||
|
|
||||||
branches.forEach(branch => {
|
// 展开/收起按钮
|
||||||
branchesHtml += '<div class="branch-item" style="padding: 8px; border-bottom: 1px solid var(--vscode-panel-border); display: flex; align-items: center;">';
|
html += '<div style="margin-bottom: 8px;">';
|
||||||
branchesHtml += '<input type="checkbox" id="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" ';
|
html += '<button class="back-btn" onclick="expandAllBranches()" style="margin-right: 8px; padding: 2px 6px; font-size: 11px;">展开全部</button>';
|
||||||
branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">';
|
html += '<button class="back-btn" onclick="collapseAllBranches()" style="padding: 2px 6px; font-size: 11px;">收起全部</button>';
|
||||||
branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">';
|
html += '</div>';
|
||||||
branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name;
|
|
||||||
branchesHtml += '</label></div>';
|
html += '<div class="branch-tree">';
|
||||||
|
html += renderBranchNodes(treeData, 0);
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
html += '<div style="margin-top: 12px;">';
|
||||||
|
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 8px; padding: 4px 8px; font-size: 12px;">✅ 克隆选中分支</button>';
|
||||||
|
html += '<button class="back-btn" onclick="cancelBranchSelection()" style="padding: 4px 8px; font-size: 12px;">取消</button>';
|
||||||
|
html += '</div></div>';
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBranchNodes(nodes, level) {
|
||||||
|
let html = '';
|
||||||
|
nodes.forEach(node => {
|
||||||
|
const indent = level * 20;
|
||||||
|
const nodeId = node.fullName.replace(/[^a-zA-Z0-9-]/g, '-');
|
||||||
|
|
||||||
|
if (node.isLeaf) {
|
||||||
|
// 叶子节点(实际分支)
|
||||||
|
html += '<div class="branch-node branch-leaf" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<input type="checkbox" id="branch-' + nodeId + '" class="branch-checkbox" ';
|
||||||
|
html += (node.branch && node.branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + node.fullName + '\\')">';
|
||||||
|
html += '<span class="branch-icon">🌿</span>';
|
||||||
|
html += '<span class="branch-name ' + (node.branch && node.branch.isCurrent ? 'current-branch' : '') + '">';
|
||||||
|
html += node.name;
|
||||||
|
html += (node.branch && node.branch.isCurrent ? ' ⭐' : '');
|
||||||
|
html += '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
} else {
|
||||||
|
// 文件夹节点
|
||||||
|
html += '<div class="branch-node" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<span class="branch-expand" onclick="toggleBranchNode(\\'' + node.fullName + '\\')">';
|
||||||
|
html += (node.expanded ? '🪵' : '🪵');
|
||||||
|
html += '</span>';
|
||||||
|
html += '<span class="branch-icon">🪵</span>';
|
||||||
|
html += '<span class="branch-name">' + node.name + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
if (node.expanded && node.children) {
|
||||||
|
html += '<div class="branch-children">';
|
||||||
|
html += renderBranchNodes(node.children, level + 1);
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
return html;
|
||||||
branchesHtml += '</div>';
|
}
|
||||||
branchesHtml += '<div style="margin-top: 15px;">';
|
|
||||||
branchesHtml += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 10px;">✅ 克隆选中分支</button>';
|
function countLeafNodes(nodes) {
|
||||||
branchesHtml += '<button class="back-btn" onclick="cancelBranchSelection()">取消</button>';
|
let count = 0;
|
||||||
branchesHtml += '</div></div>';
|
nodes.forEach(node => {
|
||||||
|
if (node.isLeaf) {
|
||||||
container.innerHTML = branchesHtml;
|
count++;
|
||||||
|
} else if (node.children) {
|
||||||
|
count += countLeafNodes(node.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对话框函数
|
// 对话框函数
|
||||||
@@ -450,7 +599,9 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
|
|
||||||
if (message.type === 'branchesFetched') {
|
if (message.type === 'branchesFetched') {
|
||||||
console.log('🌿 收到分支数据:', message.branches);
|
console.log('🌿 收到分支数据:', message.branches);
|
||||||
renderBranchSelection(message.branches, message.repoUrl);
|
console.log('🌳 收到分支树数据:', message.branchTree);
|
||||||
|
branchTreeData = message.branchTree || [];
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -462,27 +613,113 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
generateBranchesHtml(branches) {
|
generateBranchesTreeHtml(branches) {
|
||||||
if (branches.length === 0)
|
if (branches.length === 0)
|
||||||
return '';
|
return '';
|
||||||
let html = '<div class="branch-selection" style="margin: 15px 0; padding: 15px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
// 构建分支树
|
||||||
html += '<h4>🌿 选择要克隆的分支 (共 ' + branches.length + ' 个)</h4>';
|
const branchTree = this.buildBranchTree(branches);
|
||||||
html += '<div style="max-height: 200px; overflow-y: auto; margin: 10px 0;">';
|
let html = '<div class="branch-selection" style="margin: 10px 0; padding: 10px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
||||||
branches.forEach(branch => {
|
html += '<h4 class="branch-tree-title" style="margin: 0 0 8px 0;"><span class="tree-icon">🌳</span> 分支树</h4>';
|
||||||
const branchId = 'branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-');
|
html += '<div style="margin-bottom: 8px;">';
|
||||||
html += '<div class="branch-item" style="padding: 8px; border-bottom: 1px solid var(--vscode-panel-border); display: flex; align-items: center;">';
|
html += '<button class="back-btn" onclick="expandAllBranches()" style="margin-right: 8px; padding: 2px 6px; font-size: 11px;">展开全部</button>';
|
||||||
html += '<input type="checkbox" id="' + branchId + '" ';
|
html += '<button class="back-btn" onclick="collapseAllBranches()" style="padding: 2px 6px; font-size: 11px;">收起全部</button>';
|
||||||
html += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\'' + branch.name + '\')" style="margin-right: 10px;">';
|
html += '</div>';
|
||||||
html += '<label for="' + branchId + '" style="flex: 1; cursor: pointer;">';
|
html += '<div class="branch-tree">';
|
||||||
html += (branch.isCurrent ? '⭐ ' : '') + branch.name;
|
html += this.renderBranchTreeNodes(branchTree, 0);
|
||||||
html += (branch.isRemote ? '(远程)' : '(本地)') + '</label></div>';
|
html += '</div>';
|
||||||
});
|
html += '<div style="margin-top: 12px;">';
|
||||||
html += '<div style="margin-top: 15px;">';
|
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 8px; padding: 4px 8px; font-size: 12px;">✅ 克隆选中分支</button>';
|
||||||
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 10px;">✅ 克隆选中分支</button>';
|
html += '<button class="back-btn" onclick="cancelBranchSelection()" style="padding: 4px 8px; font-size: 12px;">取消</button>';
|
||||||
html += '<button class="back-btn" onclick="cancelBranchSelection()">取消</button>';
|
|
||||||
html += '</div></div>';
|
html += '</div></div>';
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 构建分支树状结构
|
||||||
|
*/
|
||||||
|
buildBranchTree(branches) {
|
||||||
|
const root = [];
|
||||||
|
branches.forEach(branch => {
|
||||||
|
const parts = branch.name.split('/');
|
||||||
|
let currentLevel = root;
|
||||||
|
for (let i = 0; i < parts.length; i++) {
|
||||||
|
const part = parts[i];
|
||||||
|
const isLeaf = i === parts.length - 1;
|
||||||
|
const fullName = parts.slice(0, i + 1).join('/');
|
||||||
|
let node = currentLevel.find(n => n.name === part);
|
||||||
|
if (!node) {
|
||||||
|
node = {
|
||||||
|
name: part,
|
||||||
|
fullName: fullName,
|
||||||
|
isLeaf: isLeaf,
|
||||||
|
children: [],
|
||||||
|
level: i
|
||||||
|
};
|
||||||
|
currentLevel.push(node);
|
||||||
|
}
|
||||||
|
if (isLeaf) {
|
||||||
|
node.branch = branch;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.expanded = node.expanded || true; // 默认展开
|
||||||
|
}
|
||||||
|
currentLevel = node.children;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 渲染分支树节点
|
||||||
|
*/
|
||||||
|
renderBranchTreeNodes(nodes, level) {
|
||||||
|
let html = '';
|
||||||
|
nodes.forEach(node => {
|
||||||
|
const indent = level * 20;
|
||||||
|
const nodeId = node.fullName.replace(/[^a-zA-Z0-9-]/g, '-');
|
||||||
|
if (node.isLeaf) {
|
||||||
|
// 叶子节点(实际分支)
|
||||||
|
html += '<div class="branch-node branch-leaf" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<input type="checkbox" id="branch-' + nodeId + '" class="branch-checkbox" ';
|
||||||
|
html += (node.branch && node.branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\'' + node.fullName + '\')">';
|
||||||
|
html += '<span class="branch-icon">🌿</span>';
|
||||||
|
html += '<span class="branch-name ' + (node.branch && node.branch.isCurrent ? 'current-branch' : '') + '">';
|
||||||
|
html += node.name;
|
||||||
|
html += (node.branch && node.branch.isCurrent ? ' ⭐' : '');
|
||||||
|
html += '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 文件夹节点
|
||||||
|
html += '<div class="branch-node" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<span class="branch-expand" onclick="toggleBranchNode(\'' + node.fullName + '\')">';
|
||||||
|
html += (node.expanded ? '🪵' : '🪵');
|
||||||
|
html += '</span>';
|
||||||
|
html += '<span class="branch-icon">🪵</span>';
|
||||||
|
html += '<span class="branch-name">' + node.name + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
if (node.expanded && node.children && node.children.length > 0) {
|
||||||
|
html += '<div class="branch-children">';
|
||||||
|
html += this.renderBranchTreeNodes(node.children, level + 1);
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 计算叶子节点数量
|
||||||
|
*/
|
||||||
|
countLeafNodes(nodes) {
|
||||||
|
let count = 0;
|
||||||
|
nodes.forEach(node => {
|
||||||
|
if (node.isLeaf) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count += this.countLeafNodes(node.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.ConfigView = ConfigView;
|
exports.ConfigView = ConfigView;
|
||||||
//# sourceMappingURL=ConfigView.js.map
|
//# sourceMappingURL=ConfigView.js.map
|
||||||
File diff suppressed because one or more lines are too long
@@ -64,7 +64,6 @@ interface ProjectData {
|
|||||||
interface GitBranch {
|
interface GitBranch {
|
||||||
name: string;
|
name: string;
|
||||||
isCurrent: boolean;
|
isCurrent: boolean;
|
||||||
isRemote: boolean;
|
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,89 +1299,133 @@ export class ConfigPanel {
|
|||||||
// === Git 分支管理 ===
|
// === Git 分支管理 ===
|
||||||
|
|
||||||
private async fetchBranches(url: string): Promise<void> {
|
private async fetchBranches(url: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('🌿 开始获取分支列表:', url);
|
console.log('🌿 开始获取分支列表:', url);
|
||||||
|
|
||||||
await vscode.window.withProgress({
|
await vscode.window.withProgress({
|
||||||
location: vscode.ProgressLocation.Notification,
|
location: vscode.ProgressLocation.Notification,
|
||||||
title: '正在获取分支信息',
|
title: '正在获取分支信息',
|
||||||
cancellable: false
|
cancellable: false
|
||||||
}, async (progress) => {
|
}, async (progress) => {
|
||||||
progress.report({ increment: 0, message: '连接远程仓库...' });
|
progress.report({ increment: 0, message: '连接远程仓库...' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 使用 isomorphic-git 的 listServerRefs
|
// 使用 isomorphic-git 的 listServerRefs
|
||||||
progress.report({ increment: 30, message: '获取远程引用...' });
|
progress.report({ increment: 30, message: '获取远程引用...' });
|
||||||
|
|
||||||
|
console.log('🔍 使用 listServerRefs 获取分支信息...');
|
||||||
|
|
||||||
|
const refs = await git.listServerRefs({
|
||||||
|
http: http,
|
||||||
|
url: url
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('📋 获取到的引用:', refs);
|
||||||
|
|
||||||
|
// 过滤出分支引用 (refs/heads/ 和 refs/remotes/origin/)
|
||||||
|
const branchRefs = refs.filter(ref =>
|
||||||
|
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('🌿 过滤后的分支引用:', branchRefs);
|
||||||
|
|
||||||
|
// 构建分支数据 - 修复分支名称显示
|
||||||
|
const branches: GitBranch[] = branchRefs.map(ref => {
|
||||||
|
let branchName: string;
|
||||||
|
|
||||||
console.log('🔍 使用 listServerRefs 获取分支信息...');
|
if (ref.ref.startsWith('refs/remotes/')) {
|
||||||
|
// 远程分支:移除 refs/remotes/origin/ 前缀
|
||||||
const refs = await git.listServerRefs({
|
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||||
http: http,
|
} else {
|
||||||
url: url
|
// 本地分支:移除 refs/heads/ 前缀
|
||||||
});
|
branchName = ref.ref.replace('refs/heads/', '');
|
||||||
|
|
||||||
console.log('📋 获取到的引用:', refs);
|
|
||||||
|
|
||||||
// 过滤出分支引用 (refs/heads/ 和 refs/remotes/origin/)
|
|
||||||
const branchRefs = refs.filter(ref =>
|
|
||||||
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('🌿 过滤后的分支引用:', branchRefs);
|
|
||||||
|
|
||||||
// 构建分支数据 - 修复分支名称显示
|
|
||||||
const branches: GitBranch[] = branchRefs.map(ref => {
|
|
||||||
const isRemote = ref.ref.startsWith('refs/remotes/');
|
|
||||||
let branchName: string;
|
|
||||||
|
|
||||||
if (isRemote) {
|
|
||||||
// 远程分支:移除 refs/remotes/origin/ 前缀
|
|
||||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
|
||||||
} else {
|
|
||||||
// 本地分支:移除 refs/heads/ 前缀
|
|
||||||
branchName = ref.ref.replace('refs/heads/', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: branchName,
|
|
||||||
isCurrent: branchName === 'main' || branchName === 'master',
|
|
||||||
isRemote: isRemote,
|
|
||||||
selected: false // 所有分支默认不选中
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('🎯 最终分支列表:', branches);
|
|
||||||
|
|
||||||
if (branches.length === 0) {
|
|
||||||
throw new Error('未找到任何分支');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
|
||||||
|
|
||||||
// 发送分支数据到前端
|
|
||||||
if (!this.isWebviewDisposed) {
|
|
||||||
this.panel.webview.postMessage({
|
|
||||||
type: 'branchesFetched',
|
|
||||||
branches: branches,
|
|
||||||
repoUrl: url
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
progress.report({ increment: 100, message: '完成' });
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ 使用 listServerRefs 获取分支失败:', error);
|
|
||||||
|
|
||||||
// 只在右下角显示分支获取失败的通知,不模拟分支数据
|
return {
|
||||||
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
name: branchName,
|
||||||
|
isCurrent: branchName === 'main' || branchName === 'master',
|
||||||
|
selected: false // 所有分支默认不选中
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('🎯 最终分支列表:', branches);
|
||||||
|
|
||||||
|
if (branches.length === 0) {
|
||||||
|
throw new Error('未找到任何分支');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||||
console.error('❌ 获取分支失败:', error);
|
|
||||||
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
// === 新增:构建分支树状结构 ===
|
||||||
}
|
const branchTree = this.buildBranchTree(branches);
|
||||||
|
console.log('🌳 构建的分支树结构:', branchTree);
|
||||||
|
|
||||||
|
// 发送分支数据到前端 - 同时包含扁平列表和树状结构
|
||||||
|
if (!this.isWebviewDisposed) {
|
||||||
|
this.panel.webview.postMessage({
|
||||||
|
type: 'branchesFetched',
|
||||||
|
branches: branches,
|
||||||
|
branchTree: branchTree, // 新增树状结构数据
|
||||||
|
repoUrl: url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.report({ increment: 100, message: '完成' });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 使用 listServerRefs 获取分支失败:', error);
|
||||||
|
|
||||||
|
// 只在右下角显示分支获取失败的通知,不模拟分支数据
|
||||||
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 获取分支失败:', error);
|
||||||
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建分支树状结构
|
||||||
|
*/
|
||||||
|
private buildBranchTree(branches: GitBranch[]): any[] {
|
||||||
|
const root: any[] = [];
|
||||||
|
|
||||||
|
branches.forEach(branch => {
|
||||||
|
const parts = branch.name.split('/');
|
||||||
|
let currentLevel = root;
|
||||||
|
|
||||||
|
for (let i = 0; i < parts.length; i++) {
|
||||||
|
const part = parts[i];
|
||||||
|
const isLeaf = i === parts.length - 1;
|
||||||
|
const fullName = parts.slice(0, i + 1).join('/');
|
||||||
|
|
||||||
|
let node = currentLevel.find((n: any) => n.name === part);
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
node = {
|
||||||
|
name: part,
|
||||||
|
fullName: fullName,
|
||||||
|
isLeaf: isLeaf,
|
||||||
|
children: [],
|
||||||
|
level: i,
|
||||||
|
expanded: true // 默认展开
|
||||||
|
};
|
||||||
|
currentLevel.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLeaf) {
|
||||||
|
// 叶子节点存储分支信息
|
||||||
|
node.branch = branch;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLevel = node.children;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
private async cloneBranches(url: string, branches: string[]): Promise<void> {
|
private async cloneBranches(url: string, branches: string[]): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -5,10 +5,19 @@ import { ContainerConfigData, ConfigViewData } from '../types/ViewTypes';
|
|||||||
interface GitBranch {
|
interface GitBranch {
|
||||||
name: string;
|
name: string;
|
||||||
isCurrent: boolean;
|
isCurrent: boolean;
|
||||||
isRemote: boolean;
|
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BranchTreeNode {
|
||||||
|
name: string;
|
||||||
|
fullName: string;
|
||||||
|
isLeaf: boolean;
|
||||||
|
children: BranchTreeNode[];
|
||||||
|
level: number;
|
||||||
|
expanded?: boolean;
|
||||||
|
branch?: GitBranch;
|
||||||
|
}
|
||||||
|
|
||||||
// Git 文件树接口
|
// Git 文件树接口
|
||||||
interface GitFileTree {
|
interface GitFileTree {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -28,6 +37,17 @@ interface GitRepo {
|
|||||||
containerId: string;
|
containerId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 树状分支节点接口
|
||||||
|
interface BranchTreeNode {
|
||||||
|
name: string;
|
||||||
|
fullName: string;
|
||||||
|
isLeaf: boolean;
|
||||||
|
children: BranchTreeNode[];
|
||||||
|
level: number;
|
||||||
|
expanded?: boolean;
|
||||||
|
branch?: GitBranch;
|
||||||
|
}
|
||||||
|
|
||||||
export class ConfigView extends BaseView {
|
export class ConfigView extends BaseView {
|
||||||
render(data?: ContainerConfigData & {
|
render(data?: ContainerConfigData & {
|
||||||
gitRepos?: GitRepo[];
|
gitRepos?: GitRepo[];
|
||||||
@@ -86,8 +106,8 @@ export class ConfigView extends BaseView {
|
|||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
// 生成分支选择的 HTML
|
// 生成分支选择的 HTML - 使用树状结构
|
||||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
|
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
@@ -131,6 +151,65 @@ export class ConfigView extends BaseView {
|
|||||||
background: var(--vscode-inputValidation-errorBackground);
|
background: var(--vscode-inputValidation-errorBackground);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 树状分支样式 */
|
||||||
|
.branch-tree {
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
user-select: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.branch-node {
|
||||||
|
padding: 2px 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
.branch-node:hover {
|
||||||
|
background: var(--vscode-list-hoverBackground);
|
||||||
|
}
|
||||||
|
.branch-icon {
|
||||||
|
margin-right: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.branch-expand {
|
||||||
|
margin-right: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 14px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.branch-checkbox {
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
.branch-name {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.branch-children {
|
||||||
|
margin-left: 16px;
|
||||||
|
border-left: 1px solid var(--vscode-panel-border);
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
.branch-leaf {
|
||||||
|
margin-left: 16px;
|
||||||
|
}
|
||||||
|
.current-branch {
|
||||||
|
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 树图标样式 */
|
||||||
|
.tree-icon {
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 分支树标题样式 */
|
||||||
|
.branch-tree-title {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -188,6 +267,7 @@ export class ConfigView extends BaseView {
|
|||||||
let currentConfigId = null;
|
let currentConfigId = null;
|
||||||
let selectedBranches = new Set();
|
let selectedBranches = new Set();
|
||||||
let currentRepoUrl = '';
|
let currentRepoUrl = '';
|
||||||
|
let branchTreeData = [];
|
||||||
|
|
||||||
// 配置管理功能
|
// 配置管理功能
|
||||||
function editConfigName(configId, currentName) {
|
function editConfigName(configId, currentName) {
|
||||||
@@ -309,7 +389,7 @@ export class ConfigView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggleBranch(branchName) {
|
function toggleBranch(branchName) {
|
||||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9]/g, '-'));
|
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
selectedBranches.add(branchName);
|
selectedBranches.add(branchName);
|
||||||
} else {
|
} else {
|
||||||
@@ -370,35 +450,124 @@ export class ConfigView extends BaseView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态渲染分支选择区域
|
// 树状分支功能
|
||||||
function renderBranchSelection(branches, repoUrl) {
|
function toggleBranchNode(nodeId) {
|
||||||
|
const node = findNodeById(branchTreeData, nodeId);
|
||||||
|
if (node && !node.isLeaf) {
|
||||||
|
node.expanded = !node.expanded;
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandAllBranches() {
|
||||||
|
setAllExpanded(branchTreeData, true);
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function collapseAllBranches() {
|
||||||
|
setAllExpanded(branchTreeData, false);
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAllExpanded(nodes, expanded) {
|
||||||
|
nodes.forEach(node => {
|
||||||
|
if (!node.isLeaf) {
|
||||||
|
node.expanded = expanded;
|
||||||
|
if (node.children) {
|
||||||
|
setAllExpanded(node.children, expanded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function findNodeById(nodes, nodeId) {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.fullName === nodeId) return node;
|
||||||
|
if (node.children) {
|
||||||
|
const found = findNodeById(node.children, nodeId);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态渲染树状分支
|
||||||
|
function renderBranchTree(treeData) {
|
||||||
const container = document.getElementById('branchSelectionContainer');
|
const container = document.getElementById('branchSelectionContainer');
|
||||||
|
|
||||||
if (branches.length === 0) {
|
if (!treeData || treeData.length === 0) {
|
||||||
container.innerHTML = '<div style="text-align: center; padding: 10px; color: var(--vscode-descriptionForeground);">未找到分支</div>';
|
container.innerHTML = '<div style="text-align: center; padding: 10px; color: var(--vscode-descriptionForeground);">未找到分支</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let branchesHtml = '<div class="branch-selection" style="margin: 15px 0; padding: 15px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
let html = '<div class="branch-selection" style="margin: 10px 0; padding: 10px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
||||||
branchesHtml += '<h4>🌿 选择要克隆的分支 (共 ' + branches.length + ' 个)</h4>';
|
html += '<h4 class="branch-tree-title" style="margin: 0 0 8px 0;"><span class="tree-icon">🌳</span> 分支树</h4>';
|
||||||
branchesHtml += '<div style="max-height: 200px; overflow-y: auto; margin: 10px 0;">';
|
|
||||||
|
|
||||||
branches.forEach(branch => {
|
// 展开/收起按钮
|
||||||
branchesHtml += '<div class="branch-item" style="padding: 8px; border-bottom: 1px solid var(--vscode-panel-border); display: flex; align-items: center;">';
|
html += '<div style="margin-bottom: 8px;">';
|
||||||
branchesHtml += '<input type="checkbox" id="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" ';
|
html += '<button class="back-btn" onclick="expandAllBranches()" style="margin-right: 8px; padding: 2px 6px; font-size: 11px;">展开全部</button>';
|
||||||
branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">';
|
html += '<button class="back-btn" onclick="collapseAllBranches()" style="padding: 2px 6px; font-size: 11px;">收起全部</button>';
|
||||||
branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">';
|
html += '</div>';
|
||||||
branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name;
|
|
||||||
branchesHtml += '</label></div>';
|
html += '<div class="branch-tree">';
|
||||||
|
html += renderBranchNodes(treeData, 0);
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
html += '<div style="margin-top: 12px;">';
|
||||||
|
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 8px; padding: 4px 8px; font-size: 12px;">✅ 克隆选中分支</button>';
|
||||||
|
html += '<button class="back-btn" onclick="cancelBranchSelection()" style="padding: 4px 8px; font-size: 12px;">取消</button>';
|
||||||
|
html += '</div></div>';
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBranchNodes(nodes, level) {
|
||||||
|
let html = '';
|
||||||
|
nodes.forEach(node => {
|
||||||
|
const indent = level * 20;
|
||||||
|
const nodeId = node.fullName.replace(/[^a-zA-Z0-9-]/g, '-');
|
||||||
|
|
||||||
|
if (node.isLeaf) {
|
||||||
|
// 叶子节点(实际分支)
|
||||||
|
html += '<div class="branch-node branch-leaf" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<input type="checkbox" id="branch-' + nodeId + '" class="branch-checkbox" ';
|
||||||
|
html += (node.branch && node.branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + node.fullName + '\\')">';
|
||||||
|
html += '<span class="branch-icon">🌿</span>';
|
||||||
|
html += '<span class="branch-name ' + (node.branch && node.branch.isCurrent ? 'current-branch' : '') + '">';
|
||||||
|
html += node.name;
|
||||||
|
html += (node.branch && node.branch.isCurrent ? ' ⭐' : '');
|
||||||
|
html += '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
} else {
|
||||||
|
// 文件夹节点
|
||||||
|
html += '<div class="branch-node" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<span class="branch-expand" onclick="toggleBranchNode(\\'' + node.fullName + '\\')">';
|
||||||
|
html += (node.expanded ? '🪵' : '🪵');
|
||||||
|
html += '</span>';
|
||||||
|
html += '<span class="branch-icon">🪵</span>';
|
||||||
|
html += '<span class="branch-name">' + node.name + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
if (node.expanded && node.children) {
|
||||||
|
html += '<div class="branch-children">';
|
||||||
|
html += renderBranchNodes(node.children, level + 1);
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
return html;
|
||||||
branchesHtml += '</div>';
|
}
|
||||||
branchesHtml += '<div style="margin-top: 15px;">';
|
|
||||||
branchesHtml += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 10px;">✅ 克隆选中分支</button>';
|
function countLeafNodes(nodes) {
|
||||||
branchesHtml += '<button class="back-btn" onclick="cancelBranchSelection()">取消</button>';
|
let count = 0;
|
||||||
branchesHtml += '</div></div>';
|
nodes.forEach(node => {
|
||||||
|
if (node.isLeaf) {
|
||||||
container.innerHTML = branchesHtml;
|
count++;
|
||||||
|
} else if (node.children) {
|
||||||
|
count += countLeafNodes(node.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对话框函数
|
// 对话框函数
|
||||||
@@ -488,7 +657,9 @@ export class ConfigView extends BaseView {
|
|||||||
|
|
||||||
if (message.type === 'branchesFetched') {
|
if (message.type === 'branchesFetched') {
|
||||||
console.log('🌿 收到分支数据:', message.branches);
|
console.log('🌿 收到分支数据:', message.branches);
|
||||||
renderBranchSelection(message.branches, message.repoUrl);
|
console.log('🌳 收到分支树数据:', message.branchTree);
|
||||||
|
branchTreeData = message.branchTree || [];
|
||||||
|
renderBranchTree(branchTreeData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -501,28 +672,124 @@ export class ConfigView extends BaseView {
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateBranchesHtml(branches: GitBranch[]): string {
|
private generateBranchesTreeHtml(branches: GitBranch[]): string {
|
||||||
if (branches.length === 0) return '';
|
if (branches.length === 0) return '';
|
||||||
|
|
||||||
let html = '<div class="branch-selection" style="margin: 15px 0; padding: 15px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
// 构建分支树
|
||||||
html += '<h4>🌿 选择要克隆的分支 (共 ' + branches.length + ' 个)</h4>';
|
const branchTree = this.buildBranchTree(branches);
|
||||||
html += '<div style="max-height: 200px; overflow-y: auto; margin: 10px 0;">';
|
|
||||||
|
|
||||||
branches.forEach(branch => {
|
let html = '<div class="branch-selection" style="margin: 10px 0; padding: 10px; background: var(--vscode-panel-background); border-radius: 4px;">';
|
||||||
const branchId = 'branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-');
|
html += '<h4 class="branch-tree-title" style="margin: 0 0 8px 0;"><span class="tree-icon">🌳</span> 分支树</h4>';
|
||||||
html += '<div class="branch-item" style="padding: 8px; border-bottom: 1px solid var(--vscode-panel-border); display: flex; align-items: center;">';
|
html += '<div style="margin-bottom: 8px;">';
|
||||||
html += '<input type="checkbox" id="' + branchId + '" ';
|
html += '<button class="back-btn" onclick="expandAllBranches()" style="margin-right: 8px; padding: 2px 6px; font-size: 11px;">展开全部</button>';
|
||||||
html += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\'' + branch.name + '\')" style="margin-right: 10px;">';
|
html += '<button class="back-btn" onclick="collapseAllBranches()" style="padding: 2px 6px; font-size: 11px;">收起全部</button>';
|
||||||
html += '<label for="' + branchId + '" style="flex: 1; cursor: pointer;">';
|
html += '</div>';
|
||||||
html += (branch.isCurrent ? '⭐ ' : '') + branch.name;
|
html += '<div class="branch-tree">';
|
||||||
html += (branch.isRemote ? '(远程)' : '(本地)') + '</label></div>';
|
html += this.renderBranchTreeNodes(branchTree, 0);
|
||||||
});
|
html += '</div>';
|
||||||
|
html += '<div style="margin-top: 12px;">';
|
||||||
html += '<div style="margin-top: 15px;">';
|
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 8px; padding: 4px 8px; font-size: 12px;">✅ 克隆选中分支</button>';
|
||||||
html += '<button class="btn-new" onclick="cloneSelectedBranches()" style="margin-right: 10px;">✅ 克隆选中分支</button>';
|
html += '<button class="back-btn" onclick="cancelBranchSelection()" style="padding: 4px 8px; font-size: 12px;">取消</button>';
|
||||||
html += '<button class="back-btn" onclick="cancelBranchSelection()">取消</button>';
|
|
||||||
html += '</div></div>';
|
html += '</div></div>';
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建分支树状结构
|
||||||
|
*/
|
||||||
|
private buildBranchTree(branches: GitBranch[]): BranchTreeNode[] {
|
||||||
|
const root: BranchTreeNode[] = [];
|
||||||
|
|
||||||
|
branches.forEach(branch => {
|
||||||
|
const parts = branch.name.split('/');
|
||||||
|
let currentLevel = root;
|
||||||
|
|
||||||
|
for (let i = 0; i < parts.length; i++) {
|
||||||
|
const part = parts[i];
|
||||||
|
const isLeaf = i === parts.length - 1;
|
||||||
|
const fullName = parts.slice(0, i + 1).join('/');
|
||||||
|
|
||||||
|
let node = currentLevel.find(n => n.name === part);
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
node = {
|
||||||
|
name: part,
|
||||||
|
fullName: fullName,
|
||||||
|
isLeaf: isLeaf,
|
||||||
|
children: [],
|
||||||
|
level: i
|
||||||
|
};
|
||||||
|
currentLevel.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLeaf) {
|
||||||
|
node.branch = branch;
|
||||||
|
} else {
|
||||||
|
node.expanded = node.expanded || true; // 默认展开
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLevel = node.children;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染分支树节点
|
||||||
|
*/
|
||||||
|
private renderBranchTreeNodes(nodes: BranchTreeNode[], level: number): string {
|
||||||
|
let html = '';
|
||||||
|
|
||||||
|
nodes.forEach(node => {
|
||||||
|
const indent = level * 20;
|
||||||
|
const nodeId = node.fullName.replace(/[^a-zA-Z0-9-]/g, '-');
|
||||||
|
|
||||||
|
if (node.isLeaf) {
|
||||||
|
// 叶子节点(实际分支)
|
||||||
|
html += '<div class="branch-node branch-leaf" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<input type="checkbox" id="branch-' + nodeId + '" class="branch-checkbox" ';
|
||||||
|
html += (node.branch && node.branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\'' + node.fullName + '\')">';
|
||||||
|
html += '<span class="branch-icon">🌿</span>';
|
||||||
|
html += '<span class="branch-name ' + (node.branch && node.branch.isCurrent ? 'current-branch' : '') + '">';
|
||||||
|
html += node.name;
|
||||||
|
html += (node.branch && node.branch.isCurrent ? ' ⭐' : '');
|
||||||
|
html += '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
} else {
|
||||||
|
// 文件夹节点
|
||||||
|
html += '<div class="branch-node" style="margin-left: ' + indent + 'px;">';
|
||||||
|
html += '<span class="branch-expand" onclick="toggleBranchNode(\'' + node.fullName + '\')">';
|
||||||
|
html += (node.expanded ? '🪵' : '🪵');
|
||||||
|
html += '</span>';
|
||||||
|
html += '<span class="branch-icon">🪵</span>';
|
||||||
|
html += '<span class="branch-name">' + node.name + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
if (node.expanded && node.children && node.children.length > 0) {
|
||||||
|
html += '<div class="branch-children">';
|
||||||
|
html += this.renderBranchTreeNodes(node.children, level + 1);
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算叶子节点数量
|
||||||
|
*/
|
||||||
|
private countLeafNodes(nodes: BranchTreeNode[]): number {
|
||||||
|
let count = 0;
|
||||||
|
nodes.forEach(node => {
|
||||||
|
if (node.isLeaf) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
count += this.countLeafNodes(node.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user