]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRef.C
Fix command-line export
[lyx.git] / src / mathed / InsetMathRef.C
1 /**
2  * \file InsetMathRef.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathRef.h"
14
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
17 #include "buffer.h"
18 #include "cursor.h"
19 #include "debug.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
22 #include "gettext.h"
23 #include "MathData.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "outputparams.h"
27 #include "sgml.h"
28
29 using lyx::docstring;
30
31 using std::string;
32 using std::auto_ptr;
33 using std::endl;
34
35
36 RefInset::RefInset()
37         : CommandInset("ref")
38 {}
39
40
41 RefInset::RefInset(string const & data)
42         : CommandInset(data)
43 {}
44
45
46 auto_ptr<InsetBase> RefInset::doClone() const
47 {
48         return auto_ptr<InsetBase>(new RefInset(*this));
49 }
50
51
52 void RefInset::infoize(std::ostream & os) const
53 {
54         os << "Ref: " << cell(0);
55 }
56
57
58 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
59 {
60         switch (cmd.action) {
61         case LFUN_INSET_MODIFY:
62                 if (cmd.getArg(0) == "ref") {
63                         MathArray ar;
64                         if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
65                                 *this = *ar[0].nucleus()->asRefInset();
66                                 break;
67                         }
68                 }
69                 cur.undispatched();
70                 break;
71
72         case LFUN_INSET_DIALOG_UPDATE: {
73                 string const data = createDialogStr("ref");
74                 cur.bv().updateDialog("ref", data);
75                 break;
76         }
77
78         case LFUN_MOUSE_RELEASE:
79                 if (cmd.button() == mouse_button::button3) {
80                         lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
81                         cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
82                         break;
83                 }
84                 if (cmd.button() == mouse_button::button1) {
85                         // Eventually trigger dialog with button 3, not 1
86                         string const data = createDialogStr("ref");
87                         cur.bv().showInsetDialog("ref", data, this);
88                         break;
89                 }
90                 cur.undispatched();
91                 break;
92
93         case LFUN_MOUSE_PRESS:
94         case LFUN_MOUSE_MOTION:
95                 // eat other mouse commands
96                 break;
97
98         default:
99                 CommandInset::doDispatch(cur, cmd);
100                 break;
101         }
102 }
103
104
105 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
106                          FuncStatus & status) const
107 {
108         switch (cmd.action) {
109         // we handle these
110         case LFUN_INSET_MODIFY:
111         case LFUN_INSET_DIALOG_UPDATE:
112         case LFUN_MOUSE_RELEASE:
113         case LFUN_MOUSE_PRESS:
114         case LFUN_MOUSE_MOTION:
115                 status.enabled(true);
116                 return true;
117         default:
118                 return CommandInset::getStatus(cur, cmd, status);
119         }
120 }
121
122
123 docstring const RefInset::screenLabel() const
124 {
125         docstring str;
126         for (int i = 0; !types[i].latex_name.empty(); ++i)
127                 if (commandname() == types[i].latex_name) {
128                         str = _(types[i].short_gui_name);
129                         break;
130                 }
131         // FIXME UNICODE
132         str += lyx::from_utf8(asString(cell(0)));
133
134         //if (/* !isLatex && */ !cell(0).empty()) {
135         //      str += "||";
136         //      str += asString(cell(1));
137         //}
138         return str;
139 }
140
141
142 void RefInset::validate(LaTeXFeatures & features) const
143 {
144         if (commandname() == "vref" || commandname() == "vpageref")
145                 features.require("varioref");
146         else if (commandname() == "prettyref")
147                 features.require("prettyref");
148 }
149
150
151 int RefInset::plaintext(lyx::odocstream & os, OutputParams const &) const
152 {
153         // FIXME UNICODE
154         os << '[' << lyx::from_utf8(asString(cell(0))) << ']';
155         return 0;
156 }
157
158
159 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
160 {
161         if (cell(1).empty()) {
162                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
163                 if (runparams.flavor == OutputParams::XML)
164                         os << "\"/>";
165                 else
166                         os << "\">";
167         } else {
168                 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
169                    << "\">" << asString(cell(1)) << "</link>";
170         }
171
172         return 0;
173 }
174
175
176 RefInset::ref_type_info RefInset::types[] = {
177         { "ref",       N_("Standard"),              N_("Ref: ")},
178         { "eqref",     N_("Equation"),              N_("EqRef: ")},
179         { "pageref",   N_("Page Number"),           N_("Page: ")},
180         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
181         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
182         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
183         { "", "", "" }
184 };