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"
22 #include "support/lstrings.h"
23 #include "support/lyxalgo.h"
26 using namespace lyx::support;
31 InsetLabel::InsetLabel(InsetCommandParams const & p)
32 : InsetCommand(p, "label")
36 CommandInfo const * InsetLabel::findInfo(string const & /* cmdName */)
38 static const char * const paramnames[] = {"name", ""};
39 static const bool isoptional[] = {false};
40 static const CommandInfo info = {1, paramnames, isoptional};
45 Inset * InsetLabel::clone() const
47 return new InsetLabel(params());
51 void InsetLabel::getLabelList(Buffer const &, vector<docstring> & list) const
53 list.push_back(getParam("name"));
57 docstring const InsetLabel::getScreenLabel(Buffer const &) const
59 return getParam("name");
63 void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
67 case LFUN_INSET_MODIFY: {
68 InsetCommandParams p(LABEL_CODE);
70 InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
71 if (p.getCmdName().empty()) {
75 if (p["name"] != params()["name"])
76 cur.bv().buffer().changeRefsIfUnique(params()["name"],
83 InsetCommand::doDispatch(cur, cmd);
89 int InsetLabel::latex(Buffer const &, odocstream & os,
90 OutputParams const &) const
92 os << escape(getCommand());
97 int InsetLabel::plaintext(Buffer const &, odocstream & os,
98 OutputParams const &) const
100 docstring const str = getParam("name");
101 os << '<' << str << '>';
102 return 2 + str.size();
106 int InsetLabel::docbook(Buffer const & buf, odocstream & os,
107 OutputParams const & runparams) const
109 os << "<!-- anchor id=\""
110 << sgml::cleanID(buf, runparams, getParam("name"))