fix(reader): skip docx annotation auto-save so close prompts save-as … - #378
Conversation
…dialog Docx files are opened through a converted temp.pdf under a random temporary directory, so annotation auto-save cannot really persist: onAutoSave wrote annotations into temp.pdf and cleared the changed flag, which made fileChanged() false on close. The save-confirmation dialog was therefore skipped and annotations were silently lost when the temporary directory was removed. Skip the annotation save in onAutoSave for docx and keep the sheet marked as changed, so closing prompts the confirmation dialog where "Save" routes to save-as PDF. PDF/DJVU/XPS behavior is unchanged. Log: 修复 docx 添加注释后关闭查看器不弹保存确认框导致注释静默丢失的问题 PMS: BUG-376501 Influence: docx 添加注释/高亮后关闭查看器会弹保存确认框,选"保存"可另存为 PDF 保留注释;PDF/DJVU/XPS 的自动保存行为不变。
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates DOCX auto-save handling to skip persistence into the temporary converted PDF and preserve the dirty state, ensuring closing prompts users to save annotations as PDF while leaving PDF/DJVU/XPS behavior unchanged. Sequence diagram for DOCX annotation close and save confirmationsequenceDiagram
participant User
participant DocSheet
participant TempPDF
participant SaveAsPDF
User->>DocSheet: add annotation
DocSheet->>DocSheet: onAutoSave()
alt DOCX
DocSheet-->>DocSheet: preserve m_documentChanged
User->>DocSheet: close viewer
DocSheet-->>User: show save-confirmation dialog
User->>DocSheet: Save
DocSheet->>SaveAsPDF: save annotations as PDF
SaveAsPDF-->>User: PDF with annotations
else PDF/DJVU/XPS
DocSheet->>TempPDF: save annotations
DocSheet-->>DocSheet: clear m_documentChanged
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。修改在 DocSheet::onAutoSave() 函数(reader/uiframe/DocSheet.cpp:2176)中增加 Dr::DOCX != fileType() 条件判断,C++ 语法正确,枚举比较使用 != 运算符合法。逻辑流程正确:跳过 DOCX 自动保存后 m_documentChanged 保持 true,fileChanged()(行618)返回 true,关闭时 CentralDocPage(行417)触发保存确认框,用户选择保存后走 saveAsCurrent() 另存为 PDF。该条件与 saveAsData()(行668)中已有的 Dr::DOCX != fileType() 模式一致,无边界条件问题。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码结构清晰,注释完整。新增5行注释详细说明了:1) DOCX 为转换打开格式,注释写入临时目录的 temp.pdf;2) 自动保存无法持久化的原因;3) 若照常保存清掉脏标志会导致关闭跳过确认框;4) 引用 BUG-376501;5) 设计意图为保持未保存状态由关闭确认框引导另存为 PDF。注释质量优秀,无代码重复,修改最小化(仅修改1个条件),符合现有代码风格。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理。新增条件 Dr::DOCX != fileType() 为 O(1) 枚举比较,开销可忽略。实际上对 DOCX 文件避免了不必要的文件 I/O 操作(m_renderer->save()),略有性能提升。无不必要的内存操作,无算法复杂度问题。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 存在0个安全漏洞。本次修改仅影响 DOCX 文件的自动保存行为,不涉及用户输入处理、认证授权、敏感信息等安全相关逻辑。无命令注入、路径遍历、缓冲区溢出等风险。OCR 审查结果同样为0个问题。 💡 改进建议代码示例// 当前修改已是最优实现,无需额外改进。
// onAutoSave() 中跳过 DOCX 自动保存的条件判断:
void DocSheet::onAutoSave()
{
qCDebug(appLog) << "Auto-save triggered for:" << m_filePath;
bool contentSaved = false;
// DOCX 跳过自动保存,保持脏标志,由关闭确认框引导另存为 PDF
if (m_documentChanged && Dr::DOCX != fileType()) {
if (m_renderer && m_renderer->save()) {
m_documentChanged = false;
m_sidebar->changeResetModelData();
contentSaved = true;
}
}
// ...
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
…dialog
Docx files are opened through a converted temp.pdf under a random temporary directory, so annotation auto-save cannot really persist: onAutoSave wrote annotations into temp.pdf and cleared the changed flag, which made fileChanged() false on close. The save-confirmation dialog was therefore skipped and annotations were silently lost when the temporary directory was removed.
Skip the annotation save in onAutoSave for docx and keep the sheet marked as changed, so closing prompts the confirmation dialog where "Save" routes to save-as PDF. PDF/DJVU/XPS behavior is unchanged.
Log: 修复 docx 添加注释后关闭查看器不弹保存确认框导致注释静默丢失的问题
PMS: BUG-376501
Influence: docx 添加注释/高亮后关闭查看器会弹保存确认框,选"保存"可另存为 PDF 保留注释;PDF/DJVU/XPS 的自动保存行为不变。
Summary by Sourcery
Ensure DOCX annotation changes prompt for confirmation on close, allowing users to save them as PDF.
Bug Fixes: