]> git.lyx.org Git - features.git/blob - src/insets/InsetLabel.cpp
Add list of labels. If I have the time and energy the next step is to cleanup the...
[features.git] / src / insets / InsetLabel.cpp
1 /**
2  * \file InsetLabel.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetLabel.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "ParIterator.h"
20 #include "sgml.h"
21 #include "Text.h"
22 #include "TocBackend.h"
23
24 #include "support/lstrings.h"
25 #include "support/lyxalgo.h"
26
27 using namespace std;
28 using namespace lyx::support;
29
30 namespace lyx {
31
32
33 InsetLabel::InsetLabel(InsetCommandParams const & p)
34         : InsetCommand(p, "label")
35 {}
36
37
38 ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
39 {
40         static ParamInfo param_info_;
41         if (param_info_.empty()) {
42                 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
43         }
44         return param_info_;
45 }
46
47
48 Inset * InsetLabel::clone() const
49 {
50         return new InsetLabel(params());
51 }
52
53
54 void InsetLabel::getLabelList(Buffer const &, vector<docstring> & list) const
55 {
56         list.push_back(getParam("name"));
57 }
58
59
60 docstring const InsetLabel::getScreenLabel(Buffer const &) const
61 {
62         return getParam("name");
63 }
64
65
66 void InsetLabel::addToToc(Buffer const & buf,
67         ParConstIterator const & cpit) const
68 {
69         ParConstIterator pit = cpit;
70         pit.push_back(*this);
71
72         //FIXME: It would be really, really, really nice if we could
73         // construct a tree here with all the cross-reference to this
74         // label.
75
76         Toc & toc = buf.tocBackend().toc("label");
77         toc.push_back(TocItem(pit, 0, getScreenLabel(buf)));
78 }
79
80
81 void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
82 {
83         switch (cmd.action) {
84
85         case LFUN_INSET_MODIFY: {
86                 InsetCommandParams p(LABEL_CODE);
87                 // FIXME UNICODE
88                 InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
89                 if (p.getCmdName().empty()) {
90                         cur.noUpdate();
91                         break;
92                 }
93                 if (p["name"] != params()["name"])
94                         cur.bv().buffer().changeRefsIfUnique(params()["name"],
95                                         p["name"], REF_CODE);
96                 setParams(p);
97                 break;
98         }
99
100         default:
101                 InsetCommand::doDispatch(cur, cmd);
102                 break;
103         }
104 }
105
106
107 int InsetLabel::latex(Buffer const &, odocstream & os,
108                       OutputParams const &) const
109 {
110         os << escape(getCommand());
111         return 0;
112 }
113
114
115 int InsetLabel::plaintext(Buffer const &, odocstream & os,
116                           OutputParams const &) const
117 {
118         docstring const str = getParam("name");
119         os << '<' << str << '>';
120         return 2 + str.size();
121 }
122
123
124 int InsetLabel::docbook(Buffer const & buf, odocstream & os,
125                         OutputParams const & runparams) const
126 {
127         os << "<!-- anchor id=\""
128            << sgml::cleanID(buf, runparams, getParam("name"))
129            << "\" -->";
130         return 0;
131 }
132
133
134 } // namespace lyx