4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
16 #include "FuncStatus.h"
17 #include "funcrequest.h"
19 #include <boost/shared_ptr.hpp>
30 /// The type of elements that can be in a menu
38 /** This is the list of last opened file,
39 typically for the File menu. */
41 /** This is the list of opened Documents,
42 typically for the Documents menu. */
46 /** This is a list of viewable formats
47 typically for the File->View menu. */
49 /** This is a list of updatable formats
50 typically for the File->Update menu. */
52 /** This is a list of exportable formats
53 typically for the File->Export menu. */
55 /** This is a list of importable formats
56 typically for the File->Export menu. */
58 /** This is the list of elements available
59 * for insertion into document. */
61 /** This is the list of floats that we can
64 /** This is the list of floats that we can
67 /** This is the list of selections that can
70 /** Available branches in document */
74 explicit MenuItem(Kind kind);
77 lyx::docstring const & label,
78 lyx::docstring const & submenu = lyx::docstring(),
79 bool optional = false);
82 lyx::docstring const & label,
83 FuncRequest const & func,
84 bool optional = false);
86 /// This one is just to please boost::shared_ptr<>
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_;}
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; }
113 Menu * submenu() const { return submenu_.get(); }
115 void submenu(Menu * menu);
118 //friend class MenuBackend;
122 lyx::docstring label_;
126 lyx::docstring submenuname_;
132 boost::shared_ptr<Menu> submenu_;
140 typedef std::vector<MenuItem> ItemList;
142 typedef ItemList::const_iterator const_iterator;
144 typedef ItemList::size_type size_type;
146 explicit Menu(lyx::docstring const & name = lyx::docstring())
148 /// Add the menu item unconditionally
149 Menu & add(MenuItem const &);
150 /// Checks the associated FuncRequest status before adding the
152 Menu & addWithStatusCheck(MenuItem const &);
154 Menu & read(LyXLex &);
156 lyx::docstring const & name() const { return name_; }
158 bool empty() const { return items_.empty(); }
159 /// Clear the menu content.
160 void clear() { items_.clear(); }
162 ItemList::size_type size() const { return items_.size(); }
164 MenuItem const & operator[](size_type) const;
166 bool hasFunc(FuncRequest const &) const;
168 const_iterator begin() const {
169 return items_.begin();
172 const_iterator end() const {
176 // Check whether the menu shortcuts are unique
177 void checkShortcuts() const;
180 friend class MenuBackend;
184 lyx::docstring name_;
192 typedef std::vector<Menu> MenuList;
194 typedef MenuList::const_iterator const_iterator;
196 typedef MenuList::iterator iterator;
198 MenuBackend() : specialmenu_(0) {}
202 void add(Menu const &);
204 bool hasMenu(lyx::docstring const &) const;
206 Menu & getMenu(lyx::docstring const &);
208 Menu const & getMenu(lyx::docstring const &) const;
210 Menu const & getMenubar() const;
212 bool empty() const { return menulist_.empty(); }
213 /** This defines a menu whose entries list the FuncRequests
214 will be removed by expand() in other menus. This is used by
217 void specialMenu(lyx::docstring const &);
218 /// Expands some special entries of the menu
219 /** The entries with the following kind are expanded to a
220 sequence of Command MenuItems: Lastfiles, Documents,
221 ViewFormats, ExportFormats, UpdateFormats, Branches
223 void expand(Menu const & frommenu, Menu & tomenu,
224 Buffer const *) const;
226 const_iterator begin() const {
227 return menulist_.begin();
231 return menulist_.begin();
234 const_iterator end() const {
235 return menulist_.end();
239 return menulist_.end();
251 extern MenuBackend menubackend;
253 #endif /* MENUBACKEND_H */