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"
22 /* InsetInfo displays shortcuts, lyxrc, package and textclass
23 availability and menu information in a non-editable boxed InsetText.
25 Output of such an inset may vary from system to system, depending
26 on LyX and LaTeX configurations. Two LyX help files, LaTeXConfig.lyx
27 and Shortcuts.lyx make heavy use of this inset. The former uses it
28 to display the availability of packages and textclasses, the latter
29 uses it to display currently used shortcuts.
31 This inset has two arguments: the type and argument of the information. The
32 screen and latex output is the content of the information. An InsetInfo can
33 have type "shortcuts", "shortcut", "lyxrc", "package", "textclass", "menu",
34 "buffer" or "vcs". Arguments and outputs vary by type.
36 date: argument of this type of InsetInfo is either a fixed date type of
37 "long" (long localized date, with weekday, as provided by QLocale),
38 "short" (short localized date, with two-digit year, as provided by QLocale),
39 "loclong" (long localized date, without weekday, defined in languages),
40 "locmedium" (medium localized date, defined in languages),
41 "locshort" (short localized date, with four-digit year, defined in languages),
42 "ISO" (ISO-conforming date)
43 or a custom date using the QDate syntax.
44 The output is a localized formatted (current) date.
46 moddate: Same as date.
47 The output is a localized formatted date of last file modification (saving).
49 fixdate: Same as date. A fixed date (in ISO format) is prepended to the argument,
51 The output is a localized formatted fix date.
53 time: argument of this type of InsetInfo is either a fixed time type of
54 "long" (long localized time, as provided by QLocale),
55 "short" (short localized time, as provided by QLocale),
56 "ISO" (ISO-conforming time)
57 or a custom date using the QTime syntax.
58 The output is a localized formatted (current) time.
60 modtime: Same as time.
61 The output is a localized formatted time of last file modification (saving).
63 fixtime: Same as time. A fixed time (in ISO format) is prepended to the argument,
65 The output is a localized formatted fix time.
67 shortcuts: argument is the name of the LFUN such as "math-insert \alpha".
68 The syntax is the same as what is used in the bind and ui files.
69 The output of this inset is all shortcuts for this LFUN separated by comma.
71 shortcut: the same as shortcuts, but only output the last shortcut.
73 lyxrc: argument is the name of the rc entry such as "bind_file". Look in
74 src/LyXRC.h for available entries. The output is the content of this RC
77 package: argument is the name of a latex package such as "listings". The
78 output is "yes" or "no", indicating the availability of this package.
80 textclass: argument is the name a textclass such as "article". The output is
81 "yes" or "no", indicating the availability of this textclass.
83 menu: argument is the name of the LFUN such as "paste". The syntax is the same
84 as what is used in the bind and ui files. The output is the menu item that
85 triggers this LFUN. For example, "File > Paste", where '>' is actually
86 \lyxarrow (an InsetSpecialChar).
88 icon: argument is the name of the LFUN such as "paste". The syntax is the same
89 as what is used in the bind and ui files. The output is the icon use in
90 the toolbar for this LFUN. Alternatively, argument can be the icon path
91 without extension specified with respect to the images directory.
93 buffer: argument can be one of "name", "name-noext", "path", "class". This inset output the
94 filename (with extension), filename (without extension), path, and textclass of this buffer.
96 lyxinfo: argument must (presently) be "version". This inset outputs information
97 about the version of LyX currently in use.
99 vcs: argument can be one of "revision", "tree-revision", "author", "time", "date".
100 This insets outputs revision control information, if available.
102 There is currently no GUI, no menu entry for this inset. A user can define a
103 shortcut for "info-insert" (e.g. C-S-I), and
105 1. input the type and argument of this inset, e.g. "menu paste", in
107 2. select the text and run "info-insert" (e.g. press C-S-I).
109 An alternative method is to enter command "info-insert type arg" in
110 the command buffer (view->Toolbar->Command Buffer).
114 class InsetInfoParams {
117 DATE_INFO, // Current date
118 MODDATE_INFO, // Date of last modification
119 FIXDATE_INFO, // Fix date
120 TIME_INFO, // Current time
121 MODTIME_INFO, // Time of last modification
122 FIXTIME_INFO, // Fix time
123 BUFFER_INFO, // Buffer related information
124 VCS_INFO, // Version control information
125 PACKAGE_INFO, // Availability of package
126 TEXTCLASS_INFO, // Availability of textclass
127 SHORTCUTS_INFO, // Keyboard shortcuts
128 SHORTCUT_INFO, // Keyboard shortcut
129 LYXRC_INFO, // RC entry
130 MENU_INFO, // Which menu item is used for certain function
131 ICON_INFO, // which toolbar icon is used for certain function
132 LYX_INFO, // LyX version information
133 UNKNOWN_INFO, // Invalid type
136 docstring getDate(std::string const, QDate const date = QDate::currentDate()) const;
138 docstring getTime(std::string const, QTime const time = QTime::currentTime()) const;
140 std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
141 std::string const &) const;
145 std::string infoType() const;
149 Language const * lang;
155 extern InsetInfoParams infoparams;
157 class InsetInfo : public InsetCollapsible {
160 InsetInfo(Buffer * buf, std::string const & info = std::string());
162 InsetCode lyxCode() const { return INFO_CODE; }
164 docstring layoutName() const;
166 Inset * editXY(Cursor & cur, int x, int y);
167 /** FIXME: we would like to do that, but then InsetText::updateBuffer breaks
168 * on info insets. Do we need to run this method on InsetInfo contents?
169 * Having a InsetInfo that hides an InsetText is really annoying, actually.
171 ///bool isActive() const { return false; }
173 bool editable() const { return false; }
175 bool hasSettings() const { return true; }
177 void read(Lexer & lex);
179 void write(std::ostream & os) const;
181 bool validateModifyArgument(docstring const & argument) const;
183 bool showInsetDialog(BufferView * bv) const;
185 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
187 void doDispatch(Cursor & cur, FuncRequest & cmd);
188 /// Force inset into LTR environment if surroundings are RTL
189 bool forceLTR() const;
191 void setInfo(std::string const & info);
193 void updateBuffer(ParIterator const & it, UpdateType utype);
195 docstring toolTip(BufferView const & bv, int x, int y) const;
197 std::string contextMenu(BufferView const &, int, int) const;
199 std::string contextMenuName() const;
200 /// should paragraph indendation be omitted in any case?
201 bool neverIndent() const { return true; }
203 InsetInfoParams params() const { return params_; }
207 virtual Inset * clone() const { return new InsetInfo(*this); }
209 void error(docstring const & err, Language const *);
211 void info(docstring const & err, Language const *);
213 void setText(docstring const & str, Language const *);
214 // make sure that the other version of setText is still available.
215 using InsetCollapsible::setText;
219 InsetInfoParams params_;
221 friend class InsetInfoParams;