]> git.lyx.org Git - features.git/blob - src/insets/InsetInfo.h
Introduce InsetInfoParams
[features.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 shortcuts: argument is the name of the LFUN such as "math-insert \alpha".
54     The syntax is the same as what is used in the bind and ui files.
55     The output of this inset is all shortcuts for this LFUN separated by comma.
56
57 shortcut: the same as shortcuts, but only output the last shortcut.
58
59 lyxrc: argument is the name of the rc entry such as "bind_file". Look in
60     src/LyXRC.h for available entries. The output is the content of this RC
61     entry.
62
63 package: argument is the name of a latex package such as "listings". The
64     output is "yes" or "no", indicating the availability of this package.
65
66 textclass: argument is the name a textclass such as "article". The output is
67     "yes" or "no", indicating the availability of this textclass.
68
69 menu: argument is the name of the LFUN such as "paste". The syntax is the same
70     as what is used in the bind and ui files. The output is the menu item that
71     triggers this LFUN. For example, "File > Paste", where '>' is actually
72     \lyxarrow (an InsetSpecialChar).
73
74 icon: argument is the name of the LFUN such as "paste". The syntax is the same
75     as what is used in the bind and ui files. The output is the icon use in
76     the toolbar for this LFUN. Alternatively, argument can be the icon path
77     without extension specified with respect to the images directory.
78
79 buffer: argument can be one of "name", "path", "class". This inset output the
80     filename, path, and textclass of this buffer.
81
82 lyxinfo: argument must (presently) be "version". This inset outputs information
83     about the version of LyX currently in use.
84
85 vcs: argument can be one of "revision", "tree-revision", "author", "time", "date".
86     This insets outputs revision control information, if available.
87
88 There is currently no GUI, no menu entry for this inset. A user can define a
89 shortcut for "info-insert" (e.g. C-S-I), and
90
91 1. input the type and argument of this inset, e.g. "menu paste", in
92    the work area.
93 2. select the text and run "info-insert" (e.g. press C-S-I).
94
95 An alternative method is to enter command "info-insert type arg" in
96 the command buffer (view->Toolbar->Command Buffer).
97
98 */
99
100 class InsetInfoParams {
101 public:
102         enum info_type {
103                 DATE_INFO,       // Current Date
104                 MODDATE_INFO,    // Date of last modification
105                 FIXDATE_INFO,    // Fix date
106                 BUFFER_INFO,     // Buffer related information
107                 VCS_INFO,        // Version control information
108                 PACKAGE_INFO,    // Availability of package
109                 TEXTCLASS_INFO,  // Availability of textclass
110                 SHORTCUTS_INFO,  // Keyboard shortcuts
111                 SHORTCUT_INFO,   // Keyboard shortcut
112                 LYXRC_INFO,      // RC entry
113                 MENU_INFO,       // Which menu item is used for certain function
114                 ICON_INFO,       // which toolbar icon is used for certain function
115                 LYX_INFO,        // LyX version information
116                 UNKNOWN_INFO,    // Invalid type
117         };
118         ///
119         docstring getDate(std::string const, QDate const date = QDate::currentDate()) const;
120         ///
121         std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
122                                                                    std::string const &) const;
123         ///
124         info_type type;
125         ///
126         std::string infoType() const;
127         ///
128         std::string name;
129         ///
130         Language const * lang;
131         ///
132         bool force_ltr;
133 };
134
135 ///
136 extern InsetInfoParams infoparams;
137
138 class InsetInfo : public InsetCollapsible {
139 public:
140         ///
141         InsetInfo(Buffer * buf, std::string const & info = std::string());
142         ///
143         InsetCode lyxCode() const { return INFO_CODE; }
144         ///
145         docstring layoutName() const;
146         ///
147         Inset * editXY(Cursor & cur, int x, int y);
148         /** FIXME: we would like to do that, but then InsetText::updateBuffer breaks
149          * on info insets. Do we need to run this method on InsetInfo contents?
150          * Having a InsetInfo that hides an InsetText is really annoying, actually.
151          */
152         ///bool isActive() const { return false; }
153         ///
154         bool editable() const { return false; }
155         ///
156         bool hasSettings() const { return true; }
157         ///
158         void read(Lexer & lex);
159         ///
160         void write(std::ostream & os) const;
161         ///
162         bool validateModifyArgument(docstring const & argument) const;
163         ///
164         bool showInsetDialog(BufferView * bv) const;
165         ///
166         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
167         ///
168         void doDispatch(Cursor & cur, FuncRequest & cmd);
169         /// Force inset into LTR environment if surroundings are RTL
170         bool forceLTR() const;
171         ///
172         void setInfo(std::string const & info);
173         ///
174         void updateBuffer(ParIterator const & it, UpdateType utype);
175         ///
176         docstring toolTip(BufferView const & bv, int x, int y) const;
177         ///
178         std::string contextMenu(BufferView const &, int, int) const;
179         ///
180         std::string contextMenuName() const;
181         /// should paragraph indendation be omitted in any case?
182         bool neverIndent() const { return true; }
183         ///
184         InsetInfoParams params() const { return params_; }
185
186 private:
187         ///
188         virtual Inset * clone() const { return new InsetInfo(*this); }
189         ///
190         void error(docstring const & err, Language const *);
191         ///
192         void info(docstring const & err, Language const *);
193         ///
194         void setText(docstring const & str, Language const *);
195         // make sure that the other version of setText is still available.
196         using InsetCollapsible::setText;
197         ///
198         bool initialized_;
199         ///
200         InsetInfoParams params_;
201         ///
202         friend class InsetInfoParams;
203 };
204
205
206 } // namespace lyx
207
208 #endif