[LyX/master] Partially fix bug #10827. Patch from Daniel, slightly modified by me.

Richard Kimberly Heck rikiheck at lyx.org
Sun Dec 4 02:48:46 UTC 2022


commit 233ce1ec12db9a0cd9c7cccd246aae05dc787836
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Sat Dec 3 22:41:26 2022 -0500

    Partially fix bug #10827. Patch from Daniel, slightly modified by me.
---
 src/frontends/qt/GuiDialog.cpp   |    8 +++++++-
 src/frontends/qt/GuiDialog.h     |    7 +++++++
 src/frontends/qt/GuiDocument.cpp |   18 +++++++++++-------
 src/frontends/qt/GuiDocument.h   |    2 +-
 4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/frontends/qt/GuiDialog.cpp b/src/frontends/qt/GuiDialog.cpp
index 3426c79..70d086c 100644
--- a/src/frontends/qt/GuiDialog.cpp
+++ b/src/frontends/qt/GuiDialog.cpp
@@ -27,7 +27,7 @@ namespace frontend {
 
 GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
 	: QDialog(&lv), Dialog(lv, name, title), updating_(false),
-	  is_closing_(false)
+      is_closing_(false), apply_stopped_(false)
 {
 	connect(&lv, SIGNAL(bufferViewChanged()),
 	        this, SLOT(onBufferViewChanged()));
@@ -52,7 +52,10 @@ void GuiDialog::setButtonsValid(bool valid)
 
 void GuiDialog::slotApply()
 {
+	setApplyStopped(false);
 	apply();
+	if (applyStopped())
+		return;
 	bc().apply();
 }
 
@@ -67,7 +70,10 @@ void GuiDialog::slotAutoApply()
 void GuiDialog::slotOK()
 {
 	is_closing_ = true;
+	setApplyStopped(false);
 	apply();
+	if (applyStopped())
+		return;
 	is_closing_ = false;
 	hideView();
 	bc().ok();
diff --git a/src/frontends/qt/GuiDialog.h b/src/frontends/qt/GuiDialog.h
index 572ff53..160357d 100644
--- a/src/frontends/qt/GuiDialog.h
+++ b/src/frontends/qt/GuiDialog.h
@@ -74,6 +74,9 @@ public:
 	 */
 	void setButtonsValid(bool valid);
 
+	// Set whether to stop the apply process
+	void setApplyStopped(bool stop) { apply_stopped_ = stop; };
+
 	/** \name Dialog Components
 	 *  Methods to access the various components making up a dialog.
 	 */
@@ -115,6 +118,10 @@ private:
 	bool updating_;
 
 	bool is_closing_;
+
+	/// stop the apply process?
+	bool applyStopped() { return apply_stopped_; };
+	bool apply_stopped_;
 };
 
 
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 83581d0..6da810f 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -657,23 +657,18 @@ void LocalLayout::hideConvert()
 
 void LocalLayout::textChanged()
 {
-	// Flashy red bold text
-	static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; text-align:left\">"
-				   "%1</p>");
-	static const QString message = ivpar.arg(qt_("Validation required!"));
+	validLB->setText("");
 	string const layout =
 		fromqstr(locallayoutTE->document()->toPlainText().trimmed());
 
 	if (layout.empty()) {
 		validated_ = true;
 		validatePB->setEnabled(false);
-		validLB->setText("");
 		hideConvert();
 		changed();
 	} else if (!validatePB->isEnabled()) {
 		// if that's already enabled, we shouldn't need to do anything.
 		validated_ = false;
-		validLB->setText(message);
 		validatePB->setEnabled(true);
 		hideConvert();
 		changed();
@@ -3418,6 +3413,16 @@ bool GuiDocument::isChildIncluded(string const & child)
 
 void GuiDocument::applyView()
 {
+	// auto-validate local layout
+	if (!localLayout->isValid()) {
+		localLayout->validate();
+		if (!localLayout->isValid()) {
+			setApplyStopped(true);
+			docPS->setCurrentPanel(N_("Local Layout"));
+			return;
+		}
+	}
+
 	// preamble
 	preambleModule->apply(bp_);
 	localLayout->apply(bp_);
@@ -4849,7 +4854,6 @@ bool GuiDocument::isValid()
 {
 	return
 		validateListingsParameters().isEmpty() &&
-		localLayout->isValid() &&
 		!localLayout->editing() &&
 		!preambleModule->editing() &&
 		(
diff --git a/src/frontends/qt/GuiDocument.h b/src/frontends/qt/GuiDocument.h
index b6a51c5..5d06226 100644
--- a/src/frontends/qt/GuiDocument.h
+++ b/src/frontends/qt/GuiDocument.h
@@ -388,6 +388,7 @@ public:
 	LocalLayout(QWidget * parent);
 	void update(BufferParams const & params, BufferId id);
 	void apply(BufferParams & params);
+	void validate();
 	bool isValid() const { return validated_; }
 	bool editing() const { return (bool)tempfile_; }
 
@@ -396,7 +397,6 @@ Q_SIGNALS:
 	void changed();
 
 private:
-	void validate();
 	void convert();
 	void hideConvert();
 private Q_SLOTS:


More information about the lyx-cvs mailing list