git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27524 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-11-16 00:18:52 +00:00
parent 435c7df10e
commit f000a62b0d
7 changed files with 59 additions and 13 deletions

View File

@ -31,7 +31,8 @@ enum HullType {
hullXXAlignAt,
hullFlAlign,
hullMultline,
hullGather
hullGather,
hullRegexp
};
HullType hullType(docstring const & name);

View File

@ -980,20 +980,27 @@ void InsetMathGrid::mathmlize(MathStream & os) const
void InsetMathGrid::write(WriteStream & os) const
{
write(os, 0, 0, nrows(), ncols());
}
void InsetMathGrid::write(WriteStream & os,
row_type beg_row, col_type beg_col,
row_type end_row, col_type end_col) const
{
MathEnsurer ensurer(os, false);
docstring eol;
for (row_type row = 0; row < nrows(); ++row) {
for (row_type row = beg_row; row < end_row; ++row) {
os << verboseHLine(rowinfo_[row].lines_);
// don't write & and empty cells at end of line
col_type lastcol = 0;
bool emptyline = true;
for (col_type col = 0; col < ncols(); ++col)
for (col_type col = beg_col; col < end_col; ++col)
if (!cell(index(row, col)).empty()) {
lastcol = col + 1;
emptyline = false;
}
for (col_type col = 0; col < lastcol; ++col) {
for (col_type col = beg_col; col < end_col; ++col) {
os << cell(index(row, col));
if (os.pendingBrace())
ModeSpecifier specifier(os, TEXT_MODE);
@ -1003,9 +1010,10 @@ void InsetMathGrid::write(WriteStream & os) const
os << eol;
// append newline only if line wasn't completely empty
// and this was not the last line in the grid
if (!emptyline && row + 1 < nrows())
if (!emptyline && row + 1 < end_row)
os << "\n";
}
// @TODO use end_row instead of nrows() ?
docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
if (!s.empty()) {
if (eol.empty()) {

View File

@ -210,6 +210,10 @@ public:
///
void write(WriteStream & os) const;
///
void write(WriteStream & os,
row_type beg_row, col_type beg_col,
row_type end_row, col_type end_col) const;
///
void normalize(NormalStream &) const;
///
//void maple(MapleStream &) const;

View File

@ -118,7 +118,8 @@ HullType hullType(docstring const & s)
if (s == "multline") return hullMultline;
if (s == "gather") return hullGather;
if (s == "flalign") return hullFlAlign;
lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl;
if (s == "regexp") return hullRegexp;
lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl;
return HullType(-1);
}
@ -137,7 +138,8 @@ docstring hullName(HullType type)
case hullMultline: return from_ascii("multline");
case hullGather: return from_ascii("gather");
case hullFlAlign: return from_ascii("flalign");
default:
case hullRegexp: return from_ascii("regexp");
default:
lyxerr << "unknown hull type '" << type << "'" << endl;
return from_ascii("none");
}
@ -556,10 +558,10 @@ bool InsetMathHull::ams() const
Inset::DisplayType InsetMathHull::display() const
{
return (type_ != hullSimple && type_ != hullNone) ? AlignCenter : Inline;
return (type_ != hullSimple && type_ != hullNone
&& type_ != hullRegexp) ? AlignCenter : Inline;
}
bool InsetMathHull::numberedType() const
{
if (type_ == hullNone)
@ -568,6 +570,8 @@ bool InsetMathHull::numberedType() const
return false;
if (type_ == hullXXAlignAt)
return false;
if (type_ == hullRegexp)
return false;
for (row_type row = 0; row < nrows(); ++row)
if (!nonum_[row])
return true;
@ -631,6 +635,10 @@ void InsetMathHull::header_write(WriteStream & os) const
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
break;
case hullRegexp:
os << "\\regexp{";
break;
default:
os << "\\begin{unknown" << star(n) << '}';
break;
@ -672,6 +680,10 @@ void InsetMathHull::footer_write(WriteStream & os) const
os << "\\end{" << hullName(type_) << "}\n";
break;
case hullRegexp:
os << "}";
break;
default:
os << "\\end{unknown" << star(n) << '}';
break;

View File

@ -111,6 +111,10 @@ public:
///
void write(std::ostream & os) const;
///
void header_write(WriteStream &) const;
///
void footer_write(WriteStream &) const;
///
void read(Lexer & lex);
///
bool readQuiet(Lexer & lex);
@ -157,10 +161,6 @@ private:
///
void validate1(LaTeXFeatures & features);
///
void header_write(WriteStream &) const;
///
void footer_write(WriteStream &) const;
///
docstring nicelabel(row_type row) const;
///
void doExtern(Cursor & cur, FuncRequest & func);

View File

@ -964,6 +964,23 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
}
case LFUN_REGEXP_MODE: {
InsetMathHull * i = dynamic_cast<InsetMathHull *>(cur.inset().asInsetMath());
if (i && i->getType() == hullRegexp) {
cur.message(_("Already in regexp mode"));
break;
}
cur.macroModeClose();
docstring const save_selection = grabAndEraseSelection(cur);
selClearOrDel(cur);
cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp)));
cur.posBackward();
cur.pushBackward(*cur.nextInset());
cur.niceInsert(save_selection);
cur.message(_("Regexp editor mode"));
break;
}
case LFUN_MATH_SIZE: {
FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, cmd.argument());
doDispatch(cur, fr);

View File

@ -41,6 +41,7 @@
#include "InsetMathTabular.h"
#include "InsetMathUnderset.h"
#include "InsetMathUnknown.h"
#include "InsetMathHull.h"
#include "InsetMathXArrow.h"
#include "InsetMathXYMatrix.h"
#include "MacroTable.h"
@ -462,6 +463,9 @@ MathAtom createInsetMath(docstring const & s)
if (isSpecialChar(s))
return MathAtom(new InsetMathSpecialChar(s));
if (s == "regexp")
return MathAtom(new InsetMathHull(hullRegexp));
return MathAtom(new MathMacro(s));
}