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