| 3847 | } |
| 3848 | |
| 3849 | void CCNotePad::dealRecentFileMenuWhenColseFile(QString closeFilePath) |
| 3850 | { |
| 3851 | //无条件加载一次,避免没有初始化 |
| 3852 | on_loadReceneFile(); |
| 3853 | |
| 3854 | QAction* act = nullptr; |
| 3855 | |
| 3856 | getRegularFilePath(closeFilePath); |
| 3857 | |
| 3858 | //如果关闭的文件,已经在最近列表中,则移动到最前面即可 |
| 3859 | int index = m_receneOpenFileList.indexOf(closeFilePath); |
| 3860 | if (-1 != index) |
| 3861 | { |
| 3862 | QString filePath = m_receneOpenFileList.takeAt(index); |
| 3863 | |
| 3864 | act = findItemInMenuByName(ui.menuRecene_File, filePath); |
| 3865 | |
| 3866 | if (act != nullptr) |
| 3867 | { |
| 3868 | ui.menuRecene_File->removeAction(act); |
| 3869 | } |
| 3870 | } |
| 3871 | else |
| 3872 | { |
| 3873 | act = new QAction(closeFilePath, ui.menuRecene_File); |
| 3874 | act->setObjectName(closeFilePath); |
| 3875 | connect(act, &QAction::triggered, this, &CCNotePad::slot_openReceneFile); |
| 3876 | } |
| 3877 | |
| 3878 | |
| 3879 | //在菜单最近列表上面添加。如果最近列表是空的,则放在退出菜单之上 |
| 3880 | if (m_receneOpenFileList.isEmpty()) |
| 3881 | { |
| 3882 | ui.menuRecene_File->insertAction(nullptr, act); |
| 3883 | } |
| 3884 | else |
| 3885 | { |
| 3886 | //放在列表最上面 |
| 3887 | QString curTopActionPath = m_receneOpenFileList.first(); |
| 3888 | |
| 3889 | QAction* topAct = findItemInMenuByName(ui.menuRecene_File, curTopActionPath); |
| 3890 | ui.menuRecene_File->insertAction(topAct, act); |
| 3891 | } |
| 3892 | |
| 3893 | m_receneOpenFileList.push_front(closeFilePath); |
| 3894 | |
| 3895 | //不能无限制变大,及时删除一部分 |
| 3896 | if (m_receneOpenFileList.size() > 15) |
| 3897 | { |
| 3898 | QString k = m_receneOpenFileList.takeLast(); |
| 3899 | QAction* lastAct = findItemInMenuByName(ui.menuRecene_File, k); |
| 3900 | if (lastAct != nullptr) |
| 3901 | { |
| 3902 | ui.menuRecene_File->removeAction(lastAct); |
| 3903 | lastAct->deleteLater(); |
| 3904 | } |
| 3905 | |
| 3906 | } |
nothing calls this directly
no test coverage detected