]> git.lyx.org Git - lyx.git/blob - src/insets/ExternalTemplate.h
4259652ae7973a6c96bf9967e5c36bff41fbd53e
[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  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef EXTERNALTEMPLATE_H
13 #define EXTERNALTEMPLATE_H
14
15 #include <boost/utility.hpp>
16
17 #include <iosfwd>
18 #include <map>
19 #include <string>
20 #include <vector>
21
22 class LyXLex;
23
24 namespace lyx {
25 namespace external {
26
27 struct Template {
28         /// We have to have default commands for safety reasons!
29         Template();
30         ///
31         void readTemplate(LyXLex &);
32         ///
33         void dumpFormats(std::ostream &) const;
34
35         /// What is the name of this template in the LyX format?
36         std::string lyxName;
37         /// What will the button in the GUI say?
38         std::string guiName;
39         /// A short help text
40         std::string helpText;
41         /** The format of the input file. Can be "*", in which case we try and
42          *   ascertain the format from the contents of the file.
43          */
44         std::string inputFormat;
45         /// A file extension regular expression for the file browser
46         std::string fileRegExp;
47         /// What command should be executed to edit the file?
48         std::string editCommand;
49         /// Should we do automatic production of the output?
50         bool automaticProduction;
51
52         /// This is the information needed to support a specific output format
53         struct Format {
54                 Format();
55                 ///
56                 void readFormat(LyXLex &);
57
58                 /// The text that should be inserted into the exported file
59                 std::string product;
60                 /// The filename of the resulting file
61                 std::string updateResult;
62                 /// The format of this file.
63                 std::string updateFormat;
64                 /// What features does this external inset require?
65                 std::string requirement;
66                 /// A collection of preamble snippets identified by name.
67                 std::vector<std::string> preambleNames;
68         };
69         ///
70         typedef std::map<std::string, Format> Formats;
71         ///
72         Formats formats;
73 };
74
75
76 /**
77  *  A singleton class that manages the external inset templates
78  */
79 class TemplateManager : boost::noncopyable {
80 public:
81         /// Map from the LyX name of the template to the template structure
82         typedef std::map<std::string, Template> Templates;
83         /** Map from the LyX name of the preamble definition to the preamble
84          *  definition itself.
85          */
86         typedef std::map<std::string, std::string> PreambleDefs;
87
88         static TemplateManager & get();
89
90         Templates const & getTemplates() const;
91         /** return the template by LyX name.
92          *  If it isn't found, return 0.
93          */
94         Template const * getTemplateByName(std::string const & name) const;
95         /** return the preamble definition by LyX name.
96          *  If it isn't found, return an empty std::string.
97          */
98         std::string const getPreambleDefByName(std::string const & name) const;
99 private:
100         TemplateManager();
101         void readTemplates(std::string const & path);
102         void dumpTemplates(std::ostream &) const;
103         void dumpPreambleDefs(std::ostream &) const;
104
105         Templates templates;
106         PreambleDefs preambledefs;
107 };
108
109 } // namespace external
110 } // namespace lyx
111
112 #endif // EXTERNALTEMPLATE_H