MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / save

Method save

src/plugins/codeeditor/gui/texteditor.cpp:92–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void TextEditor::save()
93{
94 if (!isModified())
95 return;
96
97 QFile file(d->fileName);
98 if (!file.exists())
99 return;
100
101 if (!file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate)) {
102 DDialog dialog;
103 dialog.setIcon(QIcon::fromTheme("dialog-warning"));
104 dialog.setWindowTitle(tr("Save File"));
105 QString msg(tr("The file \"%1\" has no write permission. Please add write permission and try again"));
106 dialog.setMessage(msg.arg(d->fileName));
107 dialog.addButton(tr("Ok", "button"), true, DDialog::ButtonRecommend);
108 dialog.exec();
109 return;
110 }
111
112 QByteArray fileContent = text().toLocal8Bit();
113 if (!fileContent.isEmpty()) {
114 QByteArray Outdata;
115 DetectCode::changeFileEncodingFormat(fileContent, Outdata, QString("UTF-8"), d->documentEncode);
116 if (Outdata.isEmpty()) {
117 qWarning() << qPrintable(QString("iconv Encode Transformat from '%1' to '%2' Fail! start QTextCodec Encode Transformat.")
118 .arg(QString("UTF-8"), d->documentEncode));
119 // Using QTextCodec to convert
120 QTextCodec *codec = QTextCodec::codecForName(d->documentEncode.toUtf8());
121 if (codec) {
122 QByteArray encodedString = codec->fromUnicode(fileContent);
123 if (encodedString.isEmpty()) {
124 qWarning() << qPrintable("Both iconv and QTextCodec Encode Transformat Fail!");
125 } else {
126 qWarning() << qPrintable(QString("QTextCodec Encode Transformat from '%1' to '%2' Success!")
127 .arg(QString("UTF-8"), d->documentEncode));
128 Outdata = encodedString;
129 }
130 } else {
131 qWarning() << qPrintable("Unsupported QTextCodec format:") << d->documentEncode;
132 }
133 }
134
135 if (!Outdata.isEmpty())
136 file.write(Outdata);
137 } else {
138 file.write(fileContent);
139 }
140
141 file.close();
142 setModified(false);
143 editor.fileSaved(d->fileName);
144}
145
146void TextEditor::saveAs()
147{

Callers 15

paintMethod · 0.45
paintSeparatorMethod · 0.45
paintLineNumbersMethod · 0.45
paintItemBackgroundMethod · 0.45
paintItemIconMethod · 0.45
paintItemColumnMethod · 0.45
drawBackgroundMethod · 0.45
drawSourceTextMethod · 0.45
drawCloseButtonMethod · 0.45
drawActionButtonMethod · 0.45
paintItemBackgroundMethod · 0.45
paintItemColumnMethod · 0.45

Calls 9

QStringClass · 0.50
existsMethod · 0.45
openMethod · 0.45
setIconMethod · 0.45
setMessageMethod · 0.45
execMethod · 0.45
isEmptyMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected