4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "InsetCollapsible.h"
21 /* InsetInfo displays shortcuts, lyxrc, package and textclass
22 availability and menu information in a non-editable boxed InsetText.
24 Output of such an inset may vary from system to system, depending
25 on LyX and LaTeX configurations. Two LyX help files, LaTeXConfig.lyx
26 and Shortcuts.lyx make heavy use of this inset. The former uses it
27 to display the availability of packages and textclasses, the latter
28 uses it to display currently used shortcuts.
30 This inset has two arguments: the type and argument of the information. The
31 screen and latex output is the content of the information. An InsetInfo can
32 have type "shortcuts", "shortcut", "lyxrc", "package", "textclass", "menu",
33 "buffer" or "vcs". Arguments and outputs vary by type.
35 date: argument of this type of InsetInfo is either a fixed date type of
36 "long" (long localized date, with weekday, as provided by QLocale),
37 "short" (short localized date, with two-digit year, as provided by QLocale),
38 "loclong" (long localized date, without weekday, defined in languages),
39 "locmedium" (medium localized date, defined in languages),
40 "locshort" (short localized date, with four-digit year, defined in languages),
41 "ISO" (ISO-conforming date)
42 or a custom date using the QDate syntax.
43 The output is a localized formatted (current) date.
45 moddate: Same as date.
46 The output is a localized formatted date of last file modification (saving).
48 fixdate: Same as date. A fixed date (in ISO format) is prepended to the argument,
50 The output is a localized formatted fix date.
52 time: argument of this type of InsetInfo is either a fixed time type of
53 "long" (long localized time, as provided by QLocale),
54 "short" (short localized time, as provided by QLocale),
55 "ISO" (ISO-conforming time)
56 or a custom date using the QTime syntax.
57 The output is a localized formatted (current) time.
59 modtime: Same as time.
60 The output is a localized formatted time of last file modification (saving).
62 fixtime: Same as time. A fixed time (in ISO format) is prepended to the argument,
64 The output is a localized formatted fix time.
66 shortcuts: argument is the name of the LFUN such as "math-insert \alpha".
67 The syntax is the same as what is used in the bind and ui files.
68 The output of this inset is all shortcuts for this LFUN separated by comma.
70 shortcut: the same as shortcuts, but only output the last shortcut.
72 lyxrc: argument is the name of the rc entry such as "bind_file". Look in
73 src/LyXRC.h for available entries. The output is the content of this RC
76 package: argument is the name of a latex package such as "listings". The
77 output is "yes" or "no", indicating the availability of this package.
79 textclass: argument is the name a textclass such as "article". The output is
80 "yes" or "no", indicating the availability of this textclass.
82 menu: argument is the name of the LFUN such as "paste". The syntax is the same
83 as what is used in the bind and ui files. The output is the menu item that
84 triggers this LFUN. For example, "File > Paste", where '>' is actually
85 \lyxarrow (an InsetSpecialChar).
87 l7n: argument is an English string that is marked for localization. The output
88 is the localization of that string in the current GUI language (if available).
89 Trailing colons are stripped, accelerators removed.
90 This is used to refer to GUI items in the docs.
92 icon: argument is the name of the LFUN such as "paste". The syntax is the same
93 as what is used in the bind and ui files. The output is the icon use in
94 the toolbar for this LFUN. Alternatively, argument can be the icon path
95 without extension specified with respect to the images directory.
97 buffer: argument can be one of "name", "name-noext", "path", "class". This inset output the
98 filename (with extension), filename (without extension), path, and textclass of this buffer.
100 lyxinfo: argument must be "version" or "layoutformat". This outputs information
101 about the version of LyX currently in use or the current LyX layout format, respectively.
103 vcs: argument can be one of "revision", "tree-revision", "author", "time", "date".
104 This insets outputs revision control information, if available.
106 There is currently no GUI, no menu entry for this inset. A user can define a
107 shortcut for "info-insert" (e.g. C-S-I), and
109 1. input the type and argument of this inset, e.g. "menu paste", in
111 2. select the text and run "info-insert" (e.g. press C-S-I).
113 An alternative method is to enter command "info-insert type arg" in
114 the command buffer (view->Toolbar->Command Buffer).
118 class InsetInfoParams {
121 DATE_INFO, // Current date
122 MODDATE_INFO, // Date of last modification
123 FIXDATE_INFO, // Fix date
124 TIME_INFO, // Current time
125 MODTIME_INFO, // Time of last modification
126 FIXTIME_INFO, // Fix time
127 BUFFER_INFO, // Buffer related information
128 VCS_INFO, // Version control information
129 PACKAGE_INFO, // Availability of package
130 TEXTCLASS_INFO, // Availability of textclass
131 SHORTCUTS_INFO, // Keyboard shortcuts
132 SHORTCUT_INFO, // Keyboard shortcut
133 LYXRC_INFO, // RC entry
134 MENU_INFO, // Which menu item is used for certain function
135 ICON_INFO, // which toolbar icon is used for certain function
136 LYX_INFO, // LyX version information
137 L7N_INFO, // Localized string
138 UNKNOWN_INFO, // Invalid type
141 std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
142 std::string const &) const;
144 bool validateArgument(Buffer const * buf, docstring const & argument,
145 bool const usedefault = false) const;
149 std::string infoType() const;
153 Language const * lang;
159 extern InsetInfoParams infoparams;
161 class InsetInfo : public InsetCollapsible {
164 InsetInfo(Buffer * buf, std::string const & info = std::string());
166 InsetCode lyxCode() const override { return INFO_CODE; }
168 docstring layoutName() const override;
170 Inset * editXY(Cursor & cur, int x, int y) override;
171 /** FIXME: we would like to do that, but then InsetText::updateBuffer breaks
172 * on info insets. Do we need to run this method on InsetInfo contents?
173 * Having a InsetInfo that hides an InsetText is really annoying, actually.
175 ///bool isActive() const override { return false; }
177 bool editable() const override { return false; }
179 bool hasSettings() const override { return true; }
181 void read(Lexer & lex) override;
183 void write(std::ostream & os) const override;
185 bool validateModifyArgument(docstring const & argument) const override {
186 return params_.validateArgument(&buffer(), argument); }
188 bool showInsetDialog(BufferView * bv) const override;
190 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
192 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
193 /// Force inset into LTR environment if surroundings are RTL
194 bool forceLTR(OutputParams const &) const override;
196 bool forceLocalFontSwitch() const override;
198 void setInfo(std::string const & info);
200 void updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted = false) override;
202 void metrics(MetricsInfo & mi, Dimension & dim) const override;
204 void draw(PainterInfo & pi, int x, int y) const override;
207 docstring toolTip(BufferView const & bv, int x, int y) const override;
209 std::string contextMenu(BufferView const &, int, int) const override;
211 std::string contextMenuName() const override;
212 /// should paragraph indentation be omitted in any case?
213 bool neverIndent() const override { return true; }
215 void validate(LaTeXFeatures & features) const override;
217 InsetInfoParams params() const { return params_; }
218 /// Outputs the inset as DocBook, taking advantage of the metadata available in InsetInfoParams.
219 void docbook(XMLStream &, OutputParams const &) const override;
220 /// Outputs the inset as XHTML, taking advantage of the metadata available in InsetInfoParams.
221 docstring xhtml(XMLStream &, OutputParams const &) const override;
225 Inset * clone() const override { return new InsetInfo(*this); }
227 void error(docstring const & err, Language const *);
229 void info(docstring const & err, Language const *);
231 void setText(docstring const & str, Language const *);
232 // make sure that the other version of setText is still available.
233 using InsetCollapsible::setText;
234 /// Compute the information
239 InsetInfoParams params_;
241 friend class InsetInfoParams;