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