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