]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
Get package things working with modules prior to UI patch.
[lyx.git] / src / MenuBackend.h
1 // -*- C++ -*-
2 /**
3  * \file MenuBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MENUBACKEND_H
14 #define MENUBACKEND_H
15
16 #include "FuncStatus.h"
17 #include "FuncRequest.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include <vector>
22
23
24 namespace lyx {
25
26 class Lexer;
27 class Buffer;
28 class Menu;
29
30 ///
31 class MenuItem {
32 public:
33         /// The type of elements that can be in a menu
34         enum Kind {
35                 ///
36                 Command,
37                 ///
38                 Submenu,
39                 ///
40                 Separator,
41                 /** This is the list of last opened file,
42                     typically for the File menu. */
43                 Lastfiles,
44                 /** This is the list of opened Documents,
45                     typically for the Documents menu. */
46                 Documents,
47                 /** This is the bookmarks */
48                 Bookmarks,
49                 ///
50                 Toc,
51                 /** This is a list of viewable formats
52                     typically for the File->View menu. */
53                 ViewFormats,
54                 /** This is a list of updatable formats
55                     typically for the File->Update menu. */
56                 UpdateFormats,
57                 /** This is a list of exportable formats
58                     typically for the File->Export menu. */
59                 ExportFormats,
60                 /** This is a list of importable formats
61                     typically for the File->Export menu. */
62                 ImportFormats,
63                 /** This is the list of elements available
64                  * for insertion into document. */
65                 CharStyles,
66                 /** This is the list of user-configurable
67                 insets to insert into document */
68                 Custom,
69                 /** This is the list of floats that we can
70                     insert a list for. */
71                 FloatListInsert,
72                 /** This is the list of floats that we can
73                     insert. */
74                 FloatInsert,
75                 /** This is the list of selections that can
76                     be pasted. */
77                 PasteRecent,
78                 /** toolbars */
79                 Toolbars,
80                 /** Available branches in document */
81                 Branches
82         };
83
84         explicit MenuItem(Kind kind);
85
86         MenuItem(Kind kind,
87                  docstring const & label,
88                  docstring const & submenu = docstring(),
89                  bool optional = false);
90
91         MenuItem(Kind kind,
92                  docstring const & label,
93                  FuncRequest const & func,
94                  bool optional = false);
95
96         /// This one is just to please boost::shared_ptr<>
97         ~MenuItem();
98         /// The label of a given menuitem
99         docstring const label() const;
100         /// The keyboard shortcut (usually underlined in the entry)
101         docstring const shortcut() const;
102         /// The complete label, with label and shortcut separated by a '|'
103         docstring const fulllabel() const { return label_;}
104         /// The kind of entry
105         Kind kind() const { return kind_; }
106         /// the action (if relevant)
107         FuncRequest const & func() const { return func_; }
108         /// returns true if the entry should be ommited when disabled
109         bool optional() const { return optional_; }
110         /// returns the status of the lfun associated with this entry
111         FuncStatus const & status() const { return status_; }
112         /// returns the status of the lfun associated with this entry
113         FuncStatus & status() { return status_; }
114         /// returns the status of the lfun associated with this entry
115         void status(FuncStatus const & status) { status_ = status; }
116         /**
117          * returns the binding associated to this action.
118          * Use the native UI format when \c forgui is true.
119          */
120         docstring const binding(bool forgui) const;
121         /// the description of the  submenu (if relevant)
122         docstring const & submenuname() const { return submenuname_; }
123         /// set the description of the  submenu
124         void submenuname(docstring const & name) { submenuname_ = name; }
125         ///
126         Menu * submenu() const { return submenu_.get(); }
127         ///
128         void submenu(Menu * menu);
129
130 private:
131         //friend class MenuBackend;
132         ///
133         Kind kind_;
134         ///
135         docstring label_;
136         ///
137         FuncRequest func_;
138         ///
139         docstring submenuname_;
140         ///
141         bool optional_;
142         ///
143         FuncStatus status_;
144         ///
145         boost::shared_ptr<Menu> submenu_;
146 };
147
148
149 ///
150 class Menu {
151 public:
152         ///
153         typedef std::vector<MenuItem> ItemList;
154         ///
155         typedef ItemList::const_iterator const_iterator;
156         ///
157         typedef ItemList::size_type size_type;
158         ///
159         explicit Menu(docstring const & name = docstring())
160                 : name_(name) {}
161         /// Add the menu item unconditionally
162         Menu & add(MenuItem const &);
163         /// Checks the associated FuncRequest status before adding the
164         /// menu item.
165         Menu & addWithStatusCheck(MenuItem const &);
166         ///
167         Menu & read(Lexer &);
168         ///
169         docstring const & name() const { return name_; }
170         ///
171         bool empty() const { return items_.empty(); }
172         /// Clear the menu content.
173         void clear() { items_.clear(); }
174         ///
175         ItemList::size_type size() const { return items_.size(); }
176         ///
177         MenuItem const & operator[](size_type) const;
178         ///
179         bool hasFunc(FuncRequest const &) const;
180         ///
181         const_iterator begin() const {
182                 return items_.begin();
183         }
184         ///
185         const_iterator end() const {
186                 return items_.end();
187         }
188
189         // Check whether the menu shortcuts are unique
190         void checkShortcuts() const;
191
192 private:
193         friend class MenuBackend;
194         ///
195         ItemList items_;
196         ///
197         docstring name_;
198 };
199
200
201 ///
202 class MenuBackend {
203 public:
204         ///
205         typedef std::vector<Menu> MenuList;
206         ///
207         typedef MenuList::const_iterator const_iterator;
208         ///
209         typedef MenuList::iterator iterator;
210         ///
211         MenuBackend() {}
212         ///
213         void read(Lexer &);
214         ///
215         void add(Menu const &);
216         ///
217         bool hasMenu(docstring const &) const;
218         ///
219         Menu & getMenu(docstring const &);
220         ///
221         Menu const & getMenu(docstring const &) const;
222         ///
223         Menu const & getMenubar() const;
224         ///
225         bool empty() const { return menulist_.empty(); }
226         /** This defines a menu whose entries list the FuncRequests
227             that will be removed by expand() in other menus. This is
228             used by the Qt/Mac code
229         */
230         void specialMenu(Menu const &);
231         ///
232         Menu const & specialMenu() { return specialmenu_; }
233
234         /// Expands some special entries of the menu
235         /** The entries with the following kind are expanded to a
236             sequence of Command MenuItems: Lastfiles, Documents,
237             ViewFormats, ExportFormats, UpdateFormats, Branches
238         */
239         void expand(Menu const & frommenu, Menu & tomenu,
240                     Buffer const *) const;
241         ///
242         const_iterator begin() const {
243                 return menulist_.begin();
244         }
245         ///
246         iterator begin() {
247                 return menulist_.begin();
248         }
249         ///
250         const_iterator end() const {
251                 return menulist_.end();
252         }
253         ///
254         iterator end() {
255                 return menulist_.end();
256         }
257 private:
258         ///
259         MenuList menulist_;
260         ///
261         Menu menubar_;
262         ///
263         Menu specialmenu_;
264 };
265
266 ///
267 extern MenuBackend menubackend;
268
269
270 } // namespace lyx
271
272 #endif /* MENUBACKEND_H */