deepin-editor
deepin-editor copied to clipboard
fix: 修复关闭窗口保存提示
修复关闭窗口保存提示
Bug: https://pms.uniontech.com/bug-view-315439.html https://pms.uniontech.com/bug-view-315425.html Log: 修复关闭窗口保存提示,与v20保持一致
Summary by Sourcery
Implement saveAllFiles to prompt saving modified files on window close and integrate it into the close event, and prevent auto-backup from running when no windows are open.
Bug Fixes:
- Restore prompting to save unsaved files when closing a window to match expected behavior.
- Prevent the auto-backup routine from running when there are no open windows.
Enhancements:
- Add a saveAllFiles() method in the Window class to centralize save-on-close logic.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: myk1343
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
deepin pr auto review
代码审查意见:
-
在
StartManager::autoBackupFile函数中,新增了一个条件判断if (m_windows.isEmpty()) { return; }。这个改动是合理的,可以避免在m_windows为空时执行不必要的操作。 -
在
Window::saveAllFiles函数中,使用了QMap<QString, EditWrapper *> wrappers = m_wrappers;来复制m_wrappers。这个做法虽然可以避免直接修改原始数据,但每次调用saveAllFiles时都会创建一个新的QMap对象,这可能会影响性能。建议在函数内部直接使用m_wrappers,或者将m_wrappers的引用作为参数传递给函数。 -
在
Window::saveAllFiles函数中,对于每个文件保存操作,都使用了m_tabbar->setCurrentIndex(i);来切换到当前文件所在的标签页。这个操作可能会影响性能,因为每次切换标签页都需要重新布局和渲染界面。建议在保存文件之前保存当前活动的标签页索引,保存完成后恢复该索引。 -
在
Window::saveAllFiles函数中,对于每个文件保存操作,都使用了QFileInfo fileInfo(filePath);来获取文件信息。这个操作可能会影响性能,因为每次获取文件信息都需要访问文件系统。建议将文件信息存储在EditWrapper对象中,避免重复访问文件系统。 -
在
Window::saveAllFiles函数中,对于每个文件保存操作,都使用了if (res == 0 || res == -1) { return false; }来处理用户取消或关闭弹窗的情况。这个做法可能会导致函数提前返回,从而无法保存所有文件。建议将保存操作放在一个循环中,即使某个文件保存失败,也应该继续尝试保存其他文件。 -
在
Window::saveAllFiles函数中,对于每个文件保存操作,都使用了if (res == 2) { m_tabbar->setCurrentIndex(i); ... }来处理用户选择保存的情况。这个做法可能会导致界面频繁切换,影响用户体验。建议在保存文件之前保存当前活动的标签页索引,保存完成后恢复该索引。 -
在
Window::closeEvent函数中,新增了一个条件判断if (!saveAllFiles()) { backupFile(); e->ignore(); return; }。这个改动是合理的,可以确保在关闭窗口之前保存所有文件。但是,这个改动可能会导致backupFile函数被多次调用,影响性能。建议在backupFile函数中添加一个标志位,避免重复备份。 -
在
Window::closeEvent函数中,新增了一个条件判断if (!saveAllFiles()) { backupFile(); e->ignore(); return; }。这个改动是合理的,可以确保在关闭窗口之前保存所有文件。但是,这个改动可能会导致backupFile函数被多次调用,影响性能。建议在backupFile函数中添加一个标志位,避免重复备份。
总体来说,代码改动是合理的,但是需要注意性能和用户体验的问题。建议在保存文件和备份文件时,尽量减少对文件系统的访问,避免频繁切换界面。
[!NOTE] [静态代码检查]
- 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
"src/widgets/window.cpp": [
{
"line": " QString key = \"base/enable\";",
"line_number": 372,
"rule": "S106",
"reason": "Var naming | 64f28539d9"
}
]
}
Reviewer's Guide
Introduces a centralized saveAllFiles routine in Window to prompt and persist each modified file before closing, integrates it into the closeEvent flow to allow canceling or proceeding with backups, and adds a guard in StartManager to skip backup logic when no windows are open.
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Add saveAllFiles to handle per-file save prompts on window close |
|
src/widgets/window.hsrc/widgets/window.cpp |
| Integrate saveAllFiles into closeEvent to control backup and cancellation |
|
src/widgets/window.cpp |
| Guard against empty window list in autoBackupFile |
|
src/startmanager.cpp |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
TAG Bot
New tag: 6.5.26 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #359
TAG Bot
New tag: 6.5.27 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #362
TAG Bot
New tag: 6.5.28 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #368
TAG Bot
New tag: 6.5.29 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #370
TAG Bot
New tag: 6.5.30 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #372
TAG Bot
New tag: 6.5.31 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #373
TAG Bot
New tag: 6.5.32 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #374
TAG Bot
New tag: 6.5.33 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #376
TAG Bot
New tag: 6.5.34 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #379
TAG Bot
New tag: 6.5.35 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #380
TAG Bot
New tag: 6.5.36 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #383
TAG Bot
New tag: 6.5.37 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #386
TAG Bot
New tag: 6.5.38 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #387
TAG Bot
New tag: 6.5.39 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #393
TAG Bot
New tag: 6.5.40 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #396
TAG Bot
New tag: 6.5.41 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #398