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 "MenuBackend.h"
28 #include "MetricsInfo.h"
29 #include "ParagraphParameters.h"
30 #include "TextClassList.h"
31 #include "support/lstrings.h"
32 #include "support/ExceptionMessage.h"
37 using std::ostringstream;
42 using support::prefixIs;
46 using support::ExceptionMessage;
47 using support::WarningException;
49 InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
50 : InsetText(bp), bp_(bp), type_(UNKNOWN_INFO), name_(),
53 setAutoBreakRows(true);
59 Inset * InsetInfo::editXY(Cursor & cur, int x, int y)
65 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
67 InsetText::draw(pi, x, y);
70 os << _("Information regarding ")
71 <<_(nameTranslator().find(type_))
72 << _(" ") << from_utf8(name_);
73 pi.base.bv->message(os.str());
80 Translator<InsetInfo::info_type, string> const initTranslator()
82 Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
84 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
85 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
86 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
87 translator.addPair(InsetInfo::MENU_INFO, "menu");
94 Translator<InsetInfo::info_type, std::string> const & InsetInfo::nameTranslator() const
96 static Translator<info_type, string> const translator =
103 void InsetInfo::read(Buffer const & buf, Lexer & lex)
108 token = lex.getString();
109 if (token == "type") {
111 token = lex.getString();
112 type_ = nameTranslator().find(token);
113 } else if (token == "arg") {
115 name_ = lex.getString();
116 } else if (token == "\\end_inset")
119 if (token != "\\end_inset") {
120 lex.printError("Missing \\end_inset at this point");
121 throw ExceptionMessage(WarningException,
122 _("Missing \\end_inset at this point."),
129 void InsetInfo::write(Buffer const & buf, std::ostream & os) const
131 os << "Info\ntype \""
132 << nameTranslator().find(type_)
133 << "\"\narg \"" << name_ << '\"';
137 void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
139 // FIXME: we should allow selection, copy etc...
140 switch (cmd.action) {
141 case LFUN_MOUSE_PRESS:
142 case LFUN_MOUSE_RELEASE:
143 case LFUN_MOUSE_MOTION:
144 case LFUN_MOUSE_DOUBLE:
145 case LFUN_MOUSE_TRIPLE:
146 // do not dispatch to InsetText
151 InsetText::doDispatch(cur, cmd);
157 void InsetInfo::setInfo(string const & name)
163 name_ = trim(split(name, type, ' '));
164 type_ = nameTranslator().find(type);
169 void InsetInfo::updateInfo()
175 setText(_("Unknown Info: ") + from_utf8(name_),
176 bp_.getFont(), false);
178 case SHORTCUT_INFO: {
179 FuncRequest func = lyxaction.lookupFunc(name_);
180 if (func.action != LFUN_UNKNOWN_ACTION)
181 setText(theTopLevelKeymap().printbindings(func),
182 bp_.getFont(), false);
186 // check in packages.lst
187 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
188 bp_.getFont(), false);
190 case TEXTCLASS_INFO: {
191 // name_ is the class name
192 pair<bool, lyx::textclass_type> pp =
193 textclasslist.numberOfClass(name_);
194 setText(pp.first ? _("yes") : _("no"),
195 bp_.getFont(), false);
199 stack<docstring> names;
200 FuncRequest func = lyxaction.lookupFunc(name_);
201 if (func.action == LFUN_UNKNOWN_ACTION) {
202 setText(_("No menu entry for "), bp_.getFont(), false);
205 // iterate through the menubackend to find it
206 Menu menu = menubackend.getMenubar();
207 if (!menu.searchFunc(func, names)) {
208 setText(_("No menu entry for "), bp_.getFont(), false);
211 // if find, return its path.
213 Paragraph & info = paragraphs().front();
215 while (!names.empty()) {
216 // do not insert > for the top level menu item
218 info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
219 Change(Change::UNCHANGED));
220 for (i = 0; i < names.top().length(); ++i)
221 info.insertChar(i, names.top()[i], bp_.getFont(), false);
228 paragraphs().begin()->params().noindent(true);
232 bool InsetInfo::setMouseHover(bool mouse_hover)
234 mouse_hover_ = mouse_hover;