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 void InsetLabel::getLabelList(vector<docstring> & list) const
50 list.push_back(getParam("name"));
54 docstring InsetLabel::screenLabel() const
56 return getParam("name");
60 void InsetLabel::addToToc(ParConstIterator const & cpit) const
62 Toc & toc = buffer().tocBackend().toc("label");
63 toc.push_back(TocItem(cpit, 0, screenLabel()));
67 void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
71 case LFUN_INSET_MODIFY: {
72 InsetCommandParams p(LABEL_CODE);
74 InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
75 if (p.getCmdName().empty()) {
79 if (p["name"] != params()["name"])
80 cur.bv().buffer().changeRefsIfUnique(params()["name"],
87 InsetCommand::doDispatch(cur, cmd);
93 int InsetLabel::latex(odocstream & os, OutputParams const &) const
95 os << escape(getCommand());
100 int InsetLabel::plaintext(odocstream & os, OutputParams const &) const
102 docstring const str = getParam("name");
103 os << '<' << str << '>';
104 return 2 + str.size();
108 int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
110 os << "<!-- anchor id=\""
111 << sgml::cleanID(buffer(), runparams, getParam("name"))