From ed4d403654b1f540ab8ab0d302053abcc1dbf582 Mon Sep 17 00:00:00 2001 From: IoeCmcomc <53734763+IoeCmcomc@users.noreply.github.com> Date: Thu, 27 Jul 2023 22:14:26 +0700 Subject: [PATCH] [Bugfix] Fix all-file saving overwriting currently openning files - Fix file tab titles not updated correctly Signed-off-by: IoeCmcomc <53734763+IoeCmcomc@users.noreply.github.com> --- src/tabbeddocumentinterface.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tabbeddocumentinterface.cpp b/src/tabbeddocumentinterface.cpp index cc7b9966..196dfd75 100644 --- a/src/tabbeddocumentinterface.cpp +++ b/src/tabbeddocumentinterface.cpp @@ -99,6 +99,10 @@ bool TabbedDocumentInterface::saveFile(int index, const QString &filepath) { QSaveFile file(filepath); if (curFile.fileType >= CodeFile::Text) { + auto *doc = + qobject_cast(ui->tabWidget->widget(index))->document(); + Q_ASSERT(doc != nullptr); + #ifndef QT_NO_CURSOR QGuiApplication::setOverrideCursor(Qt::WaitCursor); #endif @@ -106,7 +110,8 @@ bool TabbedDocumentInterface::saveFile(int index, const QString &filepath) { if (file.open(QFile::WriteOnly | QFile::Text)) { QTextStream out(&file); out.setCodec("UTF-8"); - out << getCurDoc()->toPlainText().toUtf8(); + + out << doc->toPlainText().toUtf8(); if (!file.commit()) { errorMessage = tr("Cannot write file %1:\n%2.") .arg(QDir::toNativeSeparators(filepath), @@ -131,9 +136,8 @@ bool TabbedDocumentInterface::saveFile(int index, const QString &filepath) { if (ok) { curFile.changePath(filepath); - getCurDoc()->setModified(false); - if (index != getCurIndex()) - updateTabTitle(index, false); + doc->setModified(false); + updateTabTitle(index, false); files[index].isModified = false; } @@ -143,7 +147,7 @@ bool TabbedDocumentInterface::saveFile(int index, const QString &filepath) { } void TabbedDocumentInterface::updateTabTitle(int index, bool changed) { - auto &&newTitle = getCurFile()->name(); + auto &&newTitle = files[index].name(); if (changed) newTitle += '*'; @@ -366,8 +370,11 @@ bool TabbedDocumentInterface::saveAllFile() { if (!hasNoFile()) { for (int i = 0; i < count(); i++) { - /* AND operation */ - r &= saveFile(i, files[i].path()); + const auto &codeFile = files.at(i); + if (codeFile.isModified) { + /* AND operation */ + r &= saveFile(i, codeFile.path()); + } } } return r;