]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInfo.h
Fix bug #12795
[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 #include <QDate>
17
18 namespace lyx {
19
20 class Cursor;
21
22 /* InsetInfo displays shortcuts, lyxrc, package and textclass
23 availability and menu information in a non-editable boxed InsetText.
24
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.
30
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.
35
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.
45
46 moddate: Same as date.
47     The output is a localized formatted date of last file modification (saving).
48
49 fixdate: Same as date. A fixed date (in ISO format) is prepended to the argument,
50     delimited by '@'.
51     The output is a localized formatted fix date.
52
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.
59
60 modtime: Same as time.
61     The output is a localized formatted time of last file modification (saving).
62
63 fixtime: Same as time. A fixed time (in ISO format) is prepended to the argument,
64     delimited by '@'.
65     The output is a localized formatted fix time.
66
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.
70
71 shortcut: the same as shortcuts, but only output the last shortcut.
72
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
75     entry.
76
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.
79
80 textclass: argument is the name a textclass such as "article". The output is
81     "yes" or "no", indicating the availability of this textclass.
82
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).
87
88 l7n: argument is an English string that is marked for localization. The output
89     is the localization of that string in the current GUI language (if available).
90     Trailing colons are stripped, accelerators removed.
91     This is used to refer to GUI items in the docs.
92
93 icon: argument is the name of the LFUN such as "paste". The syntax is the same
94     as what is used in the bind and ui files. The output is the icon use in
95     the toolbar for this LFUN. Alternatively, argument can be the icon path
96     without extension specified with respect to the images directory.
97
98 buffer: argument can be one of "name", "name-noext", "path", "class". This inset output the
99     filename (with extension), filename (without extension), path, and textclass of this buffer.
100
101 lyxinfo: argument must be "version" or "layoutformat". This outputs information
102     about the version of LyX currently in use or the current LyX layout format, respectively.
103
104 vcs: argument can be one of "revision", "tree-revision", "author", "time", "date".
105     This insets outputs revision control information, if available.
106
107 There is currently no GUI, no menu entry for this inset. A user can define a
108 shortcut for "info-insert" (e.g. C-S-I), and
109
110 1. input the type and argument of this inset, e.g. "menu paste", in
111    the work area.
112 2. select the text and run "info-insert" (e.g. press C-S-I).
113
114 An alternative method is to enter command "info-insert type arg" in
115 the command buffer (view->Toolbar->Command Buffer).
116
117 */
118
119 class InsetInfoParams {
120 public:
121         enum info_type {
122                 DATE_INFO,       // Current date
123                 MODDATE_INFO,    // Date of last modification
124                 FIXDATE_INFO,    // Fix date
125                 TIME_INFO,       // Current time
126                 MODTIME_INFO,    // Time of last modification
127                 FIXTIME_INFO,    // Fix time
128                 BUFFER_INFO,     // Buffer related information
129                 VCS_INFO,        // Version control information
130                 PACKAGE_INFO,    // Availability of package
131                 TEXTCLASS_INFO,  // Availability of textclass
132                 SHORTCUTS_INFO,  // Keyboard shortcuts
133                 SHORTCUT_INFO,   // Keyboard shortcut
134                 LYXRC_INFO,      // RC entry
135                 MENU_INFO,       // Which menu item is used for certain function
136                 ICON_INFO,       // which toolbar icon is used for certain function
137                 LYX_INFO,        // LyX version information
138                 L7N_INFO,        // Localized string
139                 UNKNOWN_INFO,    // Invalid type
140         };
141         ///
142         docstring getDate(std::string const &, QDate const date = QDate::currentDate()) const;
143         ///
144         docstring getTime(std::string const &, QTime const time = QTime::currentTime()) const;
145         ///
146         std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
147                                                                    std::string const &) const;
148         ///
149         bool validateArgument(Buffer const * buf, docstring const & argument,
150                               bool const usedefault = false) const;
151         ///
152         info_type type;
153         ///
154         std::string infoType() const;
155         ///
156         std::string name;
157         ///
158         Language const * lang;
159         ///
160         bool force_ltr;
161 };
162
163 ///
164 extern InsetInfoParams infoparams;
165
166 class InsetInfo : public InsetCollapsible {
167 public:
168         ///
169         InsetInfo(Buffer * buf, std::string const & info = std::string());
170         ///
171         InsetCode lyxCode() const override { return INFO_CODE; }
172         ///
173         docstring layoutName() const override;
174         ///
175         Inset * editXY(Cursor & cur, int x, int y) override;
176         /** FIXME: we would like to do that, but then InsetText::updateBuffer breaks
177          * on info insets. Do we need to run this method on InsetInfo contents?
178          * Having a InsetInfo that hides an InsetText is really annoying, actually.
179          */
180         ///bool isActive() const override { return false; }
181         ///
182         bool editable() const override { return false; }
183         ///
184         bool hasSettings() const override { return true; }
185         ///
186         void read(Lexer & lex) override;
187         ///
188         void write(std::ostream & os) const override;
189         ///
190         bool validateModifyArgument(docstring const & argument) const override {
191                 return params_.validateArgument(&buffer(), argument); }
192         ///
193         bool showInsetDialog(BufferView * bv) const override;
194         ///
195         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
196         ///
197         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
198         /// Force inset into LTR environment if surroundings are RTL
199         bool forceLTR(OutputParams const &) const override;
200         ///
201         bool forceLocalFontSwitch() const override;
202         ///
203         void setInfo(std::string const & info);
204         ///
205         void updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted = false) override;
206         ///
207         void metrics(MetricsInfo & mi, Dimension & dim) const override;
208         ///
209         void draw(PainterInfo & pi, int x, int y) const override;
210
211         ///
212         docstring toolTip(BufferView const & bv, int x, int y) const override;
213         ///
214         std::string contextMenu(BufferView const &, int, int) const override;
215         ///
216         std::string contextMenuName() const override;
217         /// should paragraph indentation be omitted in any case?
218         bool neverIndent() const override { return true; }
219         ///
220         void validate(LaTeXFeatures & features) const override;
221         ///
222         InsetInfoParams params() const { return params_; }
223
224 private:
225         ///
226         Inset * clone() const override { return new InsetInfo(*this); }
227         ///
228         void error(docstring const & err, Language const *);
229         ///
230         void info(docstring const & err, Language const *);
231         ///
232         void setText(docstring const & str, Language const *);
233         // make sure that the other version of setText is still available.
234         using InsetCollapsible::setText;
235         /// Compute the information
236         void build();
237         ///
238         bool initialized_;
239         ///
240         InsetInfoParams params_;
241         ///
242         friend class InsetInfoParams;
243 };
244
245
246 } // namespace lyx
247
248 #endif