mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 16:50:39 +00:00
Fix Bug 4053: Update other controls allows invalid listings parameters to be passed in listings-related dialogs.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@19223 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
df3c4dcd9f
commit
7fd53d7148
@ -225,9 +225,9 @@ QDocumentDialog::QDocumentDialog(QDocument * form)
|
|||||||
connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
|
connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
|
||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
|
connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
|
||||||
this, SLOT(validate_listings_params()));
|
this, SLOT(set_listings_msg()));
|
||||||
connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
|
connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
|
||||||
this, SLOT(validate_listings_params()));
|
this, SLOT(set_listings_msg()));
|
||||||
textLayoutModule->listingsTB->setPlainText(
|
textLayoutModule->listingsTB->setPlainText(
|
||||||
qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
|
qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
|
||||||
textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
|
textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
|
||||||
@ -623,13 +623,29 @@ void QDocumentDialog::change_adaptor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QDocumentDialog::validate_listings_params()
|
docstring QDocumentDialog::validate_listings_params()
|
||||||
|
{
|
||||||
|
// use a cache here to avoid repeated validation
|
||||||
|
// of the same parameters
|
||||||
|
static string param_cache = string();
|
||||||
|
static docstring msg_cache = docstring();
|
||||||
|
|
||||||
|
if (textLayoutModule->bypassCB->isChecked())
|
||||||
|
return docstring();
|
||||||
|
|
||||||
|
string params = fromqstr(textLayoutModule->listingsED->toPlainText());
|
||||||
|
if (params != param_cache) {
|
||||||
|
param_cache = params;
|
||||||
|
msg_cache = InsetListingsParams(params).validate();
|
||||||
|
}
|
||||||
|
return msg_cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QDocumentDialog::set_listings_msg()
|
||||||
{
|
{
|
||||||
static bool isOK = true;
|
static bool isOK = true;
|
||||||
InsetListingsParams par(fromqstr(textLayoutModule->listingsED->toPlainText()));
|
docstring msg = validate_listings_params();
|
||||||
docstring msg;
|
|
||||||
if (!textLayoutModule->bypassCB->isChecked())
|
|
||||||
msg = par.validate();
|
|
||||||
if (msg.empty()) {
|
if (msg.empty()) {
|
||||||
if (isOK)
|
if (isOK)
|
||||||
return;
|
return;
|
||||||
@ -637,14 +653,10 @@ void QDocumentDialog::validate_listings_params()
|
|||||||
// listingsTB->setTextColor("black");
|
// listingsTB->setTextColor("black");
|
||||||
textLayoutModule->listingsTB->setPlainText(
|
textLayoutModule->listingsTB->setPlainText(
|
||||||
qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
|
qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
|
||||||
okPB->setEnabled(true);
|
|
||||||
applyPB->setEnabled(true);
|
|
||||||
} else {
|
} else {
|
||||||
isOK = false;
|
isOK = false;
|
||||||
// listingsTB->setTextColor("red");
|
// listingsTB->setTextColor("red");
|
||||||
textLayoutModule->listingsTB->setPlainText(toqstr(msg));
|
textLayoutModule->listingsTB->setPlainText(toqstr(msg));
|
||||||
okPB->setEnabled(false);
|
|
||||||
applyPB->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1449,6 +1461,13 @@ void QDocument::useClassDefaults()
|
|||||||
update_contents();
|
update_contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool QDocument::isValid()
|
||||||
|
{
|
||||||
|
return dialog_->validate_listings_params().empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -68,11 +68,13 @@ public:
|
|||||||
void updatePagestyle(std::string const &, std::string const &);
|
void updatePagestyle(std::string const &, std::string const &);
|
||||||
|
|
||||||
void showPreamble();
|
void showPreamble();
|
||||||
|
/// validate listings parameters and return an error message, if any
|
||||||
|
docstring validate_listings_params();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void updateNumbering();
|
void updateNumbering();
|
||||||
void change_adaptor();
|
void change_adaptor();
|
||||||
void validate_listings_params();
|
void set_listings_msg();
|
||||||
void saveDefaultClicked();
|
void saveDefaultClicked();
|
||||||
void useDefaultsClicked();
|
void useDefaultsClicked();
|
||||||
|
|
||||||
@ -141,6 +143,9 @@ private:
|
|||||||
void saveDocDefault();
|
void saveDocDefault();
|
||||||
/// reset to default params
|
/// reset to default params
|
||||||
void useClassDefaults();
|
void useClassDefaults();
|
||||||
|
protected:
|
||||||
|
/// return false if validate_listings_params returns error
|
||||||
|
virtual bool isValid();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ QIncludeDialog::QIncludeDialog(QInclude * form)
|
|||||||
connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
|
connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
|
||||||
connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
|
connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
|
||||||
connect(listingsED, SIGNAL(textChanged()), 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_msg()));
|
||||||
connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
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_msg()));
|
||||||
|
|
||||||
setFocusProxy(filenameED);
|
setFocusProxy(filenameED);
|
||||||
}
|
}
|
||||||
@ -84,24 +84,38 @@ void QIncludeDialog::change_adaptor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QIncludeDialog::validate_listings_params()
|
docstring QIncludeDialog::validate_listings_params()
|
||||||
|
{
|
||||||
|
// use a cache here to avoid repeated validation
|
||||||
|
// of the same parameters
|
||||||
|
static string param_cache = string();
|
||||||
|
static docstring msg_cache = docstring();
|
||||||
|
|
||||||
|
if (typeCO->currentIndex() != 3 || bypassCB->isChecked())
|
||||||
|
return docstring();
|
||||||
|
|
||||||
|
string params = fromqstr(listingsED->toPlainText());
|
||||||
|
if (params != param_cache) {
|
||||||
|
param_cache = params;
|
||||||
|
msg_cache = InsetListingsParams(params).validate();
|
||||||
|
}
|
||||||
|
return msg_cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QIncludeDialog::set_listings_msg()
|
||||||
{
|
{
|
||||||
static bool isOK = true;
|
static bool isOK = true;
|
||||||
InsetListingsParams par(fromqstr(listingsED->toPlainText()));
|
docstring msg = validate_listings_params();
|
||||||
docstring msg;
|
|
||||||
if (!bypassCB->isChecked())
|
|
||||||
msg = par.validate();
|
|
||||||
if (msg.empty()) {
|
if (msg.empty()) {
|
||||||
if (isOK)
|
if (isOK)
|
||||||
return;
|
return;
|
||||||
isOK = true;
|
isOK = true;
|
||||||
listingsTB->setPlainText(
|
listingsTB->setPlainText(
|
||||||
qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
|
qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
|
||||||
okPB->setEnabled(true);
|
|
||||||
} else {
|
} else {
|
||||||
isOK = false;
|
isOK = false;
|
||||||
listingsTB->setPlainText(toqstr(msg));
|
listingsTB->setPlainText(toqstr(msg));
|
||||||
okPB->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +348,8 @@ void QInclude::load()
|
|||||||
|
|
||||||
bool QInclude::isValid()
|
bool QInclude::isValid()
|
||||||
{
|
{
|
||||||
return !dialog_->filenameED->text().isEmpty();
|
return !dialog_->filenameED->text().isEmpty() &&
|
||||||
|
dialog_->validate_listings_params().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -31,12 +31,18 @@ public:
|
|||||||
void updateLists();
|
void updateLists();
|
||||||
|
|
||||||
virtual void show();
|
virtual void show();
|
||||||
|
/// validate listings parameters and return an error message, if any
|
||||||
|
docstring validate_listings_params();
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
virtual void change_adaptor();
|
virtual void change_adaptor();
|
||||||
void validate_listings_params();
|
|
||||||
virtual void loadClicked();
|
virtual void loadClicked();
|
||||||
virtual void browseClicked();
|
virtual void browseClicked();
|
||||||
virtual void typeChanged(int v);
|
virtual void typeChanged(int v);
|
||||||
|
/// AFAIK, QValidator only works for QLineEdit so
|
||||||
|
/// I have to validate listingsED (QTextEdit) manually.
|
||||||
|
/// This function displays a hint or error message returned by
|
||||||
|
/// validate_listings_params
|
||||||
|
void set_listings_msg();
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent * e);
|
virtual void closeEvent(QCloseEvent * e);
|
||||||
private:
|
private:
|
||||||
|
@ -190,9 +190,9 @@ QListingsDialog::QListingsDialog(QListings * form)
|
|||||||
connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
||||||
|
|
||||||
connect(listingsED, SIGNAL(textChanged()), 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_msg()));
|
||||||
connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
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_msg()));
|
||||||
|
|
||||||
for (int n = 0; languages[n][0]; ++n)
|
for (int n = 0; languages[n][0]; ++n)
|
||||||
languageCO->addItem(qt_(languages_gui[n]));
|
languageCO->addItem(qt_(languages_gui[n]));
|
||||||
@ -319,26 +319,38 @@ string QListingsDialog::construct_params()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QListingsDialog::validate_listings_params()
|
docstring QListingsDialog::validate_listings_params()
|
||||||
|
{
|
||||||
|
// use a cache here to avoid repeated validation
|
||||||
|
// of the same parameters
|
||||||
|
static string param_cache = string();
|
||||||
|
static docstring msg_cache = docstring();
|
||||||
|
|
||||||
|
if (bypassCB->isChecked())
|
||||||
|
return docstring();
|
||||||
|
|
||||||
|
string params = construct_params();
|
||||||
|
if (params != param_cache) {
|
||||||
|
param_cache = params;
|
||||||
|
msg_cache = InsetListingsParams(params).validate();
|
||||||
|
}
|
||||||
|
return msg_cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QListingsDialog::set_listings_msg()
|
||||||
{
|
{
|
||||||
static bool isOK = true;
|
static bool isOK = true;
|
||||||
InsetListingsParams par(construct_params());
|
docstring msg = validate_listings_params();
|
||||||
docstring msg;
|
|
||||||
if (!bypassCB->isChecked())
|
|
||||||
msg = par.validate();
|
|
||||||
if (msg.empty()) {
|
if (msg.empty()) {
|
||||||
if (isOK)
|
if (isOK)
|
||||||
return;
|
return;
|
||||||
isOK = true;
|
isOK = true;
|
||||||
listingsTB->setPlainText(
|
listingsTB->setPlainText(
|
||||||
qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
|
qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
|
||||||
okPB->setEnabled(true);
|
|
||||||
applyPB->setEnabled(true);
|
|
||||||
} else {
|
} else {
|
||||||
isOK = false;
|
isOK = false;
|
||||||
listingsTB->setPlainText(toqstr(msg));
|
listingsTB->setPlainText(toqstr(msg));
|
||||||
okPB->setEnabled(false);
|
|
||||||
applyPB->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,6 +613,12 @@ void QListings::update_contents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool QListings::isValid()
|
||||||
|
{
|
||||||
|
return dialog_->validate_listings_params().empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -29,11 +29,15 @@ public:
|
|||||||
QListingsDialog(QListings * form);
|
QListingsDialog(QListings * form);
|
||||||
/// get values from all the widgets and form a string
|
/// get values from all the widgets and form a string
|
||||||
std::string construct_params();
|
std::string construct_params();
|
||||||
|
/// validate listings parameters and return an error message, if any
|
||||||
|
docstring validate_listings_params();
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
virtual void change_adaptor();
|
virtual void change_adaptor();
|
||||||
/// AFAIK, QValidator only works for QLineEdit so
|
/// AFAIK, QValidator only works for QLineEdit so
|
||||||
/// I have to validate listingsED (QTextEdit) manually.
|
/// I have to validate listingsED (QTextEdit) manually.
|
||||||
void validate_listings_params();
|
/// This function displays a hint or error message returned by
|
||||||
|
/// validate_listings_params
|
||||||
|
void set_listings_msg();
|
||||||
/// turn off inline when float is clicked
|
/// turn off inline when float is clicked
|
||||||
void on_floatCB_stateChanged(int state);
|
void on_floatCB_stateChanged(int state);
|
||||||
/// turn off float when inline is clicked
|
/// turn off float when inline is clicked
|
||||||
@ -63,6 +67,9 @@ private:
|
|||||||
virtual void update_contents();
|
virtual void update_contents();
|
||||||
/// build the dialog
|
/// build the dialog
|
||||||
virtual void build_dialog();
|
virtual void build_dialog();
|
||||||
|
protected:
|
||||||
|
/// return false if validate_listings_params returns error
|
||||||
|
virtual bool isValid();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -34,6 +34,8 @@ What's new
|
|||||||
|
|
||||||
* USER INTERFACE:
|
* USER INTERFACE:
|
||||||
|
|
||||||
|
- Fix Bug 4053: Update other controls allows invalid listings parameters
|
||||||
|
to be passed in listings-related dialogs.
|
||||||
|
|
||||||
|
|
||||||
* DOCUMENTATION
|
* DOCUMENTATION
|
||||||
|
Loading…
Reference in New Issue
Block a user