]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
rename commandtags.h to lfuns.h and renumber/cleanup. Rebuild the tree !
[lyx.git] / src / mathed / ref_inset.C
1
2 #include <config.h>
3
4 #include "ref_inset.h"
5 #include "math_factory.h"
6
7 #include "BufferView.h"
8 #include "debug.h"
9 #include "funcrequest.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
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         switch (cmd.action) {
45                 case LFUN_MOUSE_RELEASE:
46                         if (cmd.button() == mouse_button::button3) {
47                                 lyxerr << "trying to goto ref" << cell(0) << "\n";
48                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
49                                 return DISPATCHED;
50                         }
51                         if (cmd.button() == mouse_button::button1) {
52                                 // Eventually trigger dialog with button 3
53                                 // not 1
54                                 string const data = createDialogStr("ref");
55                                 cmd.view()->owner()->getDialogs().
56                                         show("ref", data, this);
57                                 return DISPATCHED;
58                         }
59                         break;
60                 case LFUN_MOUSE_PRESS:
61                 case LFUN_MOUSE_MOTION:
62                         // eat other mouse commands
63                         return DISPATCHED;
64                 default:
65                         return CommandInset::dispatch(cmd, idx, pos);
66         }
67         // not our business
68         return UNDISPATCHED;
69 }
70
71
72 string RefInset::screenLabel() const
73 {
74         string str;
75         for (int i = 0; !types[i].latex_name.empty(); ++i)
76                 if (name_ == types[i].latex_name) {
77                         str = _(types[i].short_gui_name);
78                         break;
79                 }
80         str += asString(cell(0));
81
82         //if (/* !isLatex && */ !cell(0).empty()) {
83         //      str += "||";
84         //      str += asString(cell(1));
85         //}
86         return str;
87 }
88
89
90 void RefInset::validate(LaTeXFeatures & features) const
91 {
92         if (name_ == "vref" || name_ == "vpageref")
93                 features.require("varioref");
94         else if (name_ == "prettyref")
95                 features.require("prettyref");
96 }
97
98
99 int RefInset::ascii(std::ostream & os, int) const
100 {
101         os << '[' << asString(cell(0)) << ']';
102         return 0;
103 }
104
105
106 int RefInset::linuxdoc(std::ostream & os) const
107 {
108         os << "<ref id=\"" << asString(cell(0))
109            << "\" name=\"" << asString(cell(1)) << "\" >";
110         return 0;
111 }
112
113
114 int RefInset::docbook(std::ostream & os, bool) const
115 {
116         if (cell(1).empty()) {
117                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
118         } else {
119                 os << "<link linkend=\"" << asString(cell(0))
120                    << "\">" << asString(cell(1)) << "</link>";
121         }
122
123         return 0;
124 }
125
126
127 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
128 {
129         if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
130                 return UNDISPATCHED;
131
132         MathArray ar;
133         if (!createMathInset_fromDialogStr(cmd.argument, ar))
134                 return UNDISPATCHED;
135
136         *this = *ar[0].nucleus()->asRefInset();
137 //      if (cmd.view())
138 //                 // This does not compile because updateInset expects
139 //                 // an Inset* and 'this' isn't.
140 //              cmd.view()->updateInset(this);
141         return DISPATCHED;
142 }
143
144
145 RefInset::ref_type_info RefInset::types[] = {
146         { "ref",        N_("Standard"),                 N_("Ref: ")},
147         { "pageref",    N_("Page Number"),              N_("Page: ")},
148         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
149         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
150         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
151         { "", "", "" }
152 };