Change to .tti suffix when saving imported file

This commit is contained in:
G.K.MacGregor
2021-08-17 18:40:57 +01:00
parent 1e943c3f26
commit e466ef2afe

View File

@@ -108,14 +108,28 @@ void MainWindow::openFile(const QString &fileName)
other->show(); other->show();
} }
static inline bool hasTTISuffix(const QString &filename)
{
return filename.endsWith(".tti", Qt::CaseInsensitive) || filename.endsWith(".ttix", Qt::CaseInsensitive);
}
bool MainWindow::save() 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() 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()) if (fileName.isEmpty())
return false; return false;