aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/TextEdit.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-05-12 16:36:57 +0000
committerSaturneric <[email protected]>2022-05-12 16:36:57 +0000
commitbaa3b65f16bf7c9ea7e5d6d3e25b9e2361cef8e1 (patch)
tree28205b29120c0ad99f1e8e262a9898f486bd10c2 /src/ui/widgets/TextEdit.cpp
parentfix: solve problem on .gitignore (diff)
downloadGpgFrontend-baa3b65f16bf7c9ea7e5d6d3e25b9e2361cef8e1.tar.gz
GpgFrontend-baa3b65f16bf7c9ea7e5d6d3e25b9e2361cef8e1.zip
feat(ui): more advanced charset functions
1. support dealing more type of files with different charsets 2. solve cash cause by reading file thread 3. improve ui operations
Diffstat (limited to '')
-rw-r--r--src/ui/widgets/TextEdit.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index ecf1a4bd..689f877b 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 {