From e466ef2afe25513d02ec15bba05a407dd207592f Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Tue, 17 Aug 2021 18:40:57 +0100 Subject: [PATCH] Change to .tti suffix when saving imported file --- mainwindow.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index dabc4e1..ea522f0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -108,14 +108,28 @@ void MainWindow::openFile(const QString &fileName) other->show(); } +static inline bool hasTTISuffix(const QString &filename) +{ + return filename.endsWith(".tti", Qt::CaseInsensitive) || filename.endsWith(".ttix", Qt::CaseInsensitive); +} + bool MainWindow::save() { - return m_isUntitled ? saveAs() : saveFile(m_curFile); + // If imported from non-.tti, force "Save As" so we don't clobber the original imported file + return m_isUntitled || !hasTTISuffix(m_curFile) ? saveAs() : saveFile(m_curFile); } bool MainWindow::saveAs() { - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), m_curFile); + QString suggestedName = m_curFile; + + // If imported from non-.tti, change extension so we don't clobber the original imported file + if (suggestedName.endsWith(".t42", Qt::CaseInsensitive)) { + suggestedName.chop(4); + suggestedName.append(".tti"); + } + + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), suggestedName, "TTI teletext page (*.tti *.ttix)"); if (fileName.isEmpty()) return false;