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"
14 #include "LayoutFile.h"
16 #include "BufferParams.h"
17 #include "BufferView.h"
18 #include "FuncRequest.h"
19 #include "InsetSpecialChar.h"
21 #include "LaTeXFeatures.h"
22 #include "LyXAction.h"
25 #include "MetricsInfo.h"
26 #include "ParagraphParameters.h"
28 #include "frontends/Application.h"
30 #include "support/debug.h"
31 #include "support/docstream.h"
32 #include "support/FileName.h"
33 #include "support/gettext.h"
34 #include "support/lstrings.h"
35 #include "support/ExceptionMessage.h"
40 using namespace lyx::support;
45 InsetInfo::InsetInfo(Buffer const & buf, string const & name)
46 : InsetText(buf), type_(UNKNOWN_INFO), name_(),
49 setAutoBreakRows(true);
55 Inset * InsetInfo::editXY(Cursor &, int, int)
61 void InsetInfo::draw(PainterInfo & pi, int x, int y) const
63 InsetText::draw(pi, x, y);
66 os << _("Information regarding ")
67 <<_(nameTranslator().find(type_))
68 << " " << from_utf8(name_);
69 pi.base.bv->message(os.str());
76 Translator<InsetInfo::info_type, string> const initTranslator()
78 Translator<InsetInfo::info_type, string>
79 translator(InsetInfo::UNKNOWN_INFO, "unknown");
81 translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
82 translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
83 translator.addPair(InsetInfo::PACKAGE_INFO, "package");
84 translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
85 translator.addPair(InsetInfo::MENU_INFO, "menu");
86 translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
93 Translator<InsetInfo::info_type, string>
94 const & InsetInfo::nameTranslator() const
96 static Translator<info_type, string> const translator = initTranslator();
102 void InsetInfo::read(Lexer & lex)
107 token = lex.getString();
108 if (token == "type") {
110 token = lex.getString();
111 type_ = nameTranslator().find(token);
112 } else if (token == "arg") {
114 name_ = lex.getString();
115 } else if (token == "\\end_inset")
118 if (token != "\\end_inset") {
119 lex.printError("Missing \\end_inset at this point");
120 throw ExceptionMessage(WarningException,
121 _("Missing \\end_inset at this point."),
128 void InsetInfo::write(ostream & os) const
130 os << "Info\ntype \"" << 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);
166 void InsetInfo::updateInfo()
170 BufferParams const & bp = buffer().params();
174 setText(_("Unknown Info: ") + from_utf8(name_),
175 bp.getFont(), false);
177 case SHORTCUT_INFO: {
178 FuncRequest func = lyxaction.lookupFunc(name_);
179 if (func.action != LFUN_UNKNOWN_ACTION)
180 setText(theTopLevelKeymap().printBindings(func),
181 bp.getFont(), false);
186 lyxrc.write(oss, true, name_);
187 string result = oss.str();
188 // remove leading \\name
189 result = result.substr(name_.size() + 2);
191 result = rtrim(result, "\n");
192 result = trim(result, "\"");
193 setText(from_utf8(result), bp.getFont(), false);
197 // check in packages.lst
198 setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
199 bp.getFont(), false);
201 case TEXTCLASS_INFO: {
202 // name_ is the class name
203 setText(LayoutFileList::get().haveClass(name_) ? _("yes") : _("no"),
204 bp.getFont(), false);
208 vector<docstring> names;
209 FuncRequest func = lyxaction.lookupFunc(name_);
210 if (func.action == LFUN_UNKNOWN_ACTION) {
211 setText(bformat(_("Unknown action %1$s"), from_utf8(name_)), bp.getFont(), false);
214 // iterate through the menubackend to find it
215 if (!theApp()->searchMenu(func, names)) {
216 setText(bformat(_("No menu entry for action %1$s"), from_utf8(name_)),
217 bp.getFont(), false);
220 // if find, return its path.
222 Paragraph & info = paragraphs().front();
224 while (!names.empty()) {
225 // do not insert > for the top level menu item
227 info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
228 Change(Change::UNCHANGED));
229 for (i = 0; i != names.back().length(); ++i)
230 info.insertChar(i, names.back()[i], bp.getFont(), false);
237 setText(from_utf8(buffer().fileName().onlyFileName()),
238 bp.getFont(), false);
239 else if (name_ == "path")
240 setText(from_utf8(buffer().filePath()), bp.getFont(), false);
241 else if (name_ == "class")
242 setText(from_utf8(bp.documentClass().name()), bp.getFont(), false);
244 setText(_("Unknown buffer info"), bp.getFont(), false);
249 paragraphs().begin()->params().noindent(true);
253 bool InsetInfo::setMouseHover(bool mouse_hover)
255 mouse_hover_ = mouse_hover;