MCPcopy Create free account
hub / github.com/cxasm/notepad-- / saveTempFile

Method saveTempFile

src/cceditor/ccnotepad.cpp:6029–6136  ·  view source on GitHub ↗

保存文件为临时文件。一定是文本格式,可读写的。只在关闭时才需要调用该函数。 凡是存在临时文件的,一定是脏文件,即关闭时没有保存的文件。 而不存在临时文件,只有一个记录在list中的文件,表示不脏的文件,直接打开原始文件即可。 1:非脏新建文件 2 非脏的已存在文件 3 脏的新建文件 4 脏的老文件。 5和3一样,但是多了一个语法设置保存。 20230119 对于1非脏的新建文件,不再保存。

Source from the content-addressed store, hash-verified

6027//5和3一样,但是多了一个语法设置保存。
6028//20230119 对于1非脏的新建文件,不再保存。
6029void CCNotePad::saveTempFile(ScintillaEditView* pEdit,int index, QSettings& qs)
6030{
6031 //16进制的处理逻辑
6032 if (TXT_TYPE != getDocTypeProperty(pEdit))
6033 {
6034 return;
6035 }
6036
6037 QVariant v = pEdit->property(Edit_Text_Change);
6038 bool isDirty = v.toBool();
6039
6040 //不脏则不需要保存,直接跳过。不脏的文件,只记录1个名称,下次打开时恢复
6041 if (!isDirty)
6042 {
6043 QString fileName = pEdit->property(Edit_View_FilePath).toString();
6044 //把文件记录到qs中去
6045 //index一定不能重复。n表示新建
6046 //如果是新建的文件
6047 if (pEdit->property(Edit_File_New) >= 0)
6048 {
6049 //不再保存新建的非脏文件。因为一定是空的,意义不大
6050 //qs.setValue(QString("%1").arg(index), QString("%1|1").arg(fileName));
6051 }
6052 else
6053 {
6054 qs.setValue(QString("%1").arg(index), QString("%1|2").arg(fileName));
6055
6056 //非新建文件,清空交换文件
6057 QString swapfile = getSwapFilePath(fileName);
6058 if (QFile::exists(swapfile))
6059 {
6060 QFile::remove(swapfile);
6061 }
6062 }
6063 return;
6064 }
6065
6066 //如果是新建的文件
6067 if (pEdit->property(Edit_File_New) >= 0)
6068 {
6069 QString qsSavePath = qs.fileName();
6070
6071 QFileInfo fi(qsSavePath);
6072 QString saveDir = fi.dir().absolutePath();
6073 QString tempFileName = QString("%1/%2").arg(saveDir).arg(index);
6074
6075 if (!saveFile(tempFileName, pEdit,false,true))
6076 {
6077 return;
6078 }
6079 else
6080 {
6081 QString fileName = pEdit->property(Edit_View_FilePath).toString();
6082 //把文件记录到qs中去
6083 //index一定不能重复。2表示新建
6084 int lexId = L_TXT;
6085 if (pEdit->lexer() != nullptr)
6086 {

Callers

nothing calls this directly

Calls 5

getDocTypePropertyFunction · 0.85
getSwapFilePathFunction · 0.85
isEmptyMethod · 0.80
lexerMethod · 0.45
lexerIdMethod · 0.45

Tested by

no test coverage detected