]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
Enable the dialog to parse the string passed to it by RefInset.
[lyx.git] / src / mathed / ref_inset.C
1
2 #include <config.h>
3
4 #include "ref_inset.h"
5 #include "funcrequest.h"
6 #include "formulabase.h"
7 #include "BufferView.h"
8 #include "frontends/LyXView.h"
9 #include "frontends/Painter.h"
10 #include "frontends/Dialogs.h"
11 #include "lyxfunc.h"
12 #include "gettext.h"
13 #include "LaTeXFeatures.h"
14 #include "debug.h"
15 #include "math_mathmlstream.h"
16 #include "Lsstream.h"
17
18
19 RefInset::RefInset()
20         : CommandInset("ref")
21 {}
22
23
24 RefInset::RefInset(string const & data)
25         : CommandInset(data)
26 {}
27
28
29 MathInset * RefInset::clone() const
30 {
31         return new RefInset(*this);
32 }
33
34
35 void RefInset::infoize(std::ostream & os) const
36 {
37         os << "Ref: " << cell(0);
38 }
39
40
41 dispatch_result
42 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
43 {
44         lyxerr << "RefInset::dispatch " << cmd.argument << std::endl;
45         switch (cmd.action) {
46                 case LFUN_MOUSE_RELEASE:
47                         if (cmd.button() == mouse_button::button3) {
48                                 lyxerr << "trying to goto ref" << cell(0) << "\n";
49                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
50                                 return DISPATCHED;
51                         }
52                         if (cmd.button() == mouse_button::button1) {
53                                 // Eventually trigger dialog with button 3
54                                 // not 1
55                                 ostringstream data;
56                                 WriteStream wsdata(data);
57                                 write(wsdata);
58                                 wsdata << "\n\\end_inset\n\n";
59
60                                 cmd.view()->owner()->getDialogs().
61                                         show("ref", data.str(), this);
62                                 return DISPATCHED;
63                         }
64                         break;
65                 case LFUN_MOUSE_PRESS:
66                 case LFUN_MOUSE_MOTION:
67                         // eat other mouse commands
68                         return DISPATCHED;
69                 default:
70                         return CommandInset::dispatch(cmd, idx, pos);
71         }
72         // not our business
73         return UNDISPATCHED;
74 }
75
76
77 string RefInset::screenLabel() const
78 {
79         string str;
80         for (int i = 0; !types[i].latex_name.empty(); ++i)
81                 if (name_ == types[i].latex_name) {
82                         str = _(types[i].short_gui_name);
83                         break;
84                 }
85         str += asString(cell(0));
86
87         //if (/* !isLatex && */ !cell(0).empty()) {
88         //      str += "||";
89         //      str += asString(cell(1));
90         //}
91         return str;
92 }
93
94
95 void RefInset::validate(LaTeXFeatures & features) const
96 {
97         if (name_ == "vref" || name_ == "vpageref")
98                 features.require("varioref");
99         else if (name_ == "prettyref")
100                 features.require("prettyref");
101 }
102
103
104 int RefInset::ascii(std::ostream & os, int) const
105 {
106         os << '[' << asString(cell(0)) << ']';
107         return 0;
108 }
109
110
111 int RefInset::linuxdoc(std::ostream & os) const
112 {
113         os << "<ref id=\"" << asString(cell(0))
114            << "\" name=\"" << asString(cell(1)) << "\" >";
115         return 0;
116 }
117
118
119 int RefInset::docbook(std::ostream & os, bool) const
120 {
121         if (cell(1).empty()) {
122                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
123         } else {
124                 os << "<link linkend=\"" << asString(cell(0))
125                    << "\">" << asString(cell(1)) << "</link>";
126         }
127
128         return 0;
129 }
130
131
132 RefInset::ref_type_info RefInset::types[] = {
133         { "ref",        N_("Standard"),                 N_("Ref: ")},
134         { "pageref",    N_("Page Number"),              N_("Page: ")},
135         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
136         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
137         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
138         { "", "", "" }
139 };