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

Method openTextFile

src/cceditor/ccnotepad.cpp:4506–4647  ·  view source on GitHub ↗

打开普通文本文件。

Source from the content-addressed store, hash-verified

4504
4505//打开普通文本文件。
4506bool CCNotePad::openTextFile(QString filePath, bool isCheckHex, CODE_ID code)
4507{
4508 getRegularFilePath(filePath);
4509
4510 //先检测交换文件是否存在,如果存在,说明上次崩溃了,提示用户恢复
4511 QString swapfile = getSwapFilePath(filePath);
4512
4513 bool isNeedRestoreFile = false;
4514
4515 QFileInfo fi(filePath);
4516
4517 //如果文件大于设定最大值,询问是否只读文件打开
4518 if (ScintillaEditView::s_bigTextSize <= 0 || ScintillaEditView::s_bigTextSize > 300)
4519 {
4520 ScintillaEditView::s_bigTextSize = 100;
4521 }
4522
4523 if (fi.size() > ScintillaEditView::s_bigTextSize*1024*1024)
4524 {
4525 //文件如果小于1G,询问用户如何打开。如果大于1G,无条件分块加载
4526 if (fi.size() < MAX_TRY_OPEN_FILE_SIZE)
4527 {
4528 BigFileMessage askMsgBox(this);
4529 askMsgBox.setTip(tr("File %1 \nFile Size %2 > %3M, How to Open it ?").arg(filePath).arg(tranFileSize(fi.size())).arg(ScintillaEditView::s_bigTextSize));
4530 int openMode = askMsgBox.exec();
4531
4532 //放弃打开
4533 if (openMode == -1)
4534 {
4535 return false;
4536 }
4537 else if (openMode == TXT_TYPE)
4538 {
4539 //正常普通文本打开,不做什么,继续往下走
4540 }
4541 else if (openMode == BIG_TEXT_RO_TYPE)
4542 {
4543 //大文本只读打开。20230125新增,做了内部索引,适合4G-8G左右的文件。
4544 return openBigTextRoFile(filePath);
4545 }
4546 else if (openMode == SUPER_BIG_TEXT_RO_TYPE)
4547 {
4548 //超大文本编辑模式。8G以上
4549 return openSuperBigTextFile(filePath);
4550 }
4551 else
4552 {
4553 //二进制打开
4554 return openHexFile(filePath);
4555 }
4556 }
4557 else
4558 {
4559 //如果小于8G,则大文本只读打开;反之则超大文本只读打开
4560 if (fi.size() <= 8 * MAX_TRY_OPEN_FILE_SIZE)
4561 {
4562 return openBigTextRoFile(filePath);
4563 }

Callers

nothing calls this directly

Calls 10

getRegularFilePathFunction · 0.85
getSwapFilePathFunction · 0.85
tranFileSizeFunction · 0.85
copyFunction · 0.85
setDocTypePropertyFunction · 0.85
setTipMethod · 0.80
newEmptyDocumentMethod · 0.80
loadFileDataInTextMethod · 0.80
sizeMethod · 0.45
setNoteWidgetMethod · 0.45

Tested by

no test coverage detected