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

Method newTxtFile

src/cceditor/ccnotepad.cpp:4071–4184  ·  view source on GitHub ↗

输入参数:名称和文件新建文件序号。一定是文本文件。contentPath:从这个路径加载文件内容,目前在恢复文件中使用。

Source from the content-addressed store, hash-verified

4069
4070//输入参数:名称和文件新建文件序号。一定是文本文件。contentPath:从这个路径加载文件内容,目前在恢复文件中使用。
4071ScintillaEditView* CCNotePad::newTxtFile(QString name, int index, QString contentPath)
4072{
4073 ScintillaEditView* pEdit = FileManager::getInstance().newEmptyDocument();
4074 pEdit->setNoteWidget(this);
4075
4076 CODE_ID code(UTF8_NOBOM);
4077
4078#ifdef _WIN32
4079 RC_LINE_FORM lineEnd(DOS_LINE);
4080#else
4081 RC_LINE_FORM lineEnd(UNIX_LINE);
4082#endif
4083
4084 bool isChange = false;
4085
4086 //如果非空,则从contentPath中加载文件内容。做恢复文件使用
4087 if (!contentPath.isEmpty())
4088 {
4089 int ret = FileManager::getInstance().loadFileDataInText(pEdit, contentPath, code, lineEnd, nullptr, false, this);
4090 if (6 == ret)
4091 {
4092 //可能存在乱码,给出警告。还是以编辑模式打开
4093 ui.statusBar->showMessage(tr("File %1 open success. But Exist Garbled code !"));
4094 }
4095 else if (ret != 0)
4096 {
4097 ui.statusBar->showMessage(tr("Restore Last Temp File %1 Failed").arg(contentPath));
4098 }
4099 isChange = true;
4100 }
4101
4102 connect(pEdit, &ScintillaEditView::cursorPositionChanged, this, &CCNotePad::slot_LineNumIndexChange, Qt::QueuedConnection);
4103 connect(pEdit, &ScintillaEditView::copyAvailable, this, &CCNotePad::slot_copyAvailable);
4104 connect(pEdit, SIGNAL(SCN_ZOOM()), this, SLOT(slot_zoomValueChange()));
4105
4106 enableEditTextChangeSign(pEdit);
4107
4108 QString label = name;
4109
4110 disconnect(ui.editTabWidget, &QTabWidget::currentChanged, this, &CCNotePad::slot_tabCurrentChanged);
4111
4112 int curIndex = ui.editTabWidget->addTab(pEdit, QIcon((StyleSet::getCurrentSytleId() != DEEP_BLACK)? TabNoNeedSave:TabNoNeedSaveDark32), label);
4113
4114 QVariant editViewFilePath(label);
4115 pEdit->setProperty(Edit_View_FilePath, editViewFilePath);
4116 ui.editTabWidget->setTabToolTip(curIndex, label);
4117
4118 setFileOpenAttrProperty(pEdit, OpenAttr::Text);
4119 setWindowTitleMode(label, OpenAttr::Text);
4120
4121 QVariant editViewNewFile(index);
4122 pEdit->setProperty(Edit_File_New, editViewNewFile);
4123
4124 QVariant editTextChange(isChange);
4125 pEdit->setProperty(Edit_Text_Change, editTextChange);
4126
4127 QVariant editTextCode((int)code);
4128 pEdit->setProperty(Edit_Text_Code, editTextCode);

Callers

nothing calls this directly

Calls 11

setFileOpenAttrPropertyFunction · 0.85
setDocTypePropertyFunction · 0.85
setEditShowBlankStatusFunction · 0.85
newEmptyDocumentMethod · 0.80
isEmptyMethod · 0.80
loadFileDataInTextMethod · 0.80
insertNewFileNodeMethod · 0.80
zoomToMethod · 0.80
setNoteWidgetMethod · 0.45
setWrapModeMethod · 0.45
setIndentGuideMethod · 0.45

Tested by

no test coverage detected