Prevent data loss when closing LyX while document dialog has unapplied changes (#12955)

Entails new strings, but I think the severity allows for that.
This commit is contained in:
Juergen Spitzmueller 2023-11-05 12:09:33 +01:00
parent 75a08df529
commit ec2da3a509
9 changed files with 30 additions and 2 deletions

View File

@ -267,6 +267,8 @@ protected:
/// To be called when the buffer view has changed /// To be called when the buffer view has changed
virtual void onBufferViewChanged() = 0; virtual void onBufferViewChanged() = 0;
/// ///
virtual void onClosing(int) = 0;
///
void connectToNewInset(); void connectToNewInset();
private: private:

View File

@ -25,6 +25,8 @@ DialogView::DialogView(GuiView & lv, QString const & name, QString const & title
{ {
connect(&lv, SIGNAL(bufferViewChanged()), connect(&lv, SIGNAL(bufferViewChanged()),
this, SLOT(onBufferViewChanged())); this, SLOT(onBufferViewChanged()));
connect(&lv, SIGNAL(closing(int)),
this, SLOT(onClosing(int)));
// remove question marks from Windows dialogs // remove question marks from Windows dialogs
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

View File

@ -48,6 +48,7 @@ protected:
protected Q_SLOTS: protected Q_SLOTS:
void onBufferViewChanged() override {} void onBufferViewChanged() override {}
void onClosing(int) override {}
}; };
} // namespace frontend } // namespace frontend

View File

@ -56,6 +56,7 @@ public:
protected Q_SLOTS: protected Q_SLOTS:
void onBufferViewChanged() override {} void onBufferViewChanged() override {}
void onClosing(int) override {}
}; };
} // namespace frontend } // namespace frontend

View File

@ -34,6 +34,8 @@ GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
{ {
connect(&lv, SIGNAL(bufferViewChanged()), connect(&lv, SIGNAL(bufferViewChanged()),
this, SLOT(onBufferViewChanged())); this, SLOT(onBufferViewChanged()));
connect(&lv, SIGNAL(closing(int)),
this, SLOT(onClosing(int)));
// remove question marks from Windows dialogs // remove question marks from Windows dialogs
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

View File

@ -66,6 +66,7 @@ public Q_SLOTS:
protected Q_SLOTS: protected Q_SLOTS:
void onBufferViewChanged() override {} void onBufferViewChanged() override {}
void onClosing(int) override {}
public: public:
/** Check whether we may apply our data. /** Check whether we may apply our data.

View 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() void GuiDocument::onBufferViewChanged()
{ {
if (switchback_) { if (switchback_) {
@ -1868,8 +1885,8 @@ void GuiDocument::onBufferViewChanged()
// Only ask if we haven't yet in this cycle // Only ask if we haven't yet in this cycle
int const ret = prompted_ ? 3 : Alert::prompt(_("Unapplied changes"), int const ret = prompted_ ? 3 : Alert::prompt(_("Unapplied changes"),
_("Some changes in the previous document were not yet applied.\n" _("Some changes in the previous document were not yet applied.\n"
"Do you want to switch back and apply them?"), "Do you want to switch back in order to apply them or dismiss the changes?"),
1, 1, _("Yes, &Switch Back"), _("No, &Dismiss Changes")); 1, 1, _("&Switch Back"), _("&Dismiss Changes"));
if (ret == 0) { if (ret == 0) {
// Switch to previous buffer view and apply // Switch to previous buffer view and apply
switchback_ = true; switchback_ = true;

View File

@ -96,6 +96,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
void onBufferViewChanged() override; void onBufferViewChanged() override;
void onClosing(int) override;
// OK button clicked // OK button clicked
void slotOK(); void slotOK();
// Apply button clicked // Apply button clicked

View File

@ -1311,6 +1311,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
// it can happen that this event arrives without selecting the view, // it can happen that this event arrives without selecting the view,
// e.g. when clicking the close button on a background window. // e.g. when clicking the close button on a background window.
setFocus(); setFocus();
Q_EMIT closing(id_);
if (!closeWorkAreaAll()) { if (!closeWorkAreaAll()) {
closing_ = false; closing_ = false;
close_event->ignore(); close_event->ignore();