mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix bug 5827 (validate date-insert argument):
* src/support/os*.{cpp,h}: - new function is_valid_strftime that validates strftime arguments, OS dependant (win32 differs here) * src/Text3.cpp: - use is_valid_strftime in LFUN_DATE_INSERT status check. * src/frontends/qt4/GuiPrefs.{cpp, h}: - new GUI validator for strftime. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28932 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e47e1cd751
commit
5be56b517a
@ -68,6 +68,7 @@
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxtime.h"
|
||||
#include "support/os.h"
|
||||
|
||||
#include "mathed/InsetMathHull.h"
|
||||
#include "mathed/MathMacroTemplate.h"
|
||||
@ -2318,6 +2319,13 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
enable = cur.inset().insetAllowed(MATH_CODE);
|
||||
break;
|
||||
|
||||
case LFUN_DATE_INSERT: {
|
||||
string const format = cmd.argument().empty()
|
||||
? lyxrc.date_insert_format : to_utf8(cmd.argument());
|
||||
enable = support::os::is_valid_strftime(format);
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_WORD_DELETE_FORWARD:
|
||||
case LFUN_WORD_DELETE_BACKWARD:
|
||||
case LFUN_LINE_DELETE:
|
||||
@ -2363,7 +2371,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
case LFUN_SERVER_SET_XY:
|
||||
case LFUN_SERVER_GET_LAYOUT:
|
||||
case LFUN_LAYOUT:
|
||||
case LFUN_DATE_INSERT:
|
||||
case LFUN_SELF_INSERT:
|
||||
case LFUN_LINE_INSERT:
|
||||
case LFUN_MATH_DISPLAY:
|
||||
|
@ -351,6 +351,35 @@ void PrefPlaintext::update(LyXRC const & rc)
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// StrftimeValidator
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
class StrftimeValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
StrftimeValidator(QWidget *);
|
||||
QValidator::State validate(QString & input, int & pos) const;
|
||||
};
|
||||
|
||||
|
||||
StrftimeValidator::StrftimeValidator(QWidget * parent)
|
||||
: QValidator(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
|
||||
{
|
||||
if (is_valid_strftime(fromqstr(input)))
|
||||
return QValidator::Acceptable;
|
||||
else
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrefDate
|
||||
@ -361,11 +390,22 @@ PrefDate::PrefDate(GuiPreferences * form)
|
||||
: PrefModule(qt_(catOutput), qt_("Date format"), form)
|
||||
{
|
||||
setupUi(this);
|
||||
DateED->setValidator(new StrftimeValidator(DateED));
|
||||
connect(DateED, SIGNAL(textChanged(QString)),
|
||||
this, SIGNAL(changed()));
|
||||
}
|
||||
|
||||
|
||||
void PrefDate::on_DateED_textChanged(const QString &)
|
||||
{
|
||||
QString t = DateED->text();
|
||||
int p = 0;
|
||||
bool valid = DateED->validator()->validate(t, p)
|
||||
== QValidator::Acceptable;
|
||||
setValid(DateLA, valid);
|
||||
}
|
||||
|
||||
|
||||
void PrefDate::apply(LyXRC & rc) const
|
||||
{
|
||||
rc.date_insert_format = fromqstr(DateED->text());
|
||||
@ -2525,7 +2565,8 @@ GuiPreferences::GuiPreferences(GuiView & lv)
|
||||
addModule(new PrefSpellchecker(this));
|
||||
|
||||
addModule(new PrefPrinter(this));
|
||||
addModule(new PrefDate(this));
|
||||
PrefDate * dateFormat = new PrefDate(this);
|
||||
addModule(dateFormat);
|
||||
addModule(new PrefPlaintext(this));
|
||||
addModule(new PrefLatex(this));
|
||||
|
||||
@ -2548,6 +2589,9 @@ GuiPreferences::GuiPreferences(GuiView & lv)
|
||||
bc().setApply(applyPB);
|
||||
bc().setCancel(closePB);
|
||||
bc().setRestore(restorePB);
|
||||
|
||||
// initialize the strftime validator
|
||||
bc().addCheckedLineEdit(dateFormat->DateED);
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,6 +177,9 @@ public:
|
||||
|
||||
virtual void apply(LyXRC & rc) const;
|
||||
virtual void update(LyXRC const & rc);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_DateED_textChanged(const QString &);
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,6 +74,9 @@ std::string internal_path_list(std::string const & p);
|
||||
*/
|
||||
std::string latex_path(std::string const & p);
|
||||
|
||||
/// Checks if the format string is suitable on the OS
|
||||
bool is_valid_strftime(std::string const & p);
|
||||
|
||||
/** Returns a string suitable to be passed to popen when
|
||||
* reading a file.
|
||||
*/
|
||||
|
@ -206,6 +206,23 @@ string latex_path(string const & p)
|
||||
}
|
||||
|
||||
|
||||
bool is_valid_strftime(string const & p)
|
||||
{
|
||||
string::size_type pos = p.find_first_of('%');
|
||||
while (pos != string::npos) {
|
||||
if (pos + 1 == string::npos)
|
||||
break;
|
||||
if (!containsOnly(p.substr(pos + 1, 1),
|
||||
"aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
|
||||
return false;
|
||||
if (pos + 2 == string::npos)
|
||||
break;
|
||||
pos = p.find_first_of('%', pos + 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// returns a string suitable to be passed to popen when
|
||||
// reading a pipe
|
||||
char const * popen_read_mode()
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "support/os.h"
|
||||
#include "support/docstring.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Carbon/Carbon.h>
|
||||
@ -96,6 +97,23 @@ string latex_path(string const & p)
|
||||
}
|
||||
|
||||
|
||||
bool is_valid_strftime(string const & p)
|
||||
{
|
||||
string::size_type pos = p.find_first_of('%');
|
||||
while (pos != string::npos) {
|
||||
if (pos + 1 == string::npos)
|
||||
break;
|
||||
if (!containsOnly(p.substr(pos + 1, 1),
|
||||
"aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
|
||||
return false;
|
||||
if (pos + 2 == string::npos)
|
||||
break;
|
||||
pos = p.find_first_of('%', pos + 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
char const * popen_read_mode()
|
||||
{
|
||||
return "r";
|
||||
|
@ -265,6 +265,23 @@ string latex_path(string const & p)
|
||||
}
|
||||
|
||||
|
||||
bool is_valid_strftime(string const & p)
|
||||
{
|
||||
string::size_type pos = p.find_first_of('%');
|
||||
while (pos != string::npos) {
|
||||
if (pos + 1 == string::npos)
|
||||
break;
|
||||
if (!containsOnly(p.substr(pos + 1, 1),
|
||||
"aAbBcdfHIjmMpSUwWxXyYzZ%"))
|
||||
return false;
|
||||
if (pos + 2 == string::npos)
|
||||
break;
|
||||
pos = p.find_first_of('%', pos + 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// returns a string suitable to be passed to popen when
|
||||
// reading a pipe
|
||||
char const * popen_read_mode()
|
||||
|
Loading…
Reference in New Issue
Block a user