mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
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:
parent
75a08df529
commit
ec2da3a509
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -48,6 +48,7 @@ protected:
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onBufferViewChanged() override {}
|
||||
void onClosing(int) override {}
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onBufferViewChanged() override {}
|
||||
void onClosing(int) override {}
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
|
||||
public Q_SLOTS:
|
||||
void onBufferViewChanged() override;
|
||||
void onClosing(int) override;
|
||||
// OK button clicked
|
||||
void slotOK();
|
||||
// Apply button clicked
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user