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

Method showBigTextFile

src/cceditor/ccnotepad.cpp:4853–4920  ·  view source on GitHub ↗

显示超大文本文件只读

Source from the content-addressed store, hash-verified

4851
4852//显示超大文本文件只读
4853bool CCNotePad::showBigTextFile(ScintillaEditView* pEdit, TextFileMgr* txtFile)
4854{
4855 qint64 addr = txtFile->fileOffset - txtFile->contentRealSize;
4856
4857
4858 CODE_ID code = (CODE_ID)txtFile->loadWithCode;
4859
4860 //不知道编码,则需要自动判断编码
4861 if (txtFile->loadWithCode == UNKOWN)
4862 {
4863 //自动从头部或文件中判断编码
4864 code = CmpareMode::getTextFileEncodeType((uchar *)txtFile->contentBuf, txtFile->contentRealSize, txtFile->filePath);
4865 }
4866
4867 QString outUtf8Text;
4868
4869 bool tranSucess = true;
4870
4871
4872 //UNICODE_LE格式需要单独处理
4873 if (code == UNICODE_LE)
4874 {
4875 tranSucess = CmpareMode::tranUnicodeLeToUtf8Bytes((uchar*)txtFile->contentBuf, txtFile->contentRealSize, outUtf8Text);
4876 }
4877 else
4878 {
4879 //如果还是unknown,则没法了,默认按照Utf8解析。
4880 if (code == UNKOWN)
4881 {
4882 code = UTF8_NOBOM;
4883 }
4884 tranSucess = Encode::tranStrToUNICODE(code, (const char*)txtFile->contentBuf, txtFile->contentRealSize, outUtf8Text);
4885 }
4886
4887 if (txtFile->loadWithCode != code)
4888 {
4889 txtFile->loadWithCode = code;
4890 }
4891
4892 //获取行结尾信息
4893 if (txtFile->lineEndType == RC_LINE_FORM::UNKNOWN_LINE)
4894 {
4895 txtFile->lineEndType = getLineEndTypeFromBigText(outUtf8Text);
4896 }
4897
4898 pEdit->setText(outUtf8Text);
4899
4900 if (tranSucess)
4901 {
4902 ui.statusBar->showMessage(tr("Current offset is %1 , load Contens Size is %2, File Total Size is %3").arg(addr).arg(txtFile->contentRealSize).arg(txtFile->fileSize));
4903 }
4904 else
4905 {
4906 //文件乱码
4907 if (txtFile->contentBuf == 0)
4908 {
4909 QMessageBox::warning(this, tr("Format Error"), tr("Not a txt format file , load with big txt is garbled code!"));
4910 }

Callers

nothing calls this directly

Calls 5

setTextMethod · 0.80
showBigTextRoLineNumMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected