]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
remove noload/don't typeset
[lyx.git] / src / insets / insetref.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "insetref.h"
8 #include "buffer.h"
9 #include "funcrequest.h"
10 #include "debug.h"
11 #include "gettext.h"
12 #include "LaTeXFeatures.h"
13 #include "frontends/LyXView.h"
14 #include "frontends/Dialogs.h"
15 #include "BufferView.h"
16 #include "support/lstrings.h"
17
18 using std::ostream;
19
20 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
21         : InsetCommand(p), isLatex(buf.isLatex())
22 {}
23
24
25 void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
26 {
27         // FuncRequestually trigger dialog with button 3 not 1
28         if (button == mouse_button::button3)
29                 bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
30         else if (button == mouse_button::button1)
31                 bv->owner()->getDialogs().showRef(this);
32 }
33
34
35 void InsetRef::edit(BufferView *, bool)
36 {}
37
38
39 string const InsetRef::getScreenLabel(Buffer const *) const
40 {
41         string temp;
42         for (int i = 0; !types[i].latex_name.empty(); ++ i)
43                 if (getCmdName() == types[i].latex_name) {
44                         temp = _(types[i].short_gui_name);
45                         break;
46                 }
47         temp += getContents();
48
49         if (!isLatex
50            && !getOptions().empty()) {
51                 temp += "||";
52                 temp += getOptions();
53         }
54         return temp;
55 }
56
57
58 int InsetRef::latex(Buffer const *, ostream & os,
59                     bool /*fragile*/, bool /*fs*/) const
60 {
61         if (getOptions().empty())
62                 os << escape(getCommand());
63         else {
64                 InsetCommandParams p(getCmdName(), getContents(), "");
65                 os << escape(p.getCommand());
66         }
67         return 0;
68 }
69
70
71 int InsetRef::ascii(Buffer const *, ostream & os, int) const
72 {
73         os << "[" << getContents() << "]";
74         return 0;
75 }
76
77
78 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
79 {
80         os << "<ref id=\"" << getContents()
81            << "\" name=\"" << getOptions() << "\" >";
82         return 0;
83 }
84
85
86 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
87 {
88         if (getOptions().empty()) {
89                 os << "<xref linkend=\"" << getContents() << "\">";
90         } else {
91                 os << "<link linkend=\"" << getContents()
92                    << "\">" << getOptions() << "</link>";
93         }
94
95         return 0;
96 }
97
98
99 void InsetRef::validate(LaTeXFeatures & features) const
100 {
101         if (getCmdName() == "vref" || getCmdName() == "vpageref")
102                 features.require("varioref");
103         else if (getCmdName() == "prettyref")
104                 features.require("prettyref");
105 }
106
107
108 InsetRef::type_info InsetRef::types[] = {
109         { "ref",        N_("Standard"),                 N_("Ref: ")},
110         { "pageref",    N_("Page Number"),              N_("Page: ")},
111         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
112         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
113         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
114         { "", "", "" }
115 };
116
117
118 int InsetRef::getType(string const & name)
119 {
120         for (int i = 0; !types[i].latex_name.empty(); ++i)
121                 if (name == types[i].latex_name)
122                         return i;
123         return 0;
124 }
125
126
127 string const & InsetRef::getName(int type)
128 {
129         return types[type].latex_name;
130 }