aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/TextEdit.cpp
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2022-05-13 19:31:40 +0000
committerGitHub <[email protected]>2022-05-13 19:31:40 +0000
commit49090d1d511a4a0fbcfac253656a40a42716c82e (patch)
tree2553bd9a1d14c099a0a990576fb7c874f72b3859 /src/ui/widgets/TextEdit.cpp
parentMerge pull request #60 from saturneric/develop-2.0.7 (diff)
parentfix(core): solve memory access issues (diff)
downloadGpgFrontend-49090d1d511a4a0fbcfac253656a40a42716c82e.tar.gz
GpgFrontend-49090d1d511a4a0fbcfac253656a40a42716c82e.zip
Merge pull request #62 from saturneric/develop-2.0.8v2.0.8
Develop 2.0.8
Diffstat (limited to 'src/ui/widgets/TextEdit.cpp')
-rw-r--r--src/ui/widgets/TextEdit.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index ecf1a4bd..713dbb80 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -166,11 +166,30 @@ bool TextEdit::save_file(const QString& fileName) {
return false;
}
+ PlainTextEditorPage* page = SlotCurPageTextEdit();
+ if (page == nullptr) return false;
+
+ if (page->WillCharsetChange()) {
+ auto result = QMessageBox::warning(
+ this, _("Save"),
+ QString("<p>") +
+ _("After saving, the encoding of the current file will be "
+ "converted to UTF-8 and the line endings will be changed to "
+ "LF. ") +
+ "</p>" + "<p>" +
+ _("If this is not the result you expect, please use \"save "
+ "as\".") +
+ "</p>",
+ QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Cancel);
+
+ if (result == QMessageBox::Cancel) {
+ return false;
+ }
+ }
+
QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- PlainTextEditorPage* page = SlotCurPageTextEdit();
-
QTextStream outputStream(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
outputStream << page->GetTextPage()->toPlainText();
@@ -182,7 +201,8 @@ bool TextEdit::save_file(const QString& fileName) {
int curIndex = tab_widget_->currentIndex();
tab_widget_->setTabText(curIndex, stripped_name(fileName));
page->SetFilePath(fileName);
- // statusBar()->showMessage(_("File saved"), 2000);
+ page->NotifyFileSaved();
+
file.close();
return true;
} else {
@@ -295,9 +315,7 @@ bool TextEdit::maybe_save_current_tab(bool askToSave) {
return false;
}
}
-
- // destroy
- page->PrepareToDestroy();
+ page->deleteLater();
return true;
}