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