From 06e4c15b5c093c7d08178111888afaccc455aee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Fri, 1 May 2026 22:39:39 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=E6=92=A4=E9=94=80/?= =?UTF-8?q?=E9=87=8D=E5=81=9A=20UI=20=E9=9B=86=E6=88=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- ...6-05-01-undo-redo-ui-integration-design.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 docs/superpowers/specs/2026-05-01-undo-redo-ui-integration-design.md diff --git a/docs/superpowers/specs/2026-05-01-undo-redo-ui-integration-design.md b/docs/superpowers/specs/2026-05-01-undo-redo-ui-integration-design.md new file mode 100644 index 0000000..d82085e --- /dev/null +++ b/docs/superpowers/specs/2026-05-01-undo-redo-ui-integration-design.md @@ -0,0 +1,65 @@ +# 撤销/重做 UI 集成 — 设计文档 + +## 背景 + +撤销/重做后端(`src/core/undo_redo.c`)已完整实现,支持 7 种操作类型的记录与回滚。所有 UI 操作(新建/编辑/删除/上移/下移/清理)均已调用 `push_undo_record()` 写入历史。但 `undo()` 和 `redo()` 函数未被任何 UI 代码调用——用户无法触发撤销或重做。 + +## 目标 + +在界面上添加撤销/重做按钮,并绑定 Ctrl+Z / Ctrl+Y 快捷键,让用户可以回退和恢复操作。 + +## 改动文件 + +| 文件 | 改动内容 | +|------|---------| +| `include/utils/ui_constants.h` | 新增 `CTRL_BTN_UNDO`、`CTRL_BTN_REDO` 常量 | +| `src/ui/main_window.c` | 创建撤销/重做按钮,绑定回调,调整布局 | +| `src/controller/callbacks_nav.c` | 新增 `btn_undo_cb`、`btn_redo_cb`,`list_k_any_cb` 增加 Ctrl+Z/Y 检测 | +| `lua/config.lua` | 新增 `button.undo`、`button.redo` 配置项 | +| `locale/` 翻译文件 | 同步新增按钮的中英文翻译 | + +## 核心逻辑 + +``` +btn_undo_cb(dlg): + ctx = get_app_context_from_dlg(dlg) + if !can_undo(ctx->undo_redo_mgr): return + undo(ctx->undo_redo_mgr, &ctx->sys_paths, &ctx->user_paths) + sync both lists to UI + update undo/redo button enabled state + +btn_redo_cb(dlg): + 同上,调用 redo() + +list_k_any_cb: + 新增分支: + if c == K_cZ → btn_undo_cb + if c == K_cY → btn_redo_cb +``` + +## 按钮布局 + +撤销/重做按钮放在上移/下移按钮下方: + +``` + [新建] [编辑] + [浏览] [删除] + (分隔) + [一键清理] + (分隔) + [导入] [导出] + [上移] [下移] + [撤销] [重做] ← 新增 +``` + +## 按钮状态 + +- `can_undo() == false` → 撤销按钮 `ACTIVE=NO` +- `can_redo() == false` → 重做按钮 `ACTIVE=NO` +- 每次 undo/redo 执行后刷新按钮状态 + +## 不做的事 + +- 不修改 `undo_redo.c` 后端代码(已完备) +- 不添加操作历史面板(保持简洁,通过按钮状态反馈即可) +- 不在保存后清空历史(当前设计由 `clear_undo_redo_history` 决定,保持现有行为)