]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
f03bf57ec9bd7e1c5f89a23dd589acac7a85f0b3
[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         };
59         /// Create a Command type MenuItem
60         MenuItem(Kind kind, 
61                  string const & label = string(), 
62                  string const & command = string(), 
63                  bool optional = false);
64         MenuItem(Kind kind,
65                  string const & label, 
66                  int action, 
67                  bool optional = false)
68                 : kind_(kind), label_(label),
69                   action_(action), submenu_(), optional_(optional) {}
70  
71         /// The label of a given menuitem
72         string const label() const { return token(label_, '|', 0); }
73         ///
74         string const shortcut() const { return token(label_, '|', 1); }
75         /// The kind of entry
76         Kind kind() const { return kind_; } 
77         /// the action (if relevant)
78         int action() const { return action_; }
79         /// the description of the  submenu (if relevant)
80         string const & submenu() const { return submenu_; }
81         /// returns true if the entry should be ommited when disabled
82         bool optional() const { return optional_; }
83 private:
84         ///
85         Kind kind_;
86         ///
87         string label_;
88         ///
89         int action_;
90         ///
91         string submenu_;
92         ///
93         bool optional_;
94 };
95
96
97 ///
98 class Menu {
99 public:
100         ///
101         typedef std::vector<MenuItem> ItemList;
102         ///
103         typedef ItemList::const_iterator const_iterator;
104         ///
105         explicit Menu(string const & name = string(), bool mb = false) 
106                 : menubar_(mb), name_(name) {}
107         ///
108         Menu & add(MenuItem const &);
109         ///
110         Menu & read(LyXLex &);
111         /// Expands some special entries of the menu
112         /** The entries with the following kind are exanded to a
113             sequence of Command MenuItems: Lastfiles, Documents,
114             ViewFormats, ExportFormats, UpdateFormats
115         */
116         void expand(Menu & tomenu, Buffer *) const;
117         /// 
118         bool menubar() const { return menubar_; }
119         /// 
120         string const & name() const { return name_; }
121         ///
122         bool empty() const { return items_.empty(); }
123         ///
124         ItemList::size_type size() const { return items_.size(); }
125         ///
126         const_iterator begin() const {
127                 return items_.begin();
128         }
129         ///
130         const_iterator end() const {
131                 return items_.end();
132         }
133 private:
134         ///
135         ItemList items_;
136         ///
137         bool menubar_;
138         ///
139         string name_;
140 };
141
142
143 ///
144 class MenuBackend {
145 public:
146         ///
147         typedef std::vector<Menu> MenuList;
148         ///
149         typedef MenuList::const_iterator const_iterator;
150         ///
151         void read(LyXLex &);
152         /// Set default values for menu structure.
153         void defaults();
154         ///
155         void add(Menu const &);
156         ///
157         bool hasMenu (string const &) const;
158         ///
159         Menu & getMenu (string const &);
160         ///
161         Menu const & getMenu (string const &) const;
162         //
163         bool empty() const { return menulist_.empty(); }
164         ///
165         const_iterator begin() const {
166                 return menulist_.begin();
167         }
168         ///
169         const_iterator end() const {
170                 return menulist_.end();
171         }
172 private:
173         ///
174         MenuList menulist_;
175 };
176
177 ///
178 extern MenuBackend menubackend;
179
180 #endif /* MENUBACKEND_H */