3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "InsetLabel.h"
16 #include "BufferView.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "ParIterator.h"
22 #include "TocBackend.h"
24 #include "support/lstrings.h"
25 #include "support/lyxalgo.h"
28 using namespace lyx::support;
33 InsetLabel::InsetLabel(InsetCommandParams const & p)
34 : InsetCommand(p, "label")
38 ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
40 static ParamInfo param_info_;
41 if (param_info_.empty()) {
42 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
48 Inset * InsetLabel::clone() const
50 return new InsetLabel(params());
54 void InsetLabel::getLabelList(Buffer const &, vector<docstring> & list) const
56 list.push_back(getParam("name"));
60 docstring const InsetLabel::getScreenLabel(Buffer const &) const
62 return getParam("name");
66 void InsetLabel::addToToc(Buffer const & buf,
67 ParConstIterator const & cpit) const
69 Toc & toc = buf.tocBackend().toc("label");
70 toc.push_back(TocItem(cpit, 0, getScreenLabel(buf)));
74 void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
78 case LFUN_INSET_MODIFY: {
79 InsetCommandParams p(LABEL_CODE);
81 InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
82 if (p.getCmdName().empty()) {
86 if (p["name"] != params()["name"])
87 cur.bv().buffer().changeRefsIfUnique(params()["name"],
94 InsetCommand::doDispatch(cur, cmd);
100 int InsetLabel::latex(Buffer const &, odocstream & os,
101 OutputParams const &) const
103 os << escape(getCommand());
108 int InsetLabel::plaintext(Buffer const &, odocstream & os,
109 OutputParams const &) const
111 docstring const str = getParam("name");
112 os << '<' << str << '>';
113 return 2 + str.size();
117 int InsetLabel::docbook(Buffer const & buf, odocstream & os,
118 OutputParams const & runparams) const
120 os << "<!-- anchor id=\""
121 << sgml::cleanID(buf, runparams, getParam("name"))