My patch to allow "spaces in file names" or not depending on LaTeX's
abilities has become quite large simply because I've also removed a heap
of bloat. I've decided, therefore, to split the patch into two.

This patch, part I, changes nothing in LyX's operation. Well actually,
that's not quite true; it enables the Qt Alert dialogs to know who their
parent is so that dialogs are stacked in the correct order.

The patch is primarily a clean-up however. It:
* replaces 6 (SIX!) identical functions with a single one.
* introduces, but does not yet use a new PathValidator class to the Qt
frontend.

Ok to commit?

-- 
Angus
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.479
diff -u -p -r1.479 ChangeLog
--- src/frontends/controllers/ChangeLog	8 May 2005 10:02:37 -0000	1.479
+++ src/frontends/controllers/ChangeLog	12 May 2005 18:02:30 -0000
@@ -1,3 +1,8 @@
+2005-05-08  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* Kernel.h (KernelDocType): wrapper class for the Kernel::DocTypes
+	enum.
+
 2005-05-07  Michael Schmitt  <[EMAIL PROTECTED]>
 
 	* ControlRef.C: rename LFUN_REF_GOTO to LFUN_LABEL_GOTO
Index: src/frontends/controllers/Kernel.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/Kernel.C,v
retrieving revision 1.13
diff -u -p -r1.13 Kernel.C
--- src/frontends/controllers/Kernel.C	8 Nov 2004 10:54:28 -0000	1.13
+++ src/frontends/controllers/Kernel.C	12 May 2005 18:02:30 -0000
@@ -69,7 +69,7 @@ string const Kernel::bufferFilepath() co
 }
 
 
-Kernel::DocTypes Kernel::docType() const
+Kernel::DocType Kernel::docType() const
 {
 	if (buffer().isLatex())
 		return LATEX;
Index: src/frontends/controllers/Kernel.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/Kernel.h,v
retrieving revision 1.14
diff -u -p -r1.14 Kernel.h
--- src/frontends/controllers/Kernel.h	13 Apr 2005 09:43:58 -0000	1.14
+++ src/frontends/controllers/Kernel.h	12 May 2005 18:02:30 -0000
@@ -64,18 +64,18 @@ public:
 	std::string const bufferFilepath() const;
 	//@}
 
-	/** \enum DocTypes used to flag the different kinds of buffer
+	/** \enum DocType used to flag the different kinds of buffer
 	 *  without making the kernel header files available to the
 	 *  dialog's Controller or View.
 	 */
-	enum DocTypes {
+	enum DocType {
 		LATEX,
 		LITERATE,
 		LINUXDOC,
 		DOCBOOK
 	};
 	/// The type of the current buffer.
-	DocTypes docType() const;
+	DocType docType() const;
 
 	/** A request that the GUI be redrawn,
 	 *  e.g. because the colors have been remapped.
@@ -99,6 +99,19 @@ public:
 
 private:
 	LyXView & lyxview_;
+};
+
+
+/** \c KernelDocType is a wrapper for Kernel::DocType.
+ *  It can be forward-declared and passed as a function argument without
+ *  having to expose Kernel.h.
+ */
+class KernelDocType {
+public:
+	KernelDocType(Kernel::DocType val) : val_(val) {}
+	operator Kernel::DocType() const { return val_; }
+private:
+	Kernel::DocType val_;
 };
 
 } // namespace frontend
Index: src/frontends/qt2/Alert_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Alert_pimpl.C,v
retrieving revision 1.26
diff -u -p -r1.26 Alert_pimpl.C
--- src/frontends/qt2/Alert_pimpl.C	5 Oct 2004 10:11:40 -0000	1.26
+++ src/frontends/qt2/Alert_pimpl.C	12 May 2005 18:02:31 -0000
@@ -18,6 +18,7 @@
 
 #include "gettext.h"
 
+#include <qapplication.h>
 #include <qmessagebox.h>
 #include <qlabel.h>
 #include <qlineedit.h>
@@ -37,9 +38,16 @@ int prompt_pimpl(string const & tit, str
 {
 	string const title = bformat(_("LyX: %1$s"), tit);
 
-	int res = QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
-		toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
-		default_button, cancel_button);
+	QWidget * const parent = qApp->focusWidget() ?
+		qApp->focusWidget() : qApp->mainWidget();
+
+	int res = QMessageBox::information(parent,
+					   toqstr(title),
+					   toqstr(formatted(question)),
+					   toqstr(b1),
+					   toqstr(b2),
+					   b3.empty() ? QString::null : toqstr(b3),
+					   default_button, cancel_button);
 
 	// Qt bug: can return -1 on cancel or WM close, despite the docs.
 	if (res == -1)
@@ -50,30 +58,48 @@ int prompt_pimpl(string const & tit, str
 
 void warning_pimpl(string const & tit, string const & message)
 {
+	QWidget * const parent = qApp->focusWidget() ?
+		qApp->focusWidget() : qApp->mainWidget();
+
 	string const title = bformat(_("LyX: %1$s"), tit);
-	QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
+	QMessageBox::warning(parent,
+			     toqstr(title),
+			     toqstr(formatted(message)));
 }
 
 
 void error_pimpl(string const & tit, string const & message)
 {
+	QWidget * const parent = qApp->focusWidget() ?
+		qApp->focusWidget() : qApp->mainWidget();
+
 	string const title = bformat(_("LyX: %1$s"), tit);
-	QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
+	QMessageBox::critical(parent,
+			      toqstr(title),
+			      toqstr(formatted(message)));
 }
 
 
 void information_pimpl(string const & tit, string const & message)
 {
+	QWidget * const parent = qApp->focusWidget() ?
+		qApp->focusWidget() : qApp->mainWidget();
+
 	string const title = bformat(_("LyX: %1$s"), tit);
-	QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
+	QMessageBox::information(parent,
+				 toqstr(title),
+				 toqstr(formatted(message)));
 }
 
 
 pair<bool, string> const
 askForText_pimpl(string const & msg, string const & dflt)
 {
+	QWidget * const parent = qApp->focusWidget() ?
+		qApp->focusWidget() : qApp->mainWidget();
+
 	string const title = bformat(_("LyX: %1$s"), msg);
-	QAskForTextDialog d(0, toqstr(title), true);
+	QAskForTextDialog d(parent, toqstr(title), true);
 	// less than ideal !
 	d.askLA->setText(toqstr('&' + msg));
 	d.askLE->setText(toqstr(dflt));
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.776
diff -u -p -r1.776 ChangeLog
--- src/frontends/qt2/ChangeLog	12 May 2005 10:16:04 -0000	1.776
+++ src/frontends/qt2/ChangeLog	12 May 2005 18:02:36 -0000
@@ -1,3 +1,22 @@
+2005-05-07  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* Alert_pimpl.C (prompt_pimpl, warning_pimpl, error_pimpl) 
+	(information_pimpl, askForText_pimpl): make these warning dialogs
+	modal with respect to the calling dialog, rather than with respect
+	to the main window.
+
+	* lengthvalidator.[Ch]: removed.
+	* validators.[Ch]: added.
+	* Makefile.dialogs: remove lengthvalidator.[Ch]. Add validators.[Ch].
+
+	* QBoxDialog.C (unsignedLengthValidator):
+	* QDocumentDialog.C (unsignedLengthValidator):
+	* QExternalDialog.C (unsignedLengthValidator):
+	* QGraphicsDialog.C (unsignedLengthValidator):
+	* QTabularDialog.C (unsignedLengthValidator):
+	* QVSpaceDialog.C (unsignedLengthValidator):
+	removed. Use the version in validators.C.
+
 2005-05-12  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* QLPopupMenu.C (fire): use lyx_gui::sync_events.
@@ -47,7 +66,7 @@
 
 2005-05-02  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
-	* QTabularDialog.C: correcht handling of the LFUN_UNSET_*
+	* QTabularDialog.C: correct handling of the LFUN_UNSET_*
 	functions within longtabular.
 	
 	* ui/QTabularDialogBase.ui: add tooltips to longtabular tab.
Index: src/frontends/qt2/Makefile.dialogs
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Makefile.dialogs,v
retrieving revision 1.55
diff -u -p -r1.55 Makefile.dialogs
--- src/frontends/qt2/Makefile.dialogs	14 Jan 2005 15:53:29 -0000	1.55
+++ src/frontends/qt2/Makefile.dialogs	12 May 2005 18:02:36 -0000
@@ -126,5 +126,5 @@ MOCFILES = \
 	QVSpaceDialog.C QVSpaceDialog.h \
 	QWrapDialog.C QWrapDialog.h \
 	QLToolbar.C QLToolbar.h \
-	lengthvalidator.C lengthvalidator.h \
-	socket_callback.C socket_callback.h
+	socket_callback.C socket_callback.h \
+	validators.C validators.h
Index: src/frontends/qt2/QBoxDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QBoxDialog.C,v
retrieving revision 1.7
diff -u -p -r1.7 QBoxDialog.C
--- src/frontends/qt2/QBoxDialog.C	26 Apr 2005 11:12:18 -0000	1.7
+++ src/frontends/qt2/QBoxDialog.C	12 May 2005 18:02:37 -0000
@@ -13,7 +13,7 @@
 #include "QBoxDialog.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "QBox.h"
 #include "qt_helpers.h"
 
@@ -23,18 +23,6 @@
 
 namespace lyx {
 namespace frontend {
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXLength());
-	return v;
-}
-
-} // namespace anon
-
 
 QBoxDialog::QBoxDialog(QBox * form)
 	: QBoxDialogBase(0, 0, false, 0),
Index: src/frontends/qt2/QDocumentDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocumentDialog.C,v
retrieving revision 1.58
diff -u -p -r1.58 QDocumentDialog.C
--- src/frontends/qt2/QDocumentDialog.C	12 May 2005 10:16:04 -0000	1.58
+++ src/frontends/qt2/QDocumentDialog.C	12 May 2005 18:02:37 -0000
@@ -15,7 +15,7 @@
 
 #include "floatplacement.h"
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "panelstack.h"
 #include "qt_helpers.h"
 
@@ -46,18 +46,6 @@ using std::string;
 
 namespace lyx {
 namespace frontend {
-
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXLength());
-	return v;
-}
-
-} // namespace anon
 
 
 QDocumentDialog::QDocumentDialog(QDocument * form)
Index: src/frontends/qt2/QExternalDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QExternalDialog.C,v
retrieving revision 1.24
diff -u -p -r1.24 QExternalDialog.C
--- src/frontends/qt2/QExternalDialog.C	27 Jan 2005 21:05:36 -0000	1.24
+++ src/frontends/qt2/QExternalDialog.C	12 May 2005 18:02:38 -0000
@@ -25,7 +25,7 @@
 #include "QExternalDialog.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 #include "QExternal.h"
 
@@ -35,7 +35,7 @@
 #include <qfiledialog.h>
 #include <qtextview.h>
 #include <qlineedit.h>
-#include <qvalidator.h>
+
 
 using lyx::support::float_equal;
 using lyx::support::isStrDbl;
@@ -43,18 +43,6 @@ using std::string;
 
 namespace lyx {
 namespace frontend {
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXLength());
-	return v;
-}
-
-} // namespace anon
-
 
 QExternalDialog::QExternalDialog(QExternal * form)
 	: QExternalDialogBase(0, 0, false, 0),
Index: src/frontends/qt2/QGraphicsDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QGraphicsDialog.C,v
retrieving revision 1.31
diff -u -p -r1.31 QGraphicsDialog.C
--- src/frontends/qt2/QGraphicsDialog.C	26 Apr 2005 11:12:18 -0000	1.31
+++ src/frontends/qt2/QGraphicsDialog.C	12 May 2005 18:02:38 -0000
@@ -15,7 +15,7 @@
 #include "QGraphics.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include "debug.h"
@@ -31,18 +31,6 @@ using std::string;
 
 namespace lyx {
 namespace frontend {
-
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXLength());
-	return v;
-}
-
-} // namespace anon
 
 
 QGraphicsDialog::QGraphicsDialog(QGraphics * form)
Index: src/frontends/qt2/QRef.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QRef.C,v
retrieving revision 1.38
diff -u -p -r1.38 QRef.C
--- src/frontends/qt2/QRef.C	20 May 2004 09:36:28 -0000	1.38
+++ src/frontends/qt2/QRef.C	12 May 2005 18:02:39 -0000
@@ -116,7 +116,7 @@ void QRef::apply()
 
 bool QRef::nameAllowed()
 {
-	Kernel::DocTypes doc_type = kernel().docType();
+	Kernel::DocType const doc_type = kernel().docType();
 	return doc_type != Kernel::LATEX &&
 		doc_type != Kernel::LITERATE;
 }
@@ -124,7 +124,7 @@ bool QRef::nameAllowed()
 
 bool QRef::typeAllowed()
 {
-	Kernel::DocTypes doc_type = kernel().docType();
+	Kernel::DocType const doc_type = kernel().docType();
 	return doc_type != Kernel::LINUXDOC &&
 		doc_type != Kernel::DOCBOOK;
 }
Index: src/frontends/qt2/QTabularDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QTabularDialog.C,v
retrieving revision 1.27
diff -u -p -r1.27 QTabularDialog.C
--- src/frontends/qt2/QTabularDialog.C	2 May 2005 05:51:27 -0000	1.27
+++ src/frontends/qt2/QTabularDialog.C	12 May 2005 18:02:40 -0000
@@ -14,7 +14,7 @@
 
 #include "QTabularDialog.h"
 #include "QTabular.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include "controllers/ControlTabular.h"
@@ -27,18 +27,6 @@ using std::string;
 
 namespace lyx {
 namespace frontend {
-
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXLength());
-	return v;
-}
-
-} // namespace anon
 
 
 QTabularDialog::QTabularDialog(QTabular * form)
Index: src/frontends/qt2/QVSpaceDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QVSpaceDialog.C,v
retrieving revision 1.10
diff -u -p -r1.10 QVSpaceDialog.C
--- src/frontends/qt2/QVSpaceDialog.C	26 Nov 2004 14:52:54 -0000	1.10
+++ src/frontends/qt2/QVSpaceDialog.C	12 May 2005 18:02:40 -0000
@@ -16,7 +16,7 @@
 #include "QVSpace.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include <qcombobox.h>
@@ -27,18 +27,6 @@
 
 namespace lyx {
 namespace frontend {
-
-
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-	LengthValidator * v = new LengthValidator(ed);
-	v->setBottom(LyXGlueLength());
-	return v;
-}
-
-} // namespace anon
 
 
 QVSpaceDialog::QVSpaceDialog(QVSpace * form)
Index: src/frontends/qt2/lengthvalidator.C
===================================================================
RCS file: src/frontends/qt2/lengthvalidator.C
diff -N src/frontends/qt2/lengthvalidator.C
--- src/frontends/qt2/lengthvalidator.C	3 Dec 2004 11:02:06 -0000	1.7
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,69 +0,0 @@
-/**
- * \file lengthvalidator.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-
-#include <config.h>
-
-#include "lengthvalidator.h"
-#include "qt_helpers.h"
-
-#include "support/lstrings.h"
-
-#include <qwidget.h>
-
-
-using lyx::support::isStrDbl;
-using std::string;
-
-
-LengthValidator::LengthValidator(QWidget * parent, const char * name)
-	: QValidator(parent, name),
-	  no_bottom_(true), glue_length_(false)
-{}
-
-
-QValidator::State LengthValidator::validate(QString & qtext, int &) const
-{
-	string const text = fromqstr(qtext);
-	if (text.empty() || isStrDbl(text))
-		return QValidator::Acceptable;
-
-	if (glue_length_) {
-		LyXGlueLength gl;
-		return (isValidGlueLength(text, &gl)) ?
-			QValidator::Acceptable : QValidator::Intermediate;
-		}
-
-	LyXLength l;
-	bool const valid_length = isValidLength(text, &l);
-	if (!valid_length)
-		return QValidator::Intermediate;
-
-	if (no_bottom_)
-		return QValidator::Acceptable;
-
-	return b_.inPixels(100) <= l.inPixels(100) ?
-		QValidator::Acceptable : QValidator::Intermediate;
-}
-
-
-void LengthValidator::setBottom(LyXLength const & b)
-{
-	b_ = b;
-	no_bottom_ = false;
-}
-
-
-void LengthValidator::setBottom(LyXGlueLength const & g)
-{
-	g_ = g;
-	no_bottom_ = false;
-	glue_length_ = true;
-}
Index: src/frontends/qt2/lengthvalidator.h
===================================================================
RCS file: src/frontends/qt2/lengthvalidator.h
diff -N src/frontends/qt2/lengthvalidator.h
--- src/frontends/qt2/lengthvalidator.h	31 Jan 2005 15:26:39 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,46 +0,0 @@
-// -*- C++ -*-
-/**
- * \file lengthvalidator.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LENGTHVALIDATOR_H
-#define LENGTHVALIDATOR_H
-
-#include "lyxlength.h"
-#include "lyxgluelength.h"
-#include <qvalidator.h>
-
-class QWidget;
-
-
-class LengthValidator : public QValidator
-{
-	Q_OBJECT
-public:
-	LengthValidator(QWidget * parent, const char *name = 0);
-
-	QValidator::State validate(QString &, int &) const;
-
-	void setBottom(LyXLength const &);
-	void setBottom(LyXGlueLength const &);
-	LyXLength bottom() const { return b_; }
-
-private:
-#if defined(Q_DISABLE_COPY)
-	LengthValidator( const LengthValidator & );
-	LengthValidator& operator=( const LengthValidator & );
-#endif
-
-	LyXLength b_;
-	LyXGlueLength g_;
-	bool no_bottom_;
-	bool glue_length_;
-};
-
-# endif // NOT LENGTHVALIDATOR_H
Index: src/frontends/qt2/validators.C
===================================================================
RCS file: src/frontends/qt2/validators.C
diff -N src/frontends/qt2/validators.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/frontends/qt2/validators.C	12 May 2005 18:02:40 -0000
@@ -0,0 +1,169 @@
+/**
+ * \file validators.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+
+#include <config.h>
+
+#include "validators.h"
+#include "qt_helpers.h"
+
+#include "gettext.h"
+#include "lyxrc.h"
+
+#include "frontends/Alert.h"
+
+#include "frontends/controllers/Dialog.h"
+
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
+#include <qlineedit.h>
+#include <qwidget.h>
+
+#include <sstream>
+
+using lyx::support::isStrDbl;
+using std::string;
+
+
+LengthValidator::LengthValidator(QWidget * parent, const char * name)
+	: QValidator(parent, name),
+	  no_bottom_(true), glue_length_(false)
+{}
+
+
+QValidator::State LengthValidator::validate(QString & qtext, int &) const
+{
+	string const text = fromqstr(qtext);
+	if (text.empty() || isStrDbl(text))
+		return QValidator::Acceptable;
+
+	if (glue_length_) {
+		LyXGlueLength gl;
+		return (isValidGlueLength(text, &gl)) ?
+			QValidator::Acceptable : QValidator::Intermediate;
+		}
+
+	LyXLength l;
+	bool const valid_length = isValidLength(text, &l);
+	if (!valid_length)
+		return QValidator::Intermediate;
+
+	if (no_bottom_)
+		return QValidator::Acceptable;
+
+	return b_.inPixels(100) <= l.inPixels(100) ?
+		QValidator::Acceptable : QValidator::Intermediate;
+}
+
+
+void LengthValidator::setBottom(LyXLength const & b)
+{
+	b_ = b;
+	no_bottom_ = false;
+}
+
+
+void LengthValidator::setBottom(LyXGlueLength const & g)
+{
+	g_ = g;
+	no_bottom_ = false;
+	glue_length_ = true;
+}
+
+
+LengthValidator * unsignedLengthValidator(QLineEdit * ed)
+{
+	LengthValidator * v = new LengthValidator(ed);
+	v->setBottom(LyXLength());
+	return v;
+}
+
+
+PathValidator::PathValidator(bool acceptable_if_empty,
+			     QWidget * parent, const char * name)
+	: QValidator(parent, name),
+	  acceptable_if_empty_(acceptable_if_empty),
+	  latex_doc_(false),
+	  tex_allows_spaces_(false)
+{}
+
+
+namespace {
+
+string const printable_list(string const & invalid_chars)
+{
+	std::ostringstream ss;
+	string::const_iterator const begin = invalid_chars.begin();
+	string::const_iterator const end = invalid_chars.end();
+	string::const_iterator it = begin;
+
+	for (; it != end; ++it) {
+		if (it != begin)
+			ss << ", ";
+		if (*it == ' ')
+			ss << _("space");
+		else
+			ss << *it;
+	}
+
+	return ss.str();
+}
+
+} // namespace anon
+
+
+QValidator::State PathValidator::validate(QString & qtext, int &) const
+{
+	if (!latex_doc_)
+		return QValidator::Acceptable;
+
+	string const text = lyx::support::trim(fromqstr(qtext));
+	if (text.empty())
+		return 	acceptable_if_empty_ ?
+			QValidator::Acceptable : QValidator::Intermediate;
+
+	string invalid_chars("#$%{}()[]:\"^");
+	if (!tex_allows_spaces_)
+		invalid_chars += ' ';
+
+	if (text.find_first_of(invalid_chars) != string::npos) {
+
+		static int counter = 0;
+		if (counter == 0) {
+			Alert::error(_("Invalid filename"),
+				     _("LyX does not provide LateX support for file names containing any of these characters:\n") +
+				     printable_list(invalid_chars));
+		}
+		++counter;
+		return QValidator::Intermediate;
+	}
+
+	return QValidator::Acceptable;
+}
+
+
+void PathValidator::setChecker(lyx::frontend::KernelDocType const & type,
+			       LyXRC const & lyxrc)
+{
+	latex_doc_ = type == lyx::frontend::Kernel::LATEX;
+	tex_allows_spaces_ = lyxrc.tex_allows_spaces;
+}
+
+
+PathValidator * getPathValidator(QLineEdit * ed)
+{
+	if (!ed)
+		return 0;
+	QValidator * validator = const_cast<QValidator *>(ed->validator());
+	if (!validator)
+		return 0;
+	return dynamic_cast<PathValidator *>(validator);
+}
Index: src/frontends/qt2/validators.h
===================================================================
RCS file: src/frontends/qt2/validators.h
diff -N src/frontends/qt2/validators.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/frontends/qt2/validators.h	12 May 2005 18:02:40 -0000
@@ -0,0 +1,132 @@
+// -*- C++ -*-
+/**
+ * \file validators.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Validators are used to decide upon the legality of some input action.
+ * For example, a "line edit" widget might be used to input a "glue length".
+ * The correct syntax for such a length is "2em + 0.5em". The LengthValidator
+ * below will report whether the input text conforms to this syntax.
+ *
+ * This information is used in LyX primarily to give the user some
+ * feedback on the validity of the input data using the "checked_widget"
+ * concept. For example, if the data is invalid then the label of
+ * a "line edit" widget is changed in colour and the dialog's "Ok"
+ * and "Apply" buttons are disabled. See checked_widgets.[Ch] for
+ * further details.
+ */
+
+#ifndef VALIDATORS_H
+#define VALIDATORS_H
+
+#include "lyxlength.h"
+#include "lyxgluelength.h"
+#include <qvalidator.h>
+
+class QWidget;
+class QLineEdit;
+
+
+/** A class to ascertain whether the data passed to the @c validate()
+ *  member function can be interpretted as a LyXGlueLength.
+ */
+class LengthValidator : public QValidator
+{
+	Q_OBJECT
+public:
+	/// Define a validator for widget @c parent.
+	LengthValidator(QWidget * parent, const char *name = 0);
+
+	/** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
+	 *  If not, returns QValidator::Intermediate.
+	 */
+	QValidator::State validate(QString & data, int &) const;
+
+	/** @name Bottom
+	 *  Set and retrieve the minimum allowed LyXLength value.
+	 */
+	//@{
+	void setBottom(LyXLength const &);
+	void setBottom(LyXGlueLength const &);
+	LyXLength bottom() const { return b_; }
+	//@}
+
+private:
+#if defined(Q_DISABLE_COPY)
+	LengthValidator( const LengthValidator & );
+	LengthValidator& operator=( const LengthValidator & );
+#endif
+
+	LyXLength b_;
+	LyXGlueLength g_;
+	bool no_bottom_;
+	bool glue_length_;
+};
+
+
+/// @returns a new @c LengthValidator that does not accept negative lengths.
+LengthValidator * unsignedLengthValidator(QLineEdit *);
+
+
+// Forward declarations
+class LyXRC;
+
+namespace lyx {
+namespace frontend {
+
+class KernelDocType;
+
+} // namespace frontend
+} // namespace lyx
+
+
+/** A class to ascertain whether the data passed to the @c validate()
+ *  member function is a valid file path.
+ *  The test is active only when the path is to be stored in a LaTeX
+ *  file, LaTeX being quite picky about legal names.
+ */
+class PathValidator : public QValidator
+{
+	Q_OBJECT
+public:
+	/** Define a validator for widget @c parent.
+	 *  If @c acceptable_if_empty is @c true then an empty path
+	 *  is regarded as acceptable.
+	 */
+	PathValidator(bool acceptable_if_empty,
+		      QWidget * parent, const char *name = 0);
+
+	/** @returns QValidator::Acceptable if @c data is a valid path.
+	 *  If not, returns QValidator::Intermediate.
+	 */
+	QValidator::State validate(QString &, int &) const;
+
+	/** Define what checks that @c validate() will perform.
+	 *  @param doc_type checks are activated only for @c LATEX docs.
+	 *  @param lyxrc contains a @c tex_allows_spaces member that
+	 *  is used to define what is legal.
+	 */
+	void setChecker(lyx::frontend::KernelDocType const & doc_type,
+			LyXRC const & lyxrc);
+
+private:
+#if defined(Q_DISABLE_COPY)
+	PathValidator( const PathValidator & );
+	PathValidator& operator=( const PathValidator & );
+#endif
+
+	bool acceptable_if_empty_;
+	bool latex_doc_;
+	bool tex_allows_spaces_;
+};
+
+
+/// @returns the PathValidator attached to the widget, or 0.
+PathValidator * getPathValidator(QLineEdit *);
+
+# endif // NOT VALIDATORS_H
Index: src/frontends/xforms/FormRef.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormRef.C,v
retrieving revision 1.80
diff -u -p -r1.80 FormRef.C
--- src/frontends/xforms/FormRef.C	5 May 2005 11:07:45 -0000	1.80
+++ src/frontends/xforms/FormRef.C	12 May 2005 18:02:40 -0000
@@ -98,7 +98,7 @@ void FormRef::update()
 	switch_go_button();
 
 	// Name is irrelevant to LaTeX/Literate documents
-	Kernel::DocTypes doctype = kernel().docType();
+	Kernel::DocType const doctype = kernel().docType();
 	if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) {
 		setEnabled(dialog_->input_name, false);
 	} else {

Reply via email to