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"
19 #include "support/debug.h"
20 #include "FuncRequest.h"
21 #include "support/gettext.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"
38 using namespace lyx::support;
43 InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
44 : InsetText(bp), type_(UNKNOWN_INFO), name_(), bp_(bp),
47 setAutoBreakRows(true);
53 Inset * InsetInfo::editXY(Cursor &, int, int)
59 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
61 InsetText::draw(pi, x, y);
64 os << _("Information regarding ")
65 <<_(nameTranslator().find(type_))
66 << _(" ") << from_utf8(name_);
67 pi.base.bv->message(os.str());
74 Translator<InsetInfo::info_type, string> const initTranslator()
76 Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
78 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
79 translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
80 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
81 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
82 translator.addPair(InsetInfo::MENU_INFO, "menu");
89 Translator<InsetInfo::info_type, std::string> const & InsetInfo::nameTranslator() const
91 static Translator<info_type, string> const translator =
98 void InsetInfo::read(Buffer const &, Lexer & lex)
103 token = lex.getString();
104 if (token == "type") {
106 token = lex.getString();
107 type_ = nameTranslator().find(token);
108 } else if (token == "arg") {
110 name_ = lex.getString();
111 } else if (token == "\\end_inset")
114 if (token != "\\end_inset") {
115 lex.printError("Missing \\end_inset at this point");
116 throw ExceptionMessage(WarningException,
117 _("Missing \\end_inset at this point."),
124 void InsetInfo::write(Buffer const &, std::ostream & os) const
126 os << "Info\ntype \""
127 << nameTranslator().find(type_)
128 << "\"\narg \"" << name_ << '\"';
132 void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
134 // FIXME: we should allow selection, copy etc...
135 switch (cmd.action) {
136 case LFUN_MOUSE_PRESS:
137 case LFUN_MOUSE_RELEASE:
138 case LFUN_MOUSE_MOTION:
139 case LFUN_MOUSE_DOUBLE:
140 case LFUN_MOUSE_TRIPLE:
141 // do not dispatch to InsetText
146 InsetText::doDispatch(cur, cmd);
152 void InsetInfo::setInfo(string const & name)
158 name_ = trim(split(name, type, ' '));
159 type_ = nameTranslator().find(type);
164 void InsetInfo::updateInfo()
170 setText(_("Unknown Info: ") + from_utf8(name_),
171 bp_.getFont(), false);
173 case SHORTCUT_INFO: {
174 FuncRequest func = lyxaction.lookupFunc(name_);
175 if (func.action != LFUN_UNKNOWN_ACTION)
176 setText(theTopLevelKeymap().printBindings(func),
177 bp_.getFont(), false);
182 lyxrc.write(oss, true, name_);
183 string result = oss.str();
184 // remove leading \\name
185 result = result.substr(name_.size() + 2);
187 result = rtrim(result, "\n");
188 result = trim(result, "\"");
189 setText(from_utf8(result), bp_.getFont(), false);
193 // check in packages.lst
194 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
195 bp_.getFont(), false);
197 case TEXTCLASS_INFO: {
198 // name_ is the class name
199 pair<bool, lyx::textclass_type> pp =
200 textclasslist.numberOfClass(name_);
201 setText(pp.first ? _("yes") : _("no"),
202 bp_.getFont(), false);
206 stack<docstring> names;
207 FuncRequest func = lyxaction.lookupFunc(name_);
208 if (func.action == LFUN_UNKNOWN_ACTION) {
209 setText(_("No menu entry for "), bp_.getFont(), false);
212 // iterate through the menubackend to find it
213 Menu menu = menubackend.getMenubar();
214 if (!menu.searchFunc(func, names)) {
215 setText(_("No menu entry for "), bp_.getFont(), false);
218 // if find, return its path.
220 Paragraph & info = paragraphs().front();
222 while (!names.empty()) {
223 // do not insert > for the top level menu item
225 info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
226 Change(Change::UNCHANGED));
227 for (i = 0; i < names.top().length(); ++i)
228 info.insertChar(i, names.top()[i], bp_.getFont(), false);
235 paragraphs().begin()->params().noindent(true);
239 bool InsetInfo::setMouseHover(bool mouse_hover)
241 mouse_hover_ = mouse_hover;