3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
12 #include "InsetInfo.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
20 #include "FuncRequest.h"
22 #include "InsetSpecialChar.h"
24 #include "LaTeXFeatures.h"
25 #include "LyXAction.h"
27 #include "MetricsInfo.h"
28 #include "ParagraphParameters.h"
29 #include "TextClassList.h"
30 #include "support/lstrings.h"
31 #include "support/ExceptionMessage.h"
36 using std::ostringstream;
41 using support::prefixIs;
45 using support::ExceptionMessage;
46 using support::WarningException;
48 InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
49 : InsetText(bp), bp_(bp), type_(UNKNOWN_INFO), name_(),
52 setAutoBreakRows(true);
58 Inset * InsetInfo::editXY(Cursor & cur, int x, int y)
64 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
66 InsetText::draw(pi, x, y);
69 os << _("Information regarding ")
70 <<_(nameTranslator().find(type_))
71 << _(" ") << from_utf8(name_);
72 pi.base.bv->message(os.str());
79 Translator<InsetInfo::info_type, string> const initTranslator()
81 Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
83 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
84 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
85 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
92 Translator<InsetInfo::info_type, std::string> const & InsetInfo::nameTranslator() const
94 static Translator<info_type, string> const translator =
101 void InsetInfo::read(Buffer const & buf, Lexer & lex)
106 token = lex.getString();
107 if (token == "type") {
109 token = lex.getString();
110 type_ = nameTranslator().find(token);
111 } else if (token == "arg") {
113 name_ = lex.getString();
114 } else if (token == "\\end_inset")
117 if (token != "\\end_inset") {
118 lex.printError("Missing \\end_inset at this point");
119 throw ExceptionMessage(WarningException,
120 _("Missing \\end_inset at this point."),
127 void InsetInfo::write(Buffer const & buf, std::ostream & os) const
129 os << "Info\ntype \""
130 << nameTranslator().find(type_)
131 << "\"\narg \"" << name_ << '\"';
135 void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
137 // FIXME: we should allow selection, copy etc...
138 switch (cmd.action) {
139 case LFUN_MOUSE_PRESS:
140 case LFUN_MOUSE_RELEASE:
141 case LFUN_MOUSE_MOTION:
142 case LFUN_MOUSE_DOUBLE:
143 case LFUN_MOUSE_TRIPLE:
144 // do not dispatch to InsetText
149 InsetText::doDispatch(cur, cmd);
155 void InsetInfo::setInfo(string const & name)
161 name_ = trim(split(name, type, ' '));
162 type_ = nameTranslator().find(type);
167 void InsetInfo::updateInfo()
173 setText(_("Unknown Info: ") + from_utf8(name_),
174 bp_.getFont(), false);
176 case SHORTCUT_INFO: {
177 FuncRequest func = lyxaction.lookupFunc(name_);
178 if (func.action != LFUN_UNKNOWN_ACTION)
179 setText(theTopLevelKeymap().printbindings(func),
180 bp_.getFont(), false);
184 // check in packages.lst
185 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
186 bp_.getFont(), false);
188 case TEXTCLASS_INFO: {
189 // name_ is the class name
190 pair<bool, lyx::textclass_type> pp =
191 textclasslist.numberOfClass(name_);
192 setText(pp.first ? _("yes") : _("no"),
193 bp_.getFont(), false);
198 paragraphs().begin()->params().noindent(true);
202 bool InsetInfo::setMouseHover(bool mouse_hover)
204 mouse_hover_ = mouse_hover;