#include "insets/RenderPreview.h"
#include "insets/InsetLabel.h"
+#include "insets/InsetRef.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
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;
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().
buffer().updateLabels();
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() != Inline;
+ : 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);
}