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