#include "FuncStatus.h"
#include "Lexer.h"
#include "MetricsInfo.h"
-#include "OutputParams.h"
-#include "output_xhtml.h"
+#include "xml.h"
+#include "texstream.h"
#include "Text.h"
#include "support/debug.h"
int const ADD_TO_VSPACE_WIDTH = 5;
-} // namespace anon
+} // namespace
InsetVSpace::InsetVSpace(VSpace const & space)
- : Inset(0), space_(space)
+ : Inset(nullptr), space_(space)
{}
-InsetVSpace::~InsetVSpace()
-{
- hideDialogs("vspace", this);
-}
-
-
void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
{
- switch (cmd.action) {
+ switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
- InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
+ cur.recordUndo();
+ string arg = to_utf8(cmd.argument());
+ if (arg == "vspace custom")
+ arg = (space_.kind() == VSpace::LENGTH)
+ ? "vspace " + space_.length().asString()
+ : "vspace 1" + string(stringFromUnit(Length::defaultUnit()));
+ InsetVSpace::string2params(arg, space_);
break;
}
bool InsetVSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
- switch (cmd.action) {
+ switch (cmd.action()) {
// we handle these
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "vspace") {
VSpace vspace;
- InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
+ string arg = to_utf8(cmd.argument());
+ if (arg == "vspace custom")
+ arg = (space_.kind() == VSpace::LENGTH)
+ ? "vspace " + space_.length().asString()
+ : "vspace 1" + string(stringFromUnit(Length::defaultUnit()));
+ InsetVSpace::string2params(arg, vspace);
status.setOnOff(vspace == space_);
- }
+ }
status.setEnabled(true);
return true;
-
+
default:
return Inset::getStatus(cur, cmd, status);
}
}
-bool InsetVSpace::showInsetDialog(BufferView * bv) const
-{
- bv->showDialog("vspace", params2string(space()),
- const_cast<InsetVSpace *>(this));
- return true;
-}
-
-
void InsetVSpace::read(Lexer & lex)
{
- LASSERT(lex.isOK(), /**/);
+ LASSERT(lex.isOK(), return);
string vsp;
lex >> vsp;
if (lex)
dim.asc = height / 2 + (a - d) / 2; // align cursor with the
dim.des = height - dim.asc; // label text
dim.wid = ADD_TO_VSPACE_WIDTH + 2 * vspace_arrow_size + 5 + w;
- // Cache the inset dimension.
- setDimCache(mi, dim);
}
}
-int InsetVSpace::latex(odocstream & os, OutputParams const &) const
+void InsetVSpace::latex(otexstream & os, OutputParams const & rp) const
{
- os << from_ascii(space_.asLatexCommand(buffer().params())) << '\n';
- return 1;
+ os << from_ascii(space_.asLatexCommand(buffer().params())) << breakln;
+ if (rp.need_noindent) {
+ // If the paragraph starts with a vspace and has more than that
+ // content, the \\noindent needs to come after that
+ // (as \\noindent leaves vmode).
+ os << "\\noindent" << termcmd;
+ }
}
-int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const
+int InsetVSpace::plaintext(odocstringstream & os,
+ OutputParams const &, size_t) const
{
os << "\n\n";
return PLAINTEXT_NEWLINE;
}
-int InsetVSpace::docbook(odocstream & os, OutputParams const &) const
+void InsetVSpace::docbook(XMLStream & xs, OutputParams const &) const
{
- os << '\n';
- return 1;
+ xs << xml::CR();
}
-docstring InsetVSpace::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetVSpace::xhtml(XMLStream & os, OutputParams const &) const
{
- odocstringstream ods;
- XHTMLStream xds(ods);
string const len = space_.asHTMLLength();
string const attr = "style='height:" + (len.empty() ? "1em" : len) + "'";
- xds << StartTag("div", attr, true) << EndTag("div");
- return ods.str();
+ os << xml::StartTag("div", attr, true) << xml::EndTag("div");
+ return docstring();
}
-docstring InsetVSpace::contextMenu(BufferView const &, int, int) const
+string InsetVSpace::contextMenuName() const
{
- return from_ascii("context-vspace");
+ return "context-vspace";
}