]> git.lyx.org Git - features.git/commitdiff
Prevent data loss when closing LyX while document dialog has unapplied changes (...
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 5 Nov 2023 11:09:33 +0000 (12:09 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 5 Nov 2023 11:09:33 +0000 (12:09 +0100)
Entails new strings, but I think the severity allows for that.

src/frontends/qt/Dialog.h
src/frontends/qt/DialogView.cpp
src/frontends/qt/DialogView.h
src/frontends/qt/DockView.h
src/frontends/qt/GuiDialog.cpp
src/frontends/qt/GuiDialog.h
src/frontends/qt/GuiDocument.cpp
src/frontends/qt/GuiDocument.h
src/frontends/qt/GuiView.cpp

index be9b3232f7fcaa267c0e389a7fa1c6237b771ce4..6968aea803d299230b2f4fa3c93fb7fe33676fdc 100644 (file)
@@ -267,6 +267,8 @@ protected:
        /// To be called when the buffer view has changed
        virtual void onBufferViewChanged() = 0;
        ///
+       virtual void onClosing(int) = 0;
+       ///
        void connectToNewInset();
 
 private:
index a5e411dedb8965b5a348f3ef41f405e0322113a2..2d778f27eb715eeb721ddb94c0e6471f7924b568 100644 (file)
@@ -25,6 +25,8 @@ DialogView::DialogView(GuiView & lv, QString const & name, QString const & title
 {
        connect(&lv, SIGNAL(bufferViewChanged()),
                this, SLOT(onBufferViewChanged()));
+       connect(&lv, SIGNAL(closing(int)),
+               this, SLOT(onClosing(int)));
 
        // remove question marks from Windows dialogs
        setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
index 514242e92668933ed190981b8454706ddc468caf..81347bde5a839cf18b8c747592632c06f1a79663 100644 (file)
@@ -48,6 +48,7 @@ protected:
 
 protected Q_SLOTS:
        void onBufferViewChanged() override {}
+       void onClosing(int) override {}
 };
 
 } // namespace frontend
index aef0c8281ac0cb2f86a8d7a2daff77f96134f7d4..1a6295446eb3c094c735b978f41a63efc757708f 100644 (file)
@@ -56,6 +56,7 @@ public:
 
 protected Q_SLOTS:
        void onBufferViewChanged() override {}
+       void onClosing(int) override {}
 };
 
 } // namespace frontend
index 186d9ea3a0b22d5e95f9d66281092b6aabb66b28..491cbeca34c90ce0cd1b6dcf77ea8501c78d6431 100644 (file)
@@ -34,6 +34,8 @@ GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
 {
        connect(&lv, SIGNAL(bufferViewChanged()),
                this, SLOT(onBufferViewChanged()));
+       connect(&lv, SIGNAL(closing(int)),
+               this, SLOT(onClosing(int)));
 
        // remove question marks from Windows dialogs
        setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
index bd50df067bc09b2316776dbbb0faf5ad58754f9b..a1681afb53080eb08d71558bbe60f8f4a127c3ee 100644 (file)
@@ -66,6 +66,7 @@ public Q_SLOTS:
 
 protected Q_SLOTS:
        void onBufferViewChanged() override {}
+       void onClosing(int) override {}
 
 public:
        /** Check whether we may apply our data.
index b16e8923bc8ef36a7d3f336f32e21f4889a6802a..bd87d9a38e09cca24fa7e539b8ce43fda8253702 100644 (file)
@@ -1849,6 +1849,23 @@ GuiDocument::GuiDocument(GuiView & lv)
 }
 
 
+void GuiDocument::onClosing(int const id)
+{
+       if (!guiApp || !guiApp->currentView()
+           || guiApp->currentView()->id() != id
+           || !bc().policy().buttonStatus(ButtonPolicy::RESTORE))
+               // notthing to do
+               return;
+
+       int const ret = Alert::prompt(_("Unapplied changes"),
+                       _("Some changes in the document were not yet applied.\n"
+                       "Do you want to apply them before closing?"),
+                       1, 1, _("Yes, &Apply"), _("No, &Dismiss Changes"));
+       if (ret == 0)
+               slotOK();
+}
+
+
 void GuiDocument::onBufferViewChanged()
 {
        if (switchback_) {
@@ -1868,8 +1885,8 @@ void GuiDocument::onBufferViewChanged()
                // Only ask if we haven't yet in this cycle
                int const ret = prompted_ ? 3 : Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the previous document were not yet applied.\n"
-                               "Do you want to switch back and apply them?"),
-                               1, 1, _("Yes, &Switch Back"), _("No, &Dismiss Changes"));
+                               "Do you want to switch back in order to apply them or dismiss the changes?"),
+                               1, 1, _("&Switch Back"), _("&Dismiss Changes"));
                if (ret == 0) {
                        // Switch to previous buffer view and apply
                        switchback_ = true;
index 5b531943cb9c9a14295c53dd8a736a5688f5bef8..c7d0cc06f83064c7fd48edb71e2da839799f2aa3 100644 (file)
@@ -96,6 +96,7 @@ public:
 
 public Q_SLOTS:
        void onBufferViewChanged() override;
+       void onClosing(int) override;
        // OK button clicked
        void slotOK();
        // Apply button clicked
index 47f8230d024c4e028cb21bac07aabc65b095f426..79ffc0a2071f857e55c160fa5f1e07b870d4c4b9 100644 (file)
@@ -1311,6 +1311,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
        // it can happen that this event arrives without selecting the view,
        // e.g. when clicking the close button on a background window.
        setFocus();
+       Q_EMIT closing(id_);
        if (!closeWorkAreaAll()) {
                closing_ = false;
                close_event->ignore();