]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
Fixed some lines that were too long. It compiled afterwards.
[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 floats that we can
67                     insert a list for. */
68                 FloatListInsert,
69                 /** This is the list of floats that we can
70                     insert. */
71                 FloatInsert,
72                 /** This is the list of selections that can
73                     be pasted. */
74                 PasteRecent,
75                 /** toolbars */
76                 Toolbars,
77                 /** Available branches in document */
78                 Branches
79         };
80
81         explicit MenuItem(Kind kind);
82
83         MenuItem(Kind kind,
84                  docstring const & label,
85                  docstring const & submenu = docstring(),
86                  bool optional = false);
87
88         MenuItem(Kind kind,
89                  docstring const & label,
90                  FuncRequest const & func,
91                  bool optional = false);
92
93         /// This one is just to please boost::shared_ptr<>
94         ~MenuItem();
95         /// The label of a given menuitem
96         docstring const label() const;
97         /// The keyboard shortcut (usually underlined in the entry)
98         docstring const shortcut() const;
99         /// The complete label, with label and shortcut separated by a '|'
100         docstring const fulllabel() const { return label_;}
101         /// The kind of entry
102         Kind kind() const { return kind_; }
103         /// the action (if relevant)
104         FuncRequest const & func() const { return func_; }
105         /// returns true if the entry should be ommited when disabled
106         bool optional() const { return optional_; }
107         /// returns the status of the lfun associated with this entry
108         FuncStatus const & status() const { return status_; }
109         /// returns the status of the lfun associated with this entry
110         FuncStatus & status() { return status_; }
111         /// returns the status of the lfun associated with this entry
112         void status(FuncStatus const & status) { status_ = status; }
113         /**
114          * returns the binding associated to this action.
115          * Use the native UI format when \c forgui is true.
116          */
117         docstring const binding(bool forgui) const;
118         /// the description of the  submenu (if relevant)
119         docstring const & submenuname() const { return submenuname_; }
120         /// set the description of the  submenu
121         void submenuname(docstring const & name) { submenuname_ = name; }
122         ///
123         Menu * submenu() const { return submenu_.get(); }
124         ///
125         void submenu(Menu * menu);
126
127 private:
128         //friend class MenuBackend;
129         ///
130         Kind kind_;
131         ///
132         docstring label_;
133         ///
134         FuncRequest func_;
135         ///
136         docstring submenuname_;
137         ///
138         bool optional_;
139         ///
140         FuncStatus status_;
141         ///
142         boost::shared_ptr<Menu> submenu_;
143 };
144
145
146 ///
147 class Menu {
148 public:
149         ///
150         typedef std::vector<MenuItem> ItemList;
151         ///
152         typedef ItemList::const_iterator const_iterator;
153         ///
154         typedef ItemList::size_type size_type;
155         ///
156         explicit Menu(docstring const & name = docstring())
157                 : name_(name) {}
158         /// Add the menu item unconditionally
159         Menu & add(MenuItem const &);
160         /// Checks the associated FuncRequest status before adding the
161         /// menu item.
162         Menu & addWithStatusCheck(MenuItem const &);
163         ///
164         Menu & read(Lexer &);
165         ///
166         docstring const & name() const { return name_; }
167         ///
168         bool empty() const { return items_.empty(); }
169         /// Clear the menu content.
170         void clear() { items_.clear(); }
171         ///
172         ItemList::size_type size() const { return items_.size(); }
173         ///
174         MenuItem const & operator[](size_type) const;
175         ///
176         bool hasFunc(FuncRequest const &) const;
177         ///
178         const_iterator begin() const {
179                 return items_.begin();
180         }
181         ///
182         const_iterator end() const {
183                 return items_.end();
184         }
185
186         // Check whether the menu shortcuts are unique
187         void checkShortcuts() const;
188
189 private:
190         friend class MenuBackend;
191         ///
192         ItemList items_;
193         ///
194         docstring name_;
195 };
196
197
198 ///
199 class MenuBackend {
200 public:
201         ///
202         typedef std::vector<Menu> MenuList;
203         ///
204         typedef MenuList::const_iterator const_iterator;
205         ///
206         typedef MenuList::iterator iterator;
207         ///
208         MenuBackend() {}
209         ///
210         void read(Lexer &);
211         ///
212         void add(Menu const &);
213         ///
214         bool hasMenu(docstring const &) const;
215         ///
216         Menu & getMenu(docstring const &);
217         ///
218         Menu const & getMenu(docstring const &) const;
219         ///
220         Menu const & getMenubar() const;
221         ///
222         bool empty() const { return menulist_.empty(); }
223         /** This defines a menu whose entries list the FuncRequests
224             that will be removed by expand() in other menus. This is
225             used by the Qt/Mac code
226         */
227         void specialMenu(Menu const &);
228         ///
229         Menu const & specialMenu() { return specialmenu_; }
230
231         /// Expands some special entries of the menu
232         /** The entries with the following kind are expanded to a
233             sequence of Command MenuItems: Lastfiles, Documents,
234             ViewFormats, ExportFormats, UpdateFormats, Branches
235         */
236         void expand(Menu const & frommenu, Menu & tomenu,
237                     Buffer const *) const;
238         ///
239         const_iterator begin() const {
240                 return menulist_.begin();
241         }
242         ///
243         iterator begin() {
244                 return menulist_.begin();
245         }
246         ///
247         const_iterator end() const {
248                 return menulist_.end();
249         }
250         ///
251         iterator end() {
252                 return menulist_.end();
253         }
254 private:
255         ///
256         MenuList menulist_;
257         ///
258         Menu menubar_;
259         ///
260         Menu specialmenu_;
261 };
262
263 ///
264 extern MenuBackend menubackend;
265
266
267 } // namespace lyx
268
269 #endif /* MENUBACKEND_H */