]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
Change MenuBackend and the other menuclasses to store a docstring. Do the required...
[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 class LyXLex;
24 class LyXView;
25 class Menu;
26
27 ///
28 class MenuItem {
29 public:
30         /// The type of elements that can be in a menu
31         enum Kind {
32                 ///
33                 Command,
34                 ///
35                 Submenu,
36                 ///
37                 Separator,
38                 /** This is the list of last opened file,
39                     typically for the File menu. */
40                 Lastfiles,
41                 /** This is the list of opened Documents,
42                     typically for the Documents menu. */
43                 Documents,
44                 ///
45                 Toc,
46                 /** This is a list of viewable formats
47                     typically for the File->View menu. */
48                 ViewFormats,
49                 /** This is a list of updatable formats
50                     typically for the File->Update menu. */
51                 UpdateFormats,
52                 /** This is a list of exportable formats
53                     typically for the File->Export menu. */
54                 ExportFormats,
55                 /** This is a list of importable formats
56                     typically for the File->Export menu. */
57                 ImportFormats,
58                 /** This is the list of elements available
59                  * for insertion into document. */
60                 CharStyles,
61                 /** This is the list of floats that we can
62                     insert a list for. */
63                 FloatListInsert,
64                 /** This is the list of floats that we can
65                     insert. */
66                 FloatInsert,
67                 /** This is the list of selections that can
68                     be pasted. */
69                 PasteRecent,
70                 /** Available branches in document */
71                 Branches
72         };
73
74         explicit MenuItem(Kind kind);
75
76         MenuItem(Kind kind,
77                  lyx::docstring const & label,
78                  lyx::docstring const & submenu = lyx::docstring(),
79                  bool optional = false);
80
81         MenuItem(Kind kind,
82                  lyx::docstring const & label,
83                  FuncRequest const & func,
84                  bool optional = false);
85
86         /// This one is just to please boost::shared_ptr<>
87         ~MenuItem();
88         /// The label of a given menuitem
89         lyx::docstring const label() const;
90         /// The keyboard shortcut (usually underlined in the entry)
91         lyx::docstring const shortcut() const;
92         /// The complete label, with label and shortcut separated by a '|'
93         lyx::docstring const fulllabel() const { return label_;}
94         /// The kind of entry
95         Kind kind() const { return kind_; }
96         /// the action (if relevant)
97         FuncRequest const & func() const { return func_; }
98         /// returns true if the entry should be ommited when disabled
99         bool optional() const { return optional_; }
100         /// returns the status of the lfun associated with this entry
101         FuncStatus const & status() const { return status_; }
102         /// returns the status of the lfun associated with this entry
103         FuncStatus & status() { return status_; }
104         /// returns the status of the lfun associated with this entry
105         void status(FuncStatus const & status) { status_ = status; }
106         /// returns the binding associated to this action
107         lyx::docstring const binding() const;
108         /// the description of the  submenu (if relevant)
109         lyx::docstring const & submenuname() const { return submenuname_; }
110         /// set the description of the  submenu
111         void submenuname(lyx::docstring const & name) { submenuname_ = name; }
112         ///
113         Menu * submenu() const { return submenu_.get(); }
114         ///
115         void submenu(Menu * menu);
116
117 private:
118         //friend class MenuBackend;
119         ///
120         Kind kind_;
121         ///
122         lyx::docstring label_;
123         ///
124         FuncRequest func_;
125         ///
126         lyx::docstring submenuname_;
127         ///
128         bool optional_;
129         ///
130         FuncStatus status_;
131         ///
132         boost::shared_ptr<Menu> submenu_;
133 };
134
135
136 ///
137 class Menu {
138 public:
139         ///
140         typedef std::vector<MenuItem> ItemList;
141         ///
142         typedef ItemList::const_iterator const_iterator;
143         ///
144         typedef ItemList::size_type size_type;
145         ///
146         explicit Menu(lyx::docstring const & name = lyx::docstring())
147                 : name_(name) {}
148         ///
149         Menu & add(MenuItem const &, LyXView const * view = 0);
150         ///
151         Menu & read(LyXLex &);
152         ///
153         lyx::docstring const & name() const { return name_; }
154         ///
155         bool empty() const { return items_.empty(); }
156         /// Clear the menu content.
157         void clear() { items_.clear(); }
158         ///
159         ItemList::size_type size() const { return items_.size(); }
160         ///
161         MenuItem const & operator[](size_type) const;
162         ///
163         bool hasFunc(FuncRequest const &) const;
164         ///
165         const_iterator begin() const {
166                 return items_.begin();
167         }
168         ///
169         const_iterator end() const {
170                 return items_.end();
171         }
172
173         // Check whether the menu shortcuts are unique
174         void checkShortcuts() const;
175
176 private:
177         friend class MenuBackend;
178         ///
179         ItemList items_;
180         ///
181         lyx::docstring name_;
182 };
183
184
185 ///
186 class MenuBackend {
187 public:
188         ///
189         typedef std::vector<Menu> MenuList;
190         ///
191         typedef MenuList::const_iterator const_iterator;
192         ///
193         typedef MenuList::iterator iterator;
194         ///
195         MenuBackend() : specialmenu_(0) {}
196         ///
197         void read(LyXLex &);
198         ///
199         void add(Menu const &);
200         ///
201         bool hasMenu(lyx::docstring const &) const;
202         ///
203         Menu & getMenu(lyx::docstring const &);
204         ///
205         Menu const & getMenu(lyx::docstring const &) const;
206         ///
207         Menu const & getMenubar() const;
208         ///
209         bool empty() const { return menulist_.empty(); }
210         /** This defines a menu whose entries list the FuncRequests
211             will be removed by expand() in other menus. This is used by
212             the Qt/Mac code
213         */
214         void specialMenu(lyx::docstring const &);
215         /// Expands some special entries of the menu
216         /** The entries with the following kind are expanded to a
217             sequence of Command MenuItems: Lastfiles, Documents,
218             ViewFormats, ExportFormats, UpdateFormats, Branches
219         */
220         void expand(Menu const & frommenu, Menu & tomenu,
221                     LyXView const *) const;
222         ///
223         const_iterator begin() const {
224                 return menulist_.begin();
225         }
226         ///
227         iterator begin() {
228                 return menulist_.begin();
229         }
230         ///
231         const_iterator end() const {
232                 return menulist_.end();
233         }
234         ///
235         iterator end() {
236                 return menulist_.end();
237         }
238 private:
239         ///
240         MenuList menulist_;
241         ///
242         Menu menubar_;
243         ///
244         Menu * specialmenu_;
245 };
246
247 ///
248 extern MenuBackend menubackend;
249
250 #endif /* MENUBACKEND_H */