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"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "FuncRequest.h"
21 #include "InsetSpecialChar.h"
23 #include "LaTeXFeatures.h"
24 #include "LyXAction.h"
27 #include "MenuBackend.h"
28 #include "MetricsInfo.h"
29 #include "ParagraphParameters.h"
30 #include "TextClassList.h"
32 #include "frontends/Application.h"
34 #include "support/debug.h"
35 #include "support/docstream.h"
36 #include "support/FileName.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39 #include "support/ExceptionMessage.h"
42 using namespace lyx::support;
47 InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
48 : InsetText(bp), type_(UNKNOWN_INFO), name_(),
51 setAutoBreakRows(true);
57 Inset * InsetInfo::editXY(Cursor &, int, int)
63 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
65 InsetText::draw(pi, x, y);
68 os << _("Information regarding ")
69 <<_(nameTranslator().find(type_))
70 << _(" ") << from_utf8(name_);
71 pi.base.bv->message(os.str());
78 Translator<InsetInfo::info_type, string> const initTranslator()
80 Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
82 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
83 translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
84 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
85 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
86 translator.addPair(InsetInfo::MENU_INFO, "menu");
87 translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
94 Translator<InsetInfo::info_type, 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 &, 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);
168 void InsetInfo::updateInfo(Buffer const & buf)
172 BufferParams const & bp = buf.params();
176 setText(_("Unknown Info: ") + from_utf8(name_),
177 bp.getFont(), false);
179 case SHORTCUT_INFO: {
180 FuncRequest func = lyxaction.lookupFunc(name_);
181 if (func.action != LFUN_UNKNOWN_ACTION)
182 setText(theTopLevelKeymap().printBindings(func),
183 bp.getFont(), false);
188 lyxrc.write(oss, true, name_);
189 string result = oss.str();
190 // remove leading \\name
191 result = result.substr(name_.size() + 2);
193 result = rtrim(result, "\n");
194 result = trim(result, "\"");
195 setText(from_utf8(result), bp.getFont(), false);
199 // check in packages.lst
200 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
201 bp.getFont(), false);
203 case TEXTCLASS_INFO: {
204 // name_ is the class name
205 pair<bool, lyx::textclass_type> pp =
206 textclasslist.numberOfClass(name_);
207 setText(pp.first ? _("yes") : _("no"),
208 bp.getFont(), false);
212 stack<docstring> names;
213 FuncRequest func = lyxaction.lookupFunc(name_);
214 if (func.action == LFUN_UNKNOWN_ACTION) {
215 setText(_("No menu entry for "), bp.getFont(), false);
218 // iterate through the menubackend to find it
219 Menu menu = theApp()->menuBackend().getMenubar();
220 if (!menu.searchFunc(func, names)) {
221 setText(_("No menu entry for "), bp.getFont(), false);
224 // if find, return its path.
226 Paragraph & info = paragraphs().front();
228 while (!names.empty()) {
229 // do not insert > for the top level menu item
231 info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
232 Change(Change::UNCHANGED));
233 for (i = 0; i < names.top().length(); ++i)
234 info.insertChar(i, names.top()[i], bp.getFont(), false);
241 setText(from_utf8(buf.fileName().onlyFileName()), bp.getFont(), false);
242 else if (name_ == "path")
243 setText(from_utf8(buf.filePath()), bp.getFont(), false);
244 else if (name_ == "class")
245 setText(from_utf8(bp.getTextClass().name()), bp.getFont(), false);
247 setText(_("Unknown buffer info"), bp.getFont(), false);
252 paragraphs().begin()->params().noindent(true);
256 bool InsetInfo::setMouseHover(bool mouse_hover)
258 mouse_hover_ = mouse_hover;