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>
34 /// The type of elements that can be in a menu
42 /** This is the list of last opened file,
43 typically for the File menu. */
45 /** This is the list of opened Documents,
46 typically for the Documents menu. */
48 /** This is the bookmarks */
52 /** This is a list of viewable formats
53 typically for the File->View menu. */
55 /** This is a list of updatable formats
56 typically for the File->Update menu. */
58 /** This is a list of exportable formats
59 typically for the File->Export menu. */
61 /** This is a list of importable formats
62 typically for the File->Export menu. */
64 /** This is the list of elements available
65 * for insertion into document. */
67 /** This is the list of user-configurable
68 insets to insert into document */
70 /** This is the list of XML elements to
71 insert into the document */
73 /** This is the list of floats that we can
76 /** This is the list of floats that we can
79 /** This is the list of selections that can
84 /** Available branches in document */
88 explicit MenuItem(Kind kind);
91 docstring const & label,
92 docstring const & submenu = docstring(),
93 bool optional = false);
96 docstring const & label,
97 FuncRequest const & func,
98 bool optional = false);
100 /// This one is just to please boost::shared_ptr<>
102 /// The label of a given menuitem
103 docstring const label() const;
104 /// The keyboard shortcut (usually underlined in the entry)
105 docstring const shortcut() const;
106 /// The complete label, with label and shortcut separated by a '|'
107 docstring const fulllabel() const { return label_;}
108 /// The kind of entry
109 Kind kind() const { return kind_; }
110 /// the action (if relevant)
111 FuncRequest const & func() const { return func_; }
112 /// returns true if the entry should be ommited when disabled
113 bool optional() const { return optional_; }
114 /// returns the status of the lfun associated with this entry
115 FuncStatus const & status() const { return status_; }
116 /// returns the status of the lfun associated with this entry
117 FuncStatus & status() { return status_; }
118 /// returns the status of the lfun associated with this entry
119 void status(FuncStatus const & status) { status_ = status; }
121 * returns the binding associated to this action.
122 * Use the native UI format when \c forgui is true.
124 docstring const binding(bool forgui) const;
125 /// the description of the submenu (if relevant)
126 docstring const & submenuname() const { return submenuname_; }
127 /// set the description of the submenu
128 void submenuname(docstring const & name) { submenuname_ = name; }
130 Menu * submenu() const { return submenu_.get(); }
132 void submenu(Menu * menu);
135 //friend class MenuBackend;
143 docstring submenuname_;
149 boost::shared_ptr<Menu> submenu_;
157 typedef std::vector<MenuItem> ItemList;
159 typedef ItemList::const_iterator const_iterator;
161 typedef ItemList::size_type size_type;
163 explicit Menu(docstring const & name = docstring()) : name_(name) {}
164 /// Add the menu item unconditionally
165 Menu & add(MenuItem const &);
166 /// Checks the associated FuncRequest status before adding the
168 Menu & addWithStatusCheck(MenuItem const &);
170 Menu & read(Lexer &);
172 docstring const & name() const { return name_; }
174 bool empty() const { return items_.empty(); }
175 /// Clear the menu content.
176 void clear() { items_.clear(); }
178 ItemList::size_type size() const { return items_.size(); }
180 MenuItem const & operator[](size_type) const;
182 bool hasFunc(FuncRequest const &) const;
184 const_iterator begin() const { return items_.begin(); }
186 const_iterator end() const { return items_.end(); }
188 // Check whether the menu shortcuts are unique
189 void checkShortcuts() const;
191 // search for func in this menu iteratively, and put menu
193 bool searchFunc(FuncRequest & func, std::stack<docstring> & names);
196 friend class MenuBackend;
208 typedef std::vector<Menu> MenuList;
210 typedef MenuList::const_iterator const_iterator;
212 typedef MenuList::iterator iterator;
218 void add(Menu const &);
220 bool hasMenu(docstring const &) const;
222 Menu & getMenu(docstring const &);
224 Menu const & getMenu(docstring const &) const;
226 Menu const & getMenubar() const;
228 bool empty() const { return menulist_.empty(); }
229 /** This defines a menu whose entries list the FuncRequests
230 that will be removed by expand() in other menus. This is
231 used by the Qt/Mac code
233 void specialMenu(Menu const &);
235 Menu const & specialMenu() { return specialmenu_; }
237 /// Expands some special entries of the menu
238 /** The entries with the following kind are expanded to a
239 sequence of Command MenuItems: Lastfiles, Documents,
240 ViewFormats, ExportFormats, UpdateFormats, Branches
242 void expand(Menu const & frommenu, Menu & tomenu,
243 Buffer const *) const;
245 const_iterator begin() const { return menulist_.begin(); }
247 iterator begin() { return menulist_.begin(); }
249 const_iterator end() const { return menulist_.end(); }
251 iterator end() { return menulist_.end(); }
263 extern MenuBackend menubackend;
268 #endif // MENUBACKEND_H