]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
Small fixes
[lyx.git] / src / MenuBackend.h
1 /* This file is part of              -*- C++ -*-
2 * ======================================================
3
4 *           LyX, The Document Processor
5 *
6 *           Copyright 1995 Matthias Ettrich
7 *           Copyright 1995-2000 The LyX Team.
8 *
9 *           This file is Copyright 1999
10 *           Jean-Marc Lasgouttes
11 *
12 *======================================================*/
13
14 #ifndef MENUBACKEND_H
15 #define MENUBACKEND_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "LString.h"
22 #include "support/lstrings.h"
23 #include <vector>
24
25 class LyXLex;
26 class Buffer;
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                 ///
48                 References,
49                 /** This is a list of viewable formats
50                     typically for the File->View menu. */
51                 ViewFormats,
52                 /** This is a list of updatable formats
53                     typically for the File->Update menu. */
54                 UpdateFormats,
55                 /** This is a list of exportable formats
56                     typically for the File->Export menu. */
57                 ExportFormats,
58                 /** This is a list of importable formats
59                     typically for the File->Export menu. */
60                 ImportFormats
61         };
62         /// Create a Command type MenuItem
63         MenuItem(Kind kind, 
64                  string const & label = string(), 
65                  string const & command = string(), 
66                  bool optional = false);
67         MenuItem(Kind kind,
68                  string const & label, 
69                  int action, 
70                  bool optional = false)
71                 : kind_(kind), label_(label),
72                   action_(action), submenu_(), optional_(optional) {}
73  
74         /// The label of a given menuitem
75         string const label() const { return token(label_, '|', 0); }
76         /// The keyboard shortcut (usually underlined in the entry)
77         string const shortcut() const { return token(label_, '|', 1); }
78         /// The complete label, with label and shortcut separated by a '|'
79         string const fulllabel() const { return label_;}
80         /// The kind of entry
81         Kind kind() const { return kind_; } 
82         /// the action (if relevant)
83         int action() const { return action_; }
84         /// the description of the  submenu (if relevant)
85         string const & submenu() const { return submenu_; }
86         /// returns true if the entry should be ommited when disabled
87         bool optional() const { return optional_; }
88 private:
89         ///
90         Kind kind_;
91         ///
92         string label_;
93         ///
94         int action_;
95         ///
96         string submenu_;
97         ///
98         bool optional_;
99 };
100
101
102 ///
103 class Menu {
104 public:
105         ///
106         typedef std::vector<MenuItem> ItemList;
107         ///
108         typedef ItemList::const_iterator const_iterator;
109         ///
110         explicit Menu(string const & name = string(), bool mb = false) 
111                 : menubar_(mb), name_(name) {}
112         ///
113         Menu & add(MenuItem const &);
114         ///
115         Menu & read(LyXLex &);
116         /// Expands some special entries of the menu
117         /** The entries with the following kind are expanded to a
118             sequence of Command MenuItems: Lastfiles, Documents,
119             ViewFormats, ExportFormats, UpdateFormats
120         */
121         void expand(Menu & tomenu, Buffer *) const;
122         /// 
123         bool menubar() const { return menubar_; }
124         /// 
125         string const & name() const { return name_; }
126         ///
127         bool empty() const { return items_.empty(); }
128         ///
129         ItemList::size_type size() const { return items_.size(); }
130         ///
131         bool hasSubmenu(string const &) const;
132         ///
133         const_iterator begin() const {
134                 return items_.begin();
135         }
136         ///
137         const_iterator end() const {
138                 return items_.end();
139         }
140
141         // Check whether the menu shortcuts are unique
142         void checkShortcuts() const;
143         
144 private:
145         ///
146         ItemList items_;
147         ///
148         bool menubar_;
149         ///
150         string name_;
151 };
152
153
154 ///
155 class MenuBackend {
156 public:
157         ///
158         typedef std::vector<Menu> MenuList;
159         ///
160         typedef MenuList::const_iterator const_iterator;
161         ///
162         void read(LyXLex &);
163         /// Set default values for menu structure.
164         void defaults();
165         ///
166         void add(Menu const &);
167         ///
168         bool hasMenu(string const &) const;
169         ///
170         Menu & getMenu (string const &);
171         ///
172         Menu const & getMenu (string const &) const;
173         //
174         bool empty() const { return menulist_.empty(); }
175         ///
176         const_iterator begin() const {
177                 return menulist_.begin();
178         }
179         ///
180         const_iterator end() const {
181                 return menulist_.end();
182         }
183 private:
184         ///
185         MenuList menulist_;
186 };
187
188 ///
189 extern MenuBackend menubackend;
190
191 #endif /* MENUBACKEND_H */