Add re-export option if .t42 file is loaded or exported

This allows a single keypress or menu click to repeatedly export a subpage
over the same .t42 file, like "Save" does for TTI files. If further teletext
page formats are added in the future this option should remember which
format was exported.

This option is deliberately different from "Save" as .t42 files are only
exported as the current subpage on view, and some metadata stored in TTI
files but not in .t42 files could be lost.

When exporting .t42 files the document is only marked as cleanly saved if it
consisted of a single subpage. Documents of more than one subpage will still
cause a confirmation dialog to be shown if unsaved, as the other subpages
will be lost unless the document is saved again as TTI.
This commit is contained in:
G.K.MacGregor
2023-02-26 17:29:09 +00:00
parent 9bd9f180c2
commit 7493c8f527
2 changed files with 63 additions and 12 deletions

View File

@@ -371,9 +371,16 @@ void MainWindow::createActions()
setRecentFilesVisible(MainWindow::hasRecentFiles()); setRecentFilesVisible(MainWindow::hasRecentFiles());
m_exportAutoAct = fileMenu->addAction(tr("Export subpage..."));
m_exportAutoAct->setEnabled(false);
m_exportAutoAct->setShortcut(tr("Ctrl+E"));
m_exportAutoAct->setStatusTip("Export this subpage back to the imported file");
connect(fileMenu, &QMenu::aboutToShow, this, &MainWindow::updateExportAutoAction);
connect(m_exportAutoAct, &QAction::triggered, this, &MainWindow::exportAuto);
QAction *exportT42Act = fileMenu->addAction(tr("Export subpage as t42...")); QAction *exportT42Act = fileMenu->addAction(tr("Export subpage as t42..."));
exportT42Act->setStatusTip("Export this subpage as a t42 file"); exportT42Act->setStatusTip("Export this subpage as a t42 file");
connect(exportT42Act, &QAction::triggered, this, &MainWindow::exportT42); connect(exportT42Act, &QAction::triggered, this, [=]() { exportT42(false); });
QMenu *exportHashStringSubMenu = fileMenu->addMenu(tr("Export subpage to online editor")); QMenu *exportHashStringSubMenu = fileMenu->addMenu(tr("Export subpage to online editor"));
@@ -934,10 +941,13 @@ void MainWindow::loadFile(const QString &fileName)
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
if (fileInfo.suffix() == "t42") if (fileInfo.suffix() == "t42") {
importT42(&file, m_textWidget->document()); importT42(&file, m_textWidget->document());
else m_exportAutoFileName = fileName;
} else {
loadTTI(&file, m_textWidget->document()); loadTTI(&file, m_textWidget->document());
m_exportAutoFileName.clear();
}
levelSeen = m_textWidget->document()->levelRequired(); levelSeen = m_textWidget->document()->levelRequired();
m_levelRadioButton[levelSeen]->toggle(); m_levelRadioButton[levelSeen]->toggle();
@@ -1021,6 +1031,18 @@ void MainWindow::updateRecentFileActions()
m_recentFileActs[i]->setVisible(false); m_recentFileActs[i]->setVisible(false);
} }
void MainWindow::updateExportAutoAction()
{
if (m_exportAutoFileName.isEmpty()) {
m_exportAutoAct->setText(tr("Export subpage..."));
m_exportAutoAct->setEnabled(false);
return;
}
m_exportAutoAct->setText(tr("Overwrite &%1").arg(MainWindow::strippedName(m_exportAutoFileName)));
m_exportAutoAct->setEnabled(true);
}
void MainWindow::openRecentFile() void MainWindow::openRecentFile()
{ {
if (const QAction *action = qobject_cast<const QAction *>(sender())) if (const QAction *action = qobject_cast<const QAction *>(sender()))
@@ -1051,16 +1073,30 @@ bool MainWindow::saveFile(const QString &fileName)
return true; return true;
} }
void MainWindow::exportT42() void MainWindow::exportAuto()
{
// Menu should be disabled if m_exportAutoFileName is empty, but just in case...
if (m_exportAutoFileName.isEmpty())
return;
exportT42(true);
}
void MainWindow::exportT42(bool fromAuto)
{ {
QString errorMessage; QString errorMessage;
QString exportFileName = m_curFile; QString exportFileName;
if (fromAuto)
exportFileName = m_exportAutoFileName;
else {
exportFileName = m_curFile;
changeSuffixFromTTI(exportFileName, "t42"); changeSuffixFromTTI(exportFileName, "t42");
exportFileName = QFileDialog::getSaveFileName(this, tr("Export t42"), exportFileName, "t42 stream (*.t42)"); exportFileName = QFileDialog::getSaveFileName(this, tr("Export t42"), exportFileName, "t42 stream (*.t42)");
if (exportFileName.isEmpty()) if (exportFileName.isEmpty())
return; return;
}
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
QSaveFile file(exportFileName); QSaveFile file(exportFileName);
@@ -1072,8 +1108,20 @@ void MainWindow::exportT42()
errorMessage = tr("Cannot open file %1 for writing:\n%2.").arg(QDir::toNativeSeparators(exportFileName), file.errorString()); errorMessage = tr("Cannot open file %1 for writing:\n%2.").arg(QDir::toNativeSeparators(exportFileName), file.errorString());
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty()) {
QMessageBox::warning(this, QApplication::applicationDisplayName(), errorMessage); QMessageBox::warning(this, QApplication::applicationDisplayName(), errorMessage);
return;
}
// Only mark as cleanly saved if the document was a single subpage
// otherwise the other subpages could be lost if not saved as TTI
if (m_textWidget->document()->numberOfSubPages() == 1) {
setCurrentFile(exportFileName);
} else
MainWindow::prependToRecentFiles(exportFileName);
m_exportAutoFileName = exportFileName;
statusBar()->showMessage(tr("File exported"), 2000);
} }
void MainWindow::exportM29() void MainWindow::exportM29()

View File

@@ -60,12 +60,14 @@ private slots:
bool save(); bool save();
bool saveAs(); bool saveAs();
void reload(); void reload();
void exportT42(); void exportAuto();
void exportT42(bool);
void exportZXNet(); void exportZXNet();
void exportEditTF(); void exportEditTF();
void exportPNG(); void exportPNG();
void exportM29(); void exportM29();
void updateRecentFileActions(); void updateRecentFileActions();
void updateExportAutoAction();
void openRecentFile(); void openRecentFile();
void about(); void about();
void updatePageWidgets(); void updatePageWidgets();
@@ -121,6 +123,7 @@ private:
QAction *m_recentFileActs[m_MaxRecentFiles]; QAction *m_recentFileActs[m_MaxRecentFiles];
QAction *m_recentFileSeparator; QAction *m_recentFileSeparator;
QAction *m_recentFileSubMenuAct; QAction *m_recentFileSubMenuAct;
QAction *m_exportAutoAct;
QAction *m_deleteSubPageAction; QAction *m_deleteSubPageAction;
QAction *m_borderActs[3]; QAction *m_borderActs[3];
QAction *m_aspectRatioActs[4]; QAction *m_aspectRatioActs[4];
@@ -131,7 +134,7 @@ private:
QPushButton *m_insertModePushButton; QPushButton *m_insertModePushButton;
QRadioButton *m_levelRadioButton[4]; QRadioButton *m_levelRadioButton[4];
QString m_curFile; QString m_curFile, m_exportAutoFileName;
bool m_isUntitled; bool m_isUntitled;
}; };