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