mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Make the Qt Alert boxes recognize their parent.
Lots of gratuitous changes that should not alter Lyx's behaviour. ************************************************************************** You're all going to get failure on link. Please "rm -f lengthvalidator.*". ************************************************************************** git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9940 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5230d7b794
commit
a8a852b4e9
@ -107,6 +107,7 @@ src/frontends/qt2/QWrap.C
|
||||
src/frontends/qt2/Qt2BC.h
|
||||
src/frontends/qt2/QtView.C
|
||||
src/frontends/qt2/floatplacement.C
|
||||
src/frontends/qt2/validators.C
|
||||
src/frontends/xforms/Alert_pimpl.C
|
||||
src/frontends/xforms/ColorHandler.C
|
||||
src/frontends/xforms/Dialogs.C
|
||||
|
@ -1,3 +1,8 @@
|
||||
2005-05-08 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* Kernel.h (KernelDocType): wrapper class for the Kernel::DocTypes
|
||||
enum.
|
||||
|
||||
2005-05-07 Michael Schmitt <michael.schmitt@teststep.org>
|
||||
|
||||
* ControlRef.C: rename LFUN_REF_GOTO to LFUN_LABEL_GOTO
|
||||
|
@ -69,7 +69,7 @@ string const Kernel::bufferFilepath() const
|
||||
}
|
||||
|
||||
|
||||
Kernel::DocTypes Kernel::docType() const
|
||||
Kernel::DocType Kernel::docType() const
|
||||
{
|
||||
if (buffer().isLatex())
|
||||
return LATEX;
|
||||
|
@ -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.
|
||||
@ -101,6 +101,19 @@ 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
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "gettext.h"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
@ -37,8 +38,15 @@ int prompt_pimpl(string const & tit, string const & question,
|
||||
{
|
||||
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),
|
||||
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.
|
||||
@ -50,30 +58,48 @@ int prompt_pimpl(string const & tit, string const & question,
|
||||
|
||||
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));
|
||||
|
@ -1,3 +1,22 @@
|
||||
2005-05-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* 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 <lasgouttes@lyx.org>
|
||||
|
||||
* QLPopupMenu.C (fire): use lyx_gui::sync_events.
|
||||
@ -47,7 +66,7 @@
|
||||
|
||||
2005-05-02 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* 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.
|
||||
|
@ -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
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "QBoxDialog.h"
|
||||
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "validators.h"
|
||||
#include "QBox.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
@ -24,18 +24,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),
|
||||
form_(form)
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "floatplacement.h"
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "validators.h"
|
||||
#include "panelstack.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
@ -48,18 +48,6 @@ 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)
|
||||
: QDocumentDialogBase(0, 0, false, 0), form_(form)
|
||||
{
|
||||
|
@ -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;
|
||||
@ -44,18 +44,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),
|
||||
form_(form)
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "QGraphics.h"
|
||||
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "validators.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "debug.h"
|
||||
@ -33,18 +33,6 @@ 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)
|
||||
: QGraphicsDialogBase(0, 0, false, 0),
|
||||
form_(form)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include "QTabularDialog.h"
|
||||
#include "QTabular.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "validators.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "controllers/ControlTabular.h"
|
||||
@ -29,18 +29,6 @@ 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)
|
||||
: QTabularDialogBase(0, 0, false, 0),
|
||||
form_(form)
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "QVSpace.h"
|
||||
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "validators.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include <qcombobox.h>
|
||||
@ -29,18 +29,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)
|
||||
: QVSpaceDialogBase(0, 0, false, 0),
|
||||
form_(form)
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
169
src/frontends/qt2/validators.C
Normal file
169
src/frontends/qt2/validators.C
Normal file
@ -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);
|
||||
}
|
132
src/frontends/qt2/validators.h
Normal file
132
src/frontends/qt2/validators.h
Normal file
@ -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
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user