保存文件的另存为槽函数。1)先执行保存。2)用保存后的新文件路径,替换当前的路径
| 5736 | |
| 5737 | //保存文件的另存为槽函数。1)先执行保存。2)用保存后的新文件路径,替换当前的路径 |
| 5738 | void CCNotePad::slot_actionSaveAsFile_toggle(bool /*checked*/) |
| 5739 | { |
| 5740 | QWidget* pw = ui.editTabWidget->currentWidget(); |
| 5741 | |
| 5742 | //16进制的处理逻辑 |
| 5743 | if (HEX_TYPE == getDocTypeProperty(pw)) |
| 5744 | { |
| 5745 | ui.statusBar->showMessage(tr("Only Text File Can Use it, Current Doc is a Hex File !"), 10000); |
| 5746 | QApplication::beep(); |
| 5747 | return; |
| 5748 | } |
| 5749 | |
| 5750 | int index = ui.editTabWidget->currentIndex(); |
| 5751 | |
| 5752 | ScintillaEditView* pEdit = dynamic_cast<ScintillaEditView*>(pw); |
| 5753 | |
| 5754 | if (pEdit != nullptr) |
| 5755 | { |
| 5756 | //如果是新建的文件,则弹出保存对话框,进行保存 |
| 5757 | if (pEdit->property(Edit_File_New) >= 0) |
| 5758 | { |
| 5759 | QString filter("Text files (*.txt);;XML files (*.xml);;h files (*.h);;cpp file(*.cpp);;All types(*.*)"); |
| 5760 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File As ..."),QString(), filter); |
| 5761 | |
| 5762 | if (!fileName.isEmpty()) |
| 5763 | { |
| 5764 | getRegularFilePath(fileName); |
| 5765 | //如果已经打开过,则直接返回到当前文档 |
| 5766 | int retIndex = findFileIsOpenAtPad(fileName); |
| 5767 | if (-1 != retIndex) |
| 5768 | { |
| 5769 | QMessageBox::warning(this, tr("Error"), tr("file %1 already open at tab %2, please select other file name.").arg(fileName).arg(retIndex)); |
| 5770 | return; |
| 5771 | } |
| 5772 | |
| 5773 | if (!saveFile(fileName, pEdit)) |
| 5774 | { |
| 5775 | return; |
| 5776 | } |
| 5777 | |
| 5778 | updateProAfterSaveNewFile(index, fileName, pEdit); |
| 5779 | |
| 5780 | addWatchFilePath(fileName); |
| 5781 | } |
| 5782 | else |
| 5783 | { |
| 5784 | //这里点击了取消,不进行保存 |
| 5785 | return; |
| 5786 | } |
| 5787 | } |
| 5788 | else |
| 5789 | { |
| 5790 | //取消旧的文件监控 |
| 5791 | removeWatchFilePath(pEdit->property(Edit_View_FilePath).toString()); |
| 5792 | |
| 5793 | //如果是打开的本来就存在的文件,也弹出保存进行 |
| 5794 | QString filter("Text files (*.txt);;XML files (*.xml);;h files (*.h);;cpp file(*.cpp);;All types(*.*)"); |
| 5795 |
nothing calls this directly
no test coverage detected