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