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