Add reload from disk

This is typically mapped to the F5 key, so the "secret force refresh"
key has been temporarily moved to F6.
This commit is contained in:
G.K.MacGregor
2022-07-17 15:16:53 +01:00
parent a8f2152c92
commit abf649d2ab
5 changed files with 55 additions and 1 deletions

View File

@@ -94,6 +94,25 @@ bool TeletextDocument::isEmpty() const
return true;
}
void TeletextDocument::clear()
{
LevelOnePage *blankSubPage = new LevelOnePage;
m_subPages.insert(m_subPages.begin(), blankSubPage);
emit aboutToChangeSubPage();
m_currentSubPageIndex = 0;
m_clutModel->setSubPage(m_subPages[0]);
emit subPageSelected();
cancelSelection();
m_undoStack->clear();
for (int i=m_subPages.size()-1; i>0; i--) {
delete(m_subPages[i]);
m_subPages.erase(m_subPages.begin()+i);
}
}
/*
void TeletextDocument::setPageFunction(PageFunctionEnum newPageFunction)
{

View File

@@ -56,6 +56,7 @@ public:
~TeletextDocument();
bool isEmpty() const;
void clear();
PageFunctionEnum pageFunction() const { return m_pageFunction; }
// void setPageFunction(PageFunctionEnum);

View File

@@ -386,7 +386,7 @@ void TeletextWidget::keyPressEvent(QKeyEvent *event)
case Qt::Key_PageDown:
m_teletextDocument->selectSubPagePrevious();
break;
case Qt::Key_F5:
case Qt::Key_F6:
m_pageDecode.decodePage();
m_pageRender.renderPage(true);
update();

View File

@@ -149,6 +149,34 @@ bool MainWindow::saveAs()
return saveFile(fileName);
}
void MainWindow::reload()
{
if (m_isUntitled)
return;
if (!m_textWidget->document()->undoStack()->isClean()) {
const QMessageBox::StandardButton ret = QMessageBox::warning(this, QApplication::applicationDisplayName(), tr("The document \"%1\" has been modified.\nDo you want to discard your changes?").arg(QFileInfo(m_curFile).fileName()), QMessageBox::Discard | QMessageBox::Cancel);
if (ret != QMessageBox::Discard)
return;
} else {
const QMessageBox::StandardButton ret = QMessageBox::warning(this, QApplication::applicationDisplayName(), tr("Do you want to reload the document \"%1\" from disk?").arg(QFileInfo(m_curFile).fileName()), QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes)
return;
}
int subPageIndex = m_textWidget->document()->currentSubPageIndex();
m_textWidget->document()->clear();
loadFile(m_curFile);
if (subPageIndex >= m_textWidget->document()->numberOfSubPages())
subPageIndex = m_textWidget->document()->numberOfSubPages()-1;
m_textWidget->document()->selectSubPageIndex(subPageIndex, true);
}
void MainWindow::exportPNG()
{
QString exportFileName = QFileDialog::getSaveFileName(this, tr("Export PNG"), QString(), "PNG image (*.png)");
@@ -328,6 +356,11 @@ void MainWindow::createActions()
saveAsAct->setShortcuts(QKeySequence::SaveAs);
saveAsAct->setStatusTip(tr("Save the document under a new name"));
const QIcon reloadIcon = QIcon::fromTheme("document-revert");
QAction *reloadAct = fileMenu->addAction(reloadIcon, tr("Reload"), this, &MainWindow::reload);
reloadAct->setShortcuts(QKeySequence::Refresh);
reloadAct->setStatusTip(tr("Reload the document from disk"));
fileMenu->addSeparator();
QMenu *recentMenu = fileMenu->addMenu(tr("Recent"));

View File

@@ -59,6 +59,7 @@ private slots:
void open();
bool save();
bool saveAs();
void reload();
void exportT42();
void exportZXNet();
void exportEditTF();