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"
28 #include "MenuBackend.h"
29 #include "MetricsInfo.h"
30 #include "ParagraphParameters.h"
31 #include "TextClassList.h"
33 #include "support/docstream.h"
34 #include "support/lstrings.h"
35 #include "support/ExceptionMessage.h"
40 using std::ostringstream;
45 using support::prefixIs;
49 using support::ExceptionMessage;
50 using support::WarningException;
52 InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
53 : InsetText(bp), type_(UNKNOWN_INFO), name_(), bp_(bp),
56 setAutoBreakRows(true);
62 Inset * InsetInfo::editXY(Cursor &, int, int)
68 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
70 InsetText::draw(pi, x, y);
73 os << _("Information regarding ")
74 <<_(nameTranslator().find(type_))
75 << _(" ") << from_utf8(name_);
76 pi.base.bv->message(os.str());
83 Translator<InsetInfo::info_type, string> const initTranslator()
85 Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
87 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
88 translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
89 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
90 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
91 translator.addPair(InsetInfo::MENU_INFO, "menu");
98 Translator<InsetInfo::info_type, std::string> const & InsetInfo::nameTranslator() const
100 static Translator<info_type, string> const translator =
107 void InsetInfo::read(Buffer const &, Lexer & lex)
112 token = lex.getString();
113 if (token == "type") {
115 token = lex.getString();
116 type_ = nameTranslator().find(token);
117 } else if (token == "arg") {
119 name_ = lex.getString();
120 } else if (token == "\\end_inset")
123 if (token != "\\end_inset") {
124 lex.printError("Missing \\end_inset at this point");
125 throw ExceptionMessage(WarningException,
126 _("Missing \\end_inset at this point."),
133 void InsetInfo::write(Buffer const &, std::ostream & os) const
135 os << "Info\ntype \""
136 << nameTranslator().find(type_)
137 << "\"\narg \"" << name_ << '\"';
141 void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
143 // FIXME: we should allow selection, copy etc...
144 switch (cmd.action) {
145 case LFUN_MOUSE_PRESS:
146 case LFUN_MOUSE_RELEASE:
147 case LFUN_MOUSE_MOTION:
148 case LFUN_MOUSE_DOUBLE:
149 case LFUN_MOUSE_TRIPLE:
150 // do not dispatch to InsetText
155 InsetText::doDispatch(cur, cmd);
161 void InsetInfo::setInfo(string const & name)
167 name_ = trim(split(name, type, ' '));
168 type_ = nameTranslator().find(type);
173 void InsetInfo::updateInfo()
179 setText(_("Unknown Info: ") + from_utf8(name_),
180 bp_.getFont(), false);
182 case SHORTCUT_INFO: {
183 FuncRequest func = lyxaction.lookupFunc(name_);
184 if (func.action != LFUN_UNKNOWN_ACTION)
185 setText(theTopLevelKeymap().printBindings(func),
186 bp_.getFont(), false);
191 lyxrc.write(oss, true, name_);
192 string result = oss.str();
193 // remove leading \\name
194 result = result.substr(name_.size() + 2);
196 result = rtrim(result, "\n");
197 result = trim(result, "\"");
198 setText(from_utf8(result), bp_.getFont(), false);
202 // check in packages.lst
203 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
204 bp_.getFont(), false);
206 case TEXTCLASS_INFO: {
207 // name_ is the class name
208 pair<bool, lyx::textclass_type> pp =
209 textclasslist.numberOfClass(name_);
210 setText(pp.first ? _("yes") : _("no"),
211 bp_.getFont(), false);
215 stack<docstring> names;
216 FuncRequest func = lyxaction.lookupFunc(name_);
217 if (func.action == LFUN_UNKNOWN_ACTION) {
218 setText(_("No menu entry for "), bp_.getFont(), false);
221 // iterate through the menubackend to find it
222 Menu menu = menubackend.getMenubar();
223 if (!menu.searchFunc(func, names)) {
224 setText(_("No menu entry for "), bp_.getFont(), false);
227 // if find, return its path.
229 Paragraph & info = paragraphs().front();
231 while (!names.empty()) {
232 // do not insert > for the top level menu item
234 info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
235 Change(Change::UNCHANGED));
236 for (i = 0; i < names.top().length(); ++i)
237 info.insertChar(i, names.top()[i], bp_.getFont(), false);
244 paragraphs().begin()->params().noindent(true);
248 bool InsetInfo::setMouseHover(bool mouse_hover)
250 mouse_hover_ = mouse_hover;