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

DOCUMENT: Add the current document for the window to help the save operations

parent 0ba0a39f
Branches
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "MainWindow.hh" #include "MainWindow.hh"
#include "DialogHelp.hh" #include "DialogHelp.hh"
#include "VivyDocumentView.hh" #include "VivyDocumentView.hh"
#include "Utils.hh"
#include <QFileInfo> #include <QFileInfo>
#include <QStandardPaths> #include <QStandardPaths>
...@@ -47,11 +48,25 @@ MainWindow::openDialogHelp() noexcept ...@@ -47,11 +48,25 @@ MainWindow::openDialogHelp() noexcept
void void
MainWindow::saveFile() noexcept 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 void
MainWindow::saveFileAs() noexcept 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 void
...@@ -100,3 +115,13 @@ MainWindow::openDocument() noexcept ...@@ -100,3 +115,13 @@ MainWindow::openDocument() noexcept
throw; 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");
}
...@@ -25,6 +25,8 @@ public: ...@@ -25,6 +25,8 @@ public:
explicit MainWindow(VivyApplication *) noexcept; explicit MainWindow(VivyApplication *) noexcept;
~MainWindow() noexcept = default; ~MainWindow() noexcept = default;
std::weak_ptr<VivyDocument> getCurrentDocument() const;
private slots: private slots:
void openDocument() noexcept; void openDocument() noexcept;
void closeDocument(int index) noexcept; void closeDocument(int index) noexcept;
......
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