]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInfo.h
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / src / insets / InsetInfo.h
1 // -*- C++ -*-
2 /**
3  * \file InsetInfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Bo Peng
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_INFO_H
13 #define INSET_INFO_H
14
15 #include "InsetCollapsible.h"
16
17 namespace lyx {
18
19 class Cursor;
20
21 /* InsetInfo displays shortcuts, lyxrc, package and textclass
22 availability and menu information in a non-editable boxed InsetText.
23
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.
29
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.
34
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.
44
45 moddate: Same as date.
46     The output is a localized formatted date of last file modification (saving).
47
48 fixdate: Same as date. A fixed date (in ISO format) is prepended to the argument,
49     delimited by '@'.
50     The output is a localized formatted fix date.
51
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.
58
59 modtime: Same as time.
60     The output is a localized formatted time of last file modification (saving).
61
62 fixtime: Same as time. A fixed time (in ISO format) is prepended to the argument,
63     delimited by '@'.
64     The output is a localized formatted fix time.
65
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.
69
70 shortcut: the same as shortcuts, but only output the last shortcut.
71
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
74     entry.
75
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.
78
79 textclass: argument is the name a textclass such as "article". The output is
80     "yes" or "no", indicating the availability of this textclass.
81
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).
86
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.
91
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.
96
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.
99
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.
102
103 vcs: argument can be one of "revision", "tree-revision", "author", "time", "date".
104     This insets outputs revision control information, if available.
105
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
108
109 1. input the type and argument of this inset, e.g. "menu paste", in
110    the work area.
111 2. select the text and run "info-insert" (e.g. press C-S-I).
112
113 An alternative method is to enter command "info-insert type arg" in
114 the command buffer (view->Toolbar->Command Buffer).
115
116 */
117
118 class InsetInfoParams {
119 public:
120         enum info_type {
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
139         };
140         ///
141         std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
142                                                                    std::string const &) const;
143         ///
144         bool validateArgument(Buffer const * buf, docstring const & argument,
145                               bool const usedefault = false) const;
146         ///
147         info_type type;
148         ///
149         std::string infoType() const;
150         ///
151         std::string name;
152         ///
153         Language const * lang;
154         ///
155         bool force_ltr;
156 };
157
158 ///
159 extern InsetInfoParams infoparams;
160
161 class InsetInfo : public InsetCollapsible {
162 public:
163         ///
164         InsetInfo(Buffer * buf, std::string const & info = std::string());
165         ///
166         InsetCode lyxCode() const override { return INFO_CODE; }
167         ///
168         docstring layoutName() const override;
169         ///
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.
174          */
175         ///bool isActive() const override { return false; }
176         ///
177         bool editable() const override { return false; }
178         ///
179         bool hasSettings() const override { return true; }
180         ///
181         void read(support::Lexer & lex) override;
182         ///
183         void write(std::ostream & os) const override;
184         ///
185         bool validateModifyArgument(docstring const & argument) const override {
186                 return params_.validateArgument(&buffer(), argument); }
187         ///
188         bool showInsetDialog(BufferView * bv) const override;
189         ///
190         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
191         ///
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;
195         ///
196         bool forceLocalFontSwitch() const override;
197         ///
198         void setInfo(std::string const & info);
199         ///
200         void updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted = false) override;
201         ///
202         void metrics(MetricsInfo & mi, Dimension & dim) const override;
203         ///
204         void draw(PainterInfo & pi, int x, int y) const override;
205
206         ///
207         docstring toolTip(BufferView const & bv, int x, int y) const override;
208         ///
209         std::string contextMenu(BufferView const &, int, int) const override;
210         ///
211         std::string contextMenuName() const override;
212         /// should paragraph indentation be omitted in any case?
213         bool neverIndent() const override { return true; }
214         ///
215         void validate(LaTeXFeatures & features) const override;
216         ///
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;
222
223 private:
224         ///
225         Inset * clone() const override { return new InsetInfo(*this); }
226         ///
227         void error(docstring const & err, Language const *);
228         ///
229         void info(docstring const & err, Language const *);
230         ///
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
235         void build();
236         ///
237         bool initialized_;
238         ///
239         InsetInfoParams params_;
240         ///
241         friend class InsetInfoParams;
242 };
243
244
245 } // namespace lyx
246
247 #endif