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