oimp
Version:
A CLI tool for generating OI problem and packages
218 lines (193 loc) • 9.38 kB
JavaScript
import { runCommandInTerminal } from "./ide-terminal.js";
import { getCurrentProblemId,selectFileInTree } from "./ide-utility.js";
export async function initWorkFlow() {
// 工作流按钮事件处理函数
function setupWorkflowButtons() {
// 题目状态按钮
const statusBtn = document.getElementById('workflow-status');
if (statusBtn) {
statusBtn.addEventListener('click', function () {
runCommandInTerminal('status');
});
}
// 编辑题目元数据按钮
const editBtn = document.getElementById('workflow-edit');
if (editBtn) {
editBtn.addEventListener('click', function () {
runCommandInTerminal('edit');
});
}
// 修复按钮
const fixBtn = document.getElementById('workflow-fix');
if (fixBtn) {
fixBtn.addEventListener('click', function () {
runCommandInTerminal('fix');
});
}
// 快照按钮
const snapshotBtn = document.getElementById('workflow-snapshot');
if (snapshotBtn) {
snapshotBtn.addEventListener('click', function () {
runCommandInTerminal('snapshot list');
});
}
// 编辑题面按钮
const editProblemBtn = document.getElementById('workflow-edit-problem');
if (editProblemBtn) {
editProblemBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/problem_zh.md`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 生成样例按钮
const genSampleBtn = document.getElementById('workflow-gen-sample');
if (genSampleBtn) {
genSampleBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/problem_zh.md`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 编辑标程按钮
const editStdBtn = document.getElementById('workflow-edit-std');
if (editStdBtn) {
editStdBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/src/std.cpp`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 编辑数据生成器按钮
const editGeneratorBtn = document.getElementById('workflow-edit-generator');
if (editGeneratorBtn) {
editGeneratorBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/src/generator.cpp`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 编辑输入验证器按钮
const editValidatorBtn = document.getElementById('workflow-edit-validator');
if (editValidatorBtn) {
editValidatorBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/src/validator.cpp`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 编辑评测器按钮
const editCheckerBtn = document.getElementById('workflow-edit-checker');
if (editCheckerBtn) {
editCheckerBtn.addEventListener('click', function () {
const problemId = getCurrentProblemId();
const filePath = `${problemId}/src/checker.cpp`;
// 只在文件树中选中该文件
selectFileInTree(filePath);
});
}
// 测试样例按钮
const testsampleBtn = document.getElementById('workflow-testsample');
if (testsampleBtn) {
testsampleBtn.addEventListener('click', function () {
runCommandInTerminal('testsample');
});
}
// 检查按钮
const checkBtn = document.getElementById('workflow-check');
if (checkBtn) {
checkBtn.addEventListener('click', function () {
runCommandInTerminal('check');
});
}
// 生成数据按钮
const gendataBtn = document.getElementById('workflow-gendata');
if (gendataBtn) {
gendataBtn.addEventListener('click', function () {
runCommandInTerminal('gendata');
});
}
// 打包按钮
const packageBtn = document.getElementById('workflow-package');
if (packageBtn) {
packageBtn.addEventListener('click', function () {
runCommandInTerminal('package');
});
}
// 工作流区域hover事件处理
const workflowBar = document.getElementById('workflow-bar');
const terminal = document.getElementById('terminal');
const previewMain = document.getElementById('ide-preview-main');
let lastTermHeight = null; // 记录展开前的终端高度
const currentTermHeight = terminal.offsetHeight;
const oldWorkflowBarHeight = workflowBar.offsetHeight;
if (workflowBar && terminal && previewMain) {
workflowBar.addEventListener('mouseenter', function () {
const topbar = document.getElementById('topbar');
const workflowExpandedHeight = 250; // 工作流展开后的高度
const totalHeight = window.innerHeight - topbar.offsetHeight;
const availableHeight = totalHeight - workflowExpandedHeight; // 减去工作流展开高度后的可用高度
lastTermHeight = currentTermHeight; // 记录展开前高度
let newTermHeight;
if (currentTermHeight > 300 && currentTermHeight < availableHeight) {
newTermHeight = currentTermHeight;
} else if (currentTermHeight <= 300) {
newTermHeight = 300;
} else {
newTermHeight = Math.floor(availableHeight * 0.6);
}
newTermHeight = Math.max(300, newTermHeight);
// 设置终端和主区高度
terminal.style.height = newTermHeight + 'px';
previewMain.style.height = (totalHeight - newTermHeight) + 'px';
// 直接同步所有区域高度,确保实时响应
const ideMain = document.getElementById('ide-main');
const fileTree = document.getElementById('file-tree');
const editorDiv = document.getElementById('editor');
const previewDiv = document.getElementById('preview');
const mainHeight = totalHeight - newTermHeight;
if (ideMain) ideMain.style.height = mainHeight + 'px';
if (fileTree) fileTree.style.height = mainHeight + 'px';
if (editorDiv) editorDiv.style.height = mainHeight + 'px';
if (previewDiv) previewDiv.style.height = mainHeight + 'px';
// 同步编辑器布局
if (window.editor && window.editor.layout) {
window.editor.layout();
}
// 适配终端
if (window.fitAddon) window.fitAddon.fit();
});
workflowBar.addEventListener('mouseleave', function () {
const topbar = document.getElementById('topbar');
const totalHeight = window.innerHeight - topbar.offsetHeight;
let restoreHeight = currentTermHeight || 200;
const dragbarHeight = document.getElementById('terminal-dragbar').offsetHeight;
// 设置终端和主区高度
terminal.style.height = currentTermHeight + 'px';
previewMain.style.height = (totalHeight - restoreHeight - oldWorkflowBarHeight-dragbarHeight) + 'px';
// 直接同步所有区域高度,确保实时响应
const ideMain = document.getElementById('ide-main');
const fileTree = document.getElementById('file-tree');
const editorDiv = document.getElementById('editor');
const previewDiv = document.getElementById('preview');
const mainHeight = totalHeight - restoreHeight - oldWorkflowBarHeight-dragbarHeight;
if (ideMain) ideMain.style.height = mainHeight + 'px';
if (fileTree) fileTree.style.height = mainHeight + 'px';
if (editorDiv) editorDiv.style.height = mainHeight + 'px';
if (previewDiv) previewDiv.style.height = mainHeight + 'px';
// 同步编辑器布局
if (window.editor && window.editor.layout) {
window.editor.layout();
}
// 适配终端
if (window.fitAddon) window.fitAddon.fit();
});
}
}
setupWorkflowButtons();
}