Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 34140e96 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MISC: The getCurrentDocument and getCurrentDocumentView now throw errors...

MISC: The getCurrentDocument and getCurrentDocumentView now throw errors instead of returning nullptr => uniform API
parent 56b0e667
Branches
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
...@@ -211,24 +211,18 @@ MainWindow::openDialogHelp() noexcept ...@@ -211,24 +211,18 @@ MainWindow::openDialogHelp() noexcept
} }
AbstractDocument * AbstractDocument *
MainWindow::getCurrentDocument() const noexcept MainWindow::getCurrentDocument() const
{ {
try {
return getCurrentDocumentView()->getDocument(); return getCurrentDocumentView()->getDocument();
} catch (const std::runtime_error &e) {
qCritical() << "No current view in the main window:" << e.what();
return nullptr;
}
} }
void void
MainWindow::saveFile() noexcept MainWindow::saveFile() noexcept
{ {
try { try {
if (auto document = getCurrentDocument()) { auto document = getCurrentDocument();
qDebug() << "Request to save the document" << document->getName(); qDebug() << "Request to save the document" << document->getName();
document->save(); document->save();
}
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what(); qCritical() << "Failed to save current document:" << e.what();
} }
...@@ -238,7 +232,7 @@ void ...@@ -238,7 +232,7 @@ void
MainWindow::saveFileAs() noexcept MainWindow::saveFileAs() noexcept
{ {
try { try {
if (auto document = getCurrentDocument()) { auto document = getCurrentDocument();
qDebug() << "Request to save the document" << document->getName(); qDebug() << "Request to save the document" << document->getName();
const QString filename = const QString filename =
dialogSaveFileName("Select the target file to save into", QDir::homePath(), dialogSaveFileName("Select the target file to save into", QDir::homePath(),
...@@ -249,7 +243,6 @@ MainWindow::saveFileAs() noexcept ...@@ -249,7 +243,6 @@ MainWindow::saveFileAs() noexcept
document->rename(filename); document->rename(filename);
document->save(); document->save();
} }
}
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what(); qCritical() << "Failed to save current document:" << e.what();
} }
......
...@@ -29,14 +29,14 @@ class MainWindow final : public QMainWindow { ...@@ -29,14 +29,14 @@ class MainWindow final : public QMainWindow {
public: public:
explicit MainWindow() noexcept; explicit MainWindow() noexcept;
AbstractDocument *getCurrentDocument() const noexcept; AbstractDocument *getCurrentDocument() const;
template <class Document> Document *getCurrentDocument() const noexcept template <class Document> Document *getCurrentDocument() const
{ {
if (AbstractDocumentView *currentView = getCurrentDocumentView(); if (AbstractDocumentView *currentView = getCurrentDocumentView();
currentView->getType() == Document::type) { currentView->getType() == Document::type) {
return currentView->getDocument(); return currentView->getDocument();
} else { } else {
return nullptr; throw std::runtime_error("No main document view was found");
} }
} }
......
...@@ -74,6 +74,9 @@ VivyDocumentView::getDocumentTabToolTip() const noexcept ...@@ -74,6 +74,9 @@ VivyDocumentView::getDocumentTabToolTip() const noexcept
QStringLiteral("}") + QStringLiteral("}") +
(document->checkDocumentOption(VivyDocument::UntouchedByDefault) (document->checkDocumentOption(VivyDocument::UntouchedByDefault)
? QStringLiteral("\nUntouched document") ? QStringLiteral("\nUntouched document")
: QStringLiteral("")) +
(document->checkDocumentOption(VivyDocument::MemoryDocumentCreation)
? QStringLiteral("\nMemory document")
: QStringLiteral("")); : QStringLiteral(""));
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter