]> git.lyx.org Git - lyx.git/blob - src/ModuleList.h
* fix crashing special menu items on Mac after preferences have been changed.
[lyx.git] / src / ModuleList.h
1 // -*- C++ -*-
2 /**
3  * \file ModuleList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Richard Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MODULELIST_H
13 #define MODULELIST_H
14
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 namespace lyx {
20         
21 /**
22  *  This struct represents a particular LyX "module", which is a like a layout
23  *  file, except that it does not stand alone. In that sense, it is more like 
24  *  a LaTeX package, where a layout file corresponds to a LaTeX class. Or, in 
25  *  LyX's own terms, a module is more like an included file that can be used
26  *  with various document classes. The difference is that using a module only
27  *  means selecting it in the Document>Settings dialog, whereas including a 
28  *  layout file means layout file editing.
29  *
30  *  In general, a given module can be used with any document class. That said,
31  *  one module may `require' another, or it may `exclude' some other module.
32  *  The requires and excludes are given in comments within the module file,
33  *  which must begin roughly so:
34  *   #\DeclareLyXModule{Theorems (By Section)}
35  *   #DescriptionBegin
36  *   #Numbers theorems and the like by section.
37  *   #DescriptionEnd
38  *   #Requires: theorems-std | theorems-ams
39  *   #Excludes: theorems-chap
40  *  The description is used in the gui to give information to the user. The
41  *  Requires and Excludes lines are read by the configuration script and
42  *  written to a file lyxmodules.lst in the user configuration directory.
43  */
44
45 class LyXModule {
46 public:
47         ///
48         LyXModule(std::string const & n, std::string const & i, 
49                   std::string const & d, std::vector<std::string> const & p,
50                   std::vector<std::string> const & r, 
51                   std::vector<std::string> const & e);
52         /// whether the required packages are available
53         bool isAvailable();
54         ///
55         std::string const & getName() const { return name; }
56         ///
57         std::string const & getID() const { return id; }
58         ///
59         std::string const & getFilename() const { return filename; }
60         ///
61         std::string const & getDescription() const { return description; }
62         ///
63         std::vector<std::string> const & getPackageList() const
64                 { return packageList; }
65         ///
66         std::vector<std::string> const & getRequiredModules() const 
67                 { return requiredModules; }
68         /// Modules this one excludes: the list should be treated disjunctively
69         std::vector<std::string> const & getExcludedModules() const 
70                 { return excludedModules; }
71         /// \return true if the module is compatible with this one, i.e.,
72         /// it does not exclude us and we do not exclude it.
73         /// this will also return true if modName is unknown and we do not
74         /// exclude it, since in that case we cannot check its exclusions.
75         bool isCompatible(std::string const & modName) const;
76         ///
77         static bool areCompatible(std::string const & mod1, std::string const & mod2);
78 private:
79         /// what appears in the ui
80         std::string name;
81         /// the module's unique identifier
82         /// at present, this is the filename, without the extension
83         std::string id;
84         /// the filename
85         std::string filename;
86         /// a short description for use in the ui
87         std::string description;
88         /// the LaTeX packages on which this depends, if any
89         std::vector<std::string> packageList;
90         /// Modules this one requires: at least one
91         std::vector<std::string> requiredModules;
92         /// Modules this one excludes: none of these
93         std::vector<std::string> excludedModules;
94         ///
95         bool checked;
96         ///
97         bool available;
98 };
99
100 typedef std::vector<LyXModule> LyXModuleList;
101
102 /**
103  *  The ModuleList represents the various LyXModule's that are available at
104  *  present.
105  */
106 class ModuleList {
107 public:
108         ///
109         ModuleList() {}
110         /// reads the modules from a file generated by configure.py
111         bool load();
112         ///
113         LyXModuleList::const_iterator begin() const;
114         ///
115         LyXModuleList::iterator begin();
116         ///
117         LyXModuleList::const_iterator end() const;
118         ///
119         LyXModuleList::iterator end();
120         ///
121         bool empty() const { return modlist_.empty(); }
122         /// Returns a pointer to the LyXModule with filename str.
123         /// Returns a null pointer if no such module is found.
124         LyXModule * operator[](std::string const & str);
125 private:
126         /// noncopyable
127         ModuleList(ModuleList const &);
128         ///
129         void operator=(ModuleList const &);
130         /// add a module to the list
131         void addLayoutModule(std::string const &, std::string const &, 
132                 std::string const &, std::vector<std::string> const &,
133                 std::vector<std::string> const &, std::vector<std::string> const &);
134         ///
135         std::vector<LyXModule> modlist_;
136 };
137
138 extern ModuleList moduleList;
139 }
140 #endif