]> git.lyx.org Git - lyx.git/blob - src/ModuleList.h
Fix bug #5131: Remember last file active.
[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  *  Modules can also be "provided" or "excluded" by document classes, using
45  *  the ProvidesModule and ExcludesModule tags.
46  */
47
48 class LyXModule {
49 public:
50         ///
51         LyXModule(std::string const & n, std::string const & i, 
52                   std::string const & d, std::vector<std::string> const & p,
53                   std::vector<std::string> const & r, 
54                   std::vector<std::string> const & e);
55         /// whether the required packages are available
56         bool isAvailable();
57         ///
58         std::string const & getName() const { return name; }
59         ///
60         std::string const & getID() const { return id; }
61         ///
62         std::string const & getFilename() const { return filename; }
63         ///
64         std::string const & getDescription() const { return description; }
65         ///
66         std::vector<std::string> const & getPackageList() const
67                 { return packageList; }
68         ///
69         std::vector<std::string> const & getRequiredModules() const 
70                 { return requiredModules; }
71         /// Modules this one excludes: the list should be treated disjunctively
72         std::vector<std::string> const & getExcludedModules() const 
73                 { return excludedModules; }
74         /// \return true if the module is compatible with this one, i.e.,
75         /// it does not exclude us and we do not exclude it.
76         /// this will also return true if modName is unknown and we do not
77         /// exclude it, since in that case we cannot check its exclusions.
78         bool isCompatible(std::string const & modName) const;
79         ///
80         static bool areCompatible(std::string const & mod1, std::string const & mod2);
81 private:
82         /// what appears in the ui
83         std::string name;
84         /// the module's unique identifier
85         /// at present, this is the filename, without the extension
86         std::string id;
87         /// the filename
88         std::string filename;
89         /// a short description for use in the ui
90         std::string description;
91         /// the LaTeX packages on which this depends, if any
92         std::vector<std::string> packageList;
93         /// Modules this one requires: at least one
94         std::vector<std::string> requiredModules;
95         /// Modules this one excludes: none of these
96         std::vector<std::string> excludedModules;
97         ///
98         bool checked;
99         ///
100         bool available;
101 };
102
103 typedef std::vector<LyXModule> LyXModuleList;
104
105 /**
106  *  The ModuleList represents the various LyXModule's that are available at
107  *  present.
108  */
109 class ModuleList {
110 public:
111         ///
112         ModuleList() {}
113         /// reads the modules from a file generated by configure.py
114         bool read();
115         ///
116         LyXModuleList::const_iterator begin() const;
117         ///
118         LyXModuleList::iterator begin();
119         ///
120         LyXModuleList::const_iterator end() const;
121         ///
122         LyXModuleList::iterator end();
123         ///
124         bool empty() const { return modlist_.empty(); }
125         /// Returns a pointer to the LyXModule with filename str.
126         /// Returns a null pointer if no such module is found.
127         LyXModule * operator[](std::string const & str);
128 private:
129         /// noncopyable
130         ModuleList(ModuleList const &);
131         ///
132         void operator=(ModuleList const &);
133         /// add a module to the list
134         void addLayoutModule(std::string const &, std::string const &, 
135                 std::string const &, std::vector<std::string> const &,
136                 std::vector<std::string> const &, std::vector<std::string> const &);
137         ///
138         std::vector<LyXModule> modlist_;
139 };
140
141 extern ModuleList moduleList;
142 }
143 #endif