* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author André Pönitz
+ * \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include "insets/RenderPreview.h"
#include "insets/InsetLabel.h"
+#include "insets/InsetRef.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
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);
}
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");
}
static docstring latexString(InsetMathHull const & inset)
{
odocstringstream ls;
- // This has to be static, because a preview snippet containing math
- // in text mode (such as $\text{$\phi$}$) gets processed twice. The
- // first time as a whole, and the second time only the inner math.
- // In this last case inset.buffer() would be invalid.
- // FIXME: preview snippets should only be processed once, such that
- // both static qualifier and isBufferValid() check can be dropped.
- static Encoding const * encoding = 0;
- if (inset.isBufferValid())
- encoding = &(inset.buffer().params().encoding());
+ Encoding const * encoding = &(inset.buffer().params().encoding());
WriteStream wi(ls, false, true, false, encoding);
inset.write(wi);
return ls.str();
bool InsetMathHull::notifyCursorLeaves(Cursor const & /*old*/, Cursor & cur)
{
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
- Buffer const & buffer = cur.buffer();
+ Buffer const * buffer = cur.buffer();
docstring const snippet = latexString(*this);
- preview_->addPreview(snippet, buffer);
- preview_->startLoading(buffer);
+ preview_->addPreview(snippet, *buffer);
+ preview_->startLoading(*buffer);
cur.updateFlags(Update::Force);
}
return false;
label_[row] = dummy_pointer;
// We need an update of the Buffer reference cache.
// This is achieved by updateLabels().
- lyx::updateLabels(buffer());
- } else
+ buffer().updateLabels();
+ } else {
label_[row]->updateCommand(label);
+ }
return;
}
InsetCommandParams p(LABEL_CODE);
if (nonum_[row] && label_[row]) {
delete label_[row];
label_[row] = 0;
+ if (!buffer_) {
+ // The buffer is set at the end of readInset.
+ // When parsing the inset, buffer_ is 0.
+ return;
+ }
// We need an update of the Buffer reference cache.
// This is achieved by updateLabels().
- lyx::updateLabels(buffer());
+ buffer().updateLabels();
}
}
bool InsetMathHull::ams() const
{
- return
- type_ == hullAlign ||
- type_ == hullFlAlign ||
- type_ == hullMultline ||
- type_ == hullGather ||
- type_ == hullAlignAt ||
- type_ == hullXAlignAt ||
- type_ == hullXXAlignAt;
+ return type_ == hullAlign
+ || type_ == hullFlAlign
+ || type_ == hullMultline
+ || type_ == hullGather
+ || type_ == hullAlignAt
+ || type_ == hullXAlignAt
+ || type_ == hullXXAlignAt;
}
Inset::DisplayType InsetMathHull::display() const
{
- return (type_ != hullSimple && type_ != hullNone) ? AlignCenter : Inline;
+ if (type_ == hullSimple || type_ == hullNone || type_ == hullRegexp)
+ return Inline;
+ return AlignCenter;
}
-
bool InsetMathHull::numberedType() const
{
if (type_ == hullNone)
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;
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
break;
+ case hullRegexp:
+ os << "\\regexp{";
+ break;
+
default:
os << "\\begin{unknown" << star(n) << '}';
break;
os << "\\end{" << hullName(type_) << "}\n";
break;
+ case hullRegexp:
+ os << "}";
+ break;
+
default:
os << "\\end{unknown" << star(n) << '}';
break;
break;
}
+ case LFUN_LABEL_COPY_AS_REF: {
+ row_type row;
+ if (cmd.argument().empty() && &cur.inset() == this)
+ // if there is no argument and we're inside math, we retrieve
+ // the row number from the cursor position.
+ row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+ else {
+ // if there is an argument, find the corresponding label, else
+ // check whether there is at least one label.
+ for (row = 0; row != nrows(); ++row)
+ if (!nonum_[row] && label_[row]
+ && (cmd.argument().empty() || label(row) == cmd.argument()))
+ break;
+ }
+
+ if (row == nrows())
+ break;
+
+ InsetCommandParams p(REF_CODE, "ref");
+ p["reference"] = label(row);
+ cap::clearSelection();
+ cap::copyInset(cur, new InsetRef(*cur.buffer(), p), label(row));
+ break;
+ }
+
case LFUN_WORD_DELETE_FORWARD:
case LFUN_CHAR_DELETE_FORWARD:
if (col(cur.idx()) + 1 == ncols()
case LFUN_DOWN:
case LFUN_NEWLINE_INSERT:
case LFUN_MATH_EXTERN:
- case LFUN_MATH_MUTATE:
case LFUN_MATH_DISPLAY:
// we handle these
status.setEnabled(true);
return true;
+
+ case LFUN_MATH_MUTATE: {
+ HullType ht = hullType(cmd.argument());
+ status.setOnOff(type_ == ht);
+ status.setEnabled(true);
+ return true;
+ }
+
case LFUN_MATH_NUMBER_TOGGLE:
// FIXME: what is the right test, this or the one of
// LABEL_INSERT?
status.setEnabled(display());
status.setOnOff(numberedType());
return true;
+
case LFUN_MATH_NUMBER_LINE_TOGGLE: {
// FIXME: what is the right test, this or the one of
// LABEL_INSERT?
- bool const enable = (type_ == hullMultline) ?
- (nrows() - 1 == cur.row()) : display();
+ bool const enable = (type_ == hullMultline)
+ ? (nrows() - 1 == cur.row())
+ : display() != Inline && nrows() > 1;
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
status.setEnabled(enable);
- status.setOnOff(numbered(r));
+ status.setOnOff(enable && numbered(r));
return true;
}
+
case LFUN_LABEL_INSERT:
status.setEnabled(type_ != hullSimple);
return true;
+
+ case LFUN_LABEL_COPY_AS_REF: {
+ bool enabled = false;
+ row_type row;
+ if (cmd.argument().empty() && &cur.inset() == this) {
+ // if there is no argument and we're inside math, we retrieve
+ // the row number from the cursor position.
+ row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+ enabled = numberedType() && label_[row] && !nonum_[row];
+ } else {
+ // if there is an argument, find the corresponding label, else
+ // check whether there is at least one label.
+ for (row_type row = 0; row != nrows(); ++row) {
+ if (!nonum_[row] && label_[row] &&
+ (cmd.argument().empty() || label(row) == cmd.argument())) {
+ enabled = true;
+ break;
+ }
+ }
+ }
+ status.setEnabled(enabled);
+ return true;
+ }
+
case LFUN_INSET_INSERT:
if (cmd.getArg(0) == "label") {
status.setEnabled(type_ != hullSimple);
return true;
}
return InsetMathGrid::getStatus(cur, cmd, status);
+
case LFUN_TABULAR_FEATURE: {
istringstream is(to_utf8(cmd.argument()));
string s;
}
return InsetMathGrid::getStatus(cur, cmd, status);
}
+
default:
return InsetMathGrid::getStatus(cur, cmd, status);
}
}
-void InsetMathHull::readQuiet(Lexer & lex)
+bool InsetMathHull::readQuiet(Lexer & lex)
{
MathAtom at;
- mathed_parse_normal(at, lex, Parse::QUIET);
+ bool result = mathed_parse_normal(at, lex, Parse::QUIET);
operator=(*at->asHullInset());
+ return result;
}