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