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