Skip to content

Commit

Permalink
[Bugfix] Fix all-file saving overwriting currently openning files
Browse files Browse the repository at this point in the history
- Fix file tab titles not updated correctly

Signed-off-by: IoeCmcomc <53734763+IoeCmcomc@users.noreply.github.com>
  • Loading branch information
IoeCmcomc committed Jul 28, 2023
1 parent b4851c4 commit ed4d403
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/tabbeddocumentinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ bool TabbedDocumentInterface::saveFile(int index, const QString &filepath) {

QSaveFile file(filepath);
if (curFile.fileType >= CodeFile::Text) {
auto *doc =
qobject_cast<CodeEditor *>(ui->tabWidget->widget(index))->document();
Q_ASSERT(doc != nullptr);

#ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif

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),
Expand All @@ -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;
}

Expand All @@ -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 += '*';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ed4d403

Please sign in to comment.