]> git.lyx.org Git - lyx.git/blob - src/insets/ExternalTemplate.h
#5502 add binding for full screen toggle on mac
[lyx.git] / src / insets / ExternalTemplate.h
1 // -*- C++ -*-
2 /**
3  * \file ExternalTemplate.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef EXTERNALTEMPLATE_H
14 #define EXTERNALTEMPLATE_H
15
16 #include "ExternalTransforms.h"
17
18 #include <boost/noncopyable.hpp>
19
20 #include <vector>
21
22 namespace lyx {
23
24 namespace support { class FileName; }
25
26 class Lexer;
27
28 enum PreviewMode {
29         PREVIEW_OFF = 0,
30         PREVIEW_GRAPHICS,
31         PREVIEW_INSTANT
32 };
33
34 namespace external {
35
36 class Template {
37 public:
38         /// We have to have default commands for safety reasons!
39         Template();
40         ///
41         void readTemplate(Lexer &);
42         ///
43         void dumpFormats(std::ostream &) const;
44
45         class Option {
46         public:
47                 Option(std::string const & name_, std::string const & opt_)
48                         : name(name_), option(opt_) {}
49                 std::string name;
50                 std::string option;
51         };
52
53         /// What is the name of this template in the LyX format?
54         std::string lyxName;
55         /// What will the button in the GUI say?
56         std::string guiName;
57         /// A short help text
58         std::string helpText;
59         /** The format of the input file. Can be "*", in which case we try and
60          *   ascertain the format from the contents of the file.
61          */
62         std::string inputFormat;
63         /// A file extension regular expression for the file browser
64         std::string fileRegExp;
65         /// Should we do automatic production of the output?
66         bool automaticProduction;
67         /// How should we preview the data in LyX?
68         PreviewMode preview_mode;
69         /// A collection of transforms that we can use to transform the data.
70         std::vector<TransformID> transformIds;
71
72         /// This is the information needed to support a specific output format
73         class Format {
74         public:
75                 Format();
76                 ///
77                 void readFormat(Lexer &);
78
79                 /// The text that should be inserted into the exported file
80                 std::string product;
81                 /// The filename of the resulting file
82                 std::string updateResult;
83                 /// The format of this file.
84                 std::string updateFormat;
85                 /// What features does this external inset require?
86                 std::vector<std::string> requirements;
87                 /// A collection of preamble snippets identified by name.
88                 std::vector<std::string> preambleNames;
89                 /// A list of options to the basic command.
90                 std::vector<Option> options;
91
92                 /// The factory functions for each supported transformation.
93                 std::map<TransformID, TransformStore> command_transformers;
94                 std::map<TransformID, TransformStore> option_transformers;
95
96                 typedef std::map<std::string,
97                                  std::vector<std::string> > FileMap;
98                 /// Referenced files for some formats
99                 FileMap referencedFiles;
100         };
101         ///
102         typedef std::map<std::string, Format> Formats;
103         ///
104         Formats formats;
105 };
106
107 /**
108  *  A singleton class that manages the external inset templates
109  */
110 class TemplateManager {
111 public:
112         /// Map from the LyX name of the template to the template structure
113         typedef std::map<std::string, Template> Templates;
114         /** Map from the LyX name of the preamble definition to the preamble
115          *  definition itself.
116          */
117         typedef std::map<std::string, std::string> PreambleDefs;
118
119         static TemplateManager & get();
120
121         Templates const & getTemplates() const;
122         /** return the template by LyX name.
123          *  If it isn't found, return 0.
124          */
125         Template const * getTemplateByName(std::string const & name) const;
126         /** return the preamble definition by LyX name.
127          *  If it isn't found, return an empty std::string.
128          */
129         std::string const getPreambleDefByName(std::string const & name) const;
130 private:
131         TemplateManager();
132         /// noncopyable
133         TemplateManager(TemplateManager const &);
134         void operator=(TemplateManager const &);
135
136         void readTemplates(support::FileName const & path);
137         void dumpTemplates(std::ostream &) const;
138         void dumpPreambleDefs(std::ostream &) const;
139
140         Templates templates;
141         PreambleDefs preambledefs;
142 };
143
144 } // namespace external
145 } // namespace lyx
146
147 #endif // EXTERNALTEMPLATE_H