Hi,

I did not know there is a virutal bool isValid() function that can be
used to determine if 'OK' should be enabled in DialogView. Clearly,
isValid should be defined in QListings, QInclude etc, and calls
validate_listings_parameter. A proper fix to bug 4053 should follow
the attached patch.

Jurgen, I would appreciate it if you can finish the patch (apply to
three listings-related dialogs). Otherwise, I can do it over the
weekend.

Thanks.
Bo
Index: src/frontends/qt4/QListings.h
===================================================================
--- src/frontends/qt4/QListings.h	(revision 19162)
+++ src/frontends/qt4/QListings.h	(working copy)
@@ -29,11 +29,13 @@
 	QListingsDialog(QListings * form);
 	/// get values from all the widgets and form a string
 	std::string construct_params();
+	///
+	docstring validate_listings_params();
 protected Q_SLOTS:
 	virtual void change_adaptor();
 	/// AFAIK, QValidator only works for QLineEdit so
 	/// I have to validate listingsED (QTextEdit) manually.
-	void validate_listings_params();
+	void set_listings_hint();
 	/// turn off inline when float is clicked
 	void on_floatCB_stateChanged(int state);
 	/// turn off float when inline is clicked
@@ -63,6 +65,9 @@
 	virtual void update_contents();
 	/// build the dialog
 	virtual void build_dialog();
+protected:
+	/// 
+	virtual bool isValid();
 };
 
 } // namespace frontend
Index: src/frontends/qt4/QListings.cpp
===================================================================
--- src/frontends/qt4/QListings.cpp	(revision 19162)
+++ src/frontends/qt4/QListings.cpp	(working copy)
@@ -190,9 +190,9 @@
 	connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
 
 	connect(listingsED,  SIGNAL(textChanged()), this, SLOT(change_adaptor()));
-	connect(listingsED,  SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
+	connect(listingsED,  SIGNAL(textChanged()), this, SLOT(set_listings_hint()));
 	connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-	connect(bypassCB, SIGNAL(clicked()), this, SLOT(validate_listings_params()));
+	connect(bypassCB, SIGNAL(clicked()), this, SLOT(set_listings_hint()));
 
 	for (int n = 0; languages[n][0]; ++n)
 		languageCO->addItem(qt_(languages_gui[n]));
@@ -319,26 +319,29 @@
 }
 
 
-void QListingsDialog::validate_listings_params()
+docstring QListingsDialog::validate_listings_params()
 {
-	static bool isOK = true;
 	InsetListingsParams par(construct_params());
 	docstring msg;
 	if (!bypassCB->isChecked())
 		msg = par.validate();
+	return msg;
+}
+
+
+void QListingsDialog::set_listings_hint()
+{
+	static bool isOK = true;
+	docstring msg = validate_listings_params();
 	if (msg.empty()) {
 		if (isOK)
 			return;
 		isOK = true;
 		listingsTB->setPlainText(
 			qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
-		okPB->setEnabled(true);
-		applyPB->setEnabled(true);
 	} else {
 		isOK = false;
 		listingsTB->setPlainText(toqstr(msg));
-		okPB->setEnabled(false);
-		applyPB->setEnabled(false);
 	}
 }
 
@@ -601,6 +604,12 @@
 }
 
 
+bool QListings::isValid()
+{
+	return dialog_->validate_listings_params().empty();
+}
+
+
 } // namespace frontend
 } // namespace lyx
 

Reply via email to