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