diff --git a/src/MainWindow.cc b/src/MainWindow.cc index ae85a01d72d317a87e1fea31162e527cb9210d20..2f1c36adaadfb3ecb93f9b0f748b2e3b4c4d44b7 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -3,6 +3,7 @@ #include "MainWindow.hh" #include "DialogHelp.hh" #include "VivyDocumentView.hh" +#include "Utils.hh" #include <QFileInfo> #include <QStandardPaths> @@ -47,11 +48,25 @@ MainWindow::openDialogHelp() noexcept void MainWindow::saveFile() noexcept { + try { + if (auto document = getCurrentDocument().lock()) { + qDebug() << "Request to save the document" << document->getName(); + } + } catch (const std::runtime_error &e) { + qCritical() << "Failed to save current document:" << e.what(); + } } void MainWindow::saveFileAs() noexcept { + try { + if (auto document = getCurrentDocument().lock()) { + qDebug() << "Request to save the document" << document->getName(); + } + } catch (const std::runtime_error &e) { + qCritical() << "Failed to save current document:" << e.what(); + } } void @@ -100,3 +115,13 @@ MainWindow::openDocument() noexcept throw; } } + +std::weak_ptr<VivyDocument> +MainWindow::getCurrentDocument() const +{ + VivyDocumentView *currentView = reinterpret_cast<VivyDocumentView *>(documents->currentWidget()); + if (currentView) + return currentView->getDocument(); + else + throw std::runtime_error("no current document"); +} diff --git a/src/MainWindow.hh b/src/MainWindow.hh index 3cf488231c93a88a6643d0f2e7bc7e613f5889f9..23b5adbe8452d5a9dc7520b747541b65d48ffc53 100644 --- a/src/MainWindow.hh +++ b/src/MainWindow.hh @@ -25,6 +25,8 @@ public: explicit MainWindow(VivyApplication *) noexcept; ~MainWindow() noexcept = default; + std::weak_ptr<VivyDocument> getCurrentDocument() const; + private slots: void openDocument() noexcept; void closeDocument(int index) noexcept;