diff --git a/src/Document/VivyDocumentStore.cc b/src/Document/VivyDocumentStore.cc index 67732cb55fc8d2207cf55a66e6db3de6ed2d997d..07c4fd8b336f88bb3f93cbf26217372c4432cf5d 100644 --- a/src/Document/VivyDocumentStore.cc +++ b/src/Document/VivyDocumentStore.cc @@ -32,6 +32,12 @@ VivyDocumentStore::loadDocument(const QString &file) noexcept return ret; } +bool +VivyDocumentStore::isDocumentPresent(const QString &name) noexcept +{ + return documents.count(name) >= 1; +} + VivyDocument * VivyDocumentStore::newDocument([[maybe_unused]] const QString &name) noexcept { diff --git a/src/Document/VivyDocumentStore.h b/src/Document/VivyDocumentStore.h index b4aee533ad9d5797b7470eb34f650759d037d5d0..b7e9c2cbcbfc8123a90abfddf51110bd5d7dec37 100644 --- a/src/Document/VivyDocumentStore.h +++ b/src/Document/VivyDocumentStore.h @@ -22,6 +22,9 @@ public: [[nodiscard("allocated")]] VivyDocument *loadDocument(const QString &file) noexcept; [[nodiscard("allocated")]] VivyDocument *newDocument(const QString &name) noexcept; + /* Get to see if a document is already present or not */ + [[nodiscard("handle-it")]] bool isDocumentPresent(const QString &name) noexcept; + /* Close a document, please be sure to not used any of the dangling * references to the closed document... */ void closeDocument(const QString &name) noexcept; diff --git a/src/MainWindow.cc b/src/MainWindow.cc index f32f54a529f6bacff8945e7a9c99088daab4c07f..e2d7edd09481394f9ad6f4e209f6b073913b8586 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) noexcept documents->setTabsClosable(true); documents->setElideMode(Qt::ElideRight); documents->setUsesScrollButtons(true); + documents->setDocumentMode(true); connect(documents, &QTabWidget::tabCloseRequested, this, &MainWindow::closeDocument); setCentralWidget(documents); @@ -75,6 +76,11 @@ MainWindow::openDocument() noexcept } QFileInfo fileInfo(filename); + const QString baseName = fileInfo.baseName(); + if (documentStore.isDocumentPresent(baseName)) { + qWarning() << "The document " << baseName << " is already loaded"; + return; + } qDebug() << "Trying to open file " << filename; VivyDocument *document = documentStore.loadDocument(filename);