]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
patch from dekel and patch from angus
[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
27 ///
28 class MenuItem {
29 public:
30         /// The type of elements that can be in a menu
31         enum Kind {
32                 ///
33                 Command,
34                 ///
35                 Submenu,
36                 ///
37                 Separator,
38                 /** This is the list of last opened file,
39                     typically for the File menu. */
40                 Lastfiles,
41                 /** This is the list of opened Documents,
42                     typically for the Documents menu. */
43                 Documents,
44                 ///
45                 Toc,
46                 ///
47                 References,
48                 /** This is a list of viewable formats
49                     typically for the Documents menu. */
50                 ViewFormats,
51                 /** This is a list of updatable formats
52                     typically for the Documents menu. */
53                 UpdateFormats,
54                 /** This is a list of exportable formats
55                     typically for the Documents menu. */
56                 ExportFormats
57         };
58         /// Create a Command type MenuItem
59         MenuItem(Kind kind, 
60                  string const & label = string(), 
61                  string const & command = string(), 
62                  bool optional = false);
63         /// The label of a given menuitem
64         string label() const { return token(label_, '|', 0); }
65         ///
66         string shortcut() const { return token(label_, '|', 1); }
67         /// The kind of entry
68         Kind kind() const { return kind_; } 
69         /// the action (if relevant)
70         int action() const { return action_; }
71         /// the description of the  submenu (if relevant)
72         string const & submenu() const { return submenu_; }
73         /// returns true if the entry should be ommited when disabled
74         bool optional() const { return optional_; }
75 private:
76         ///
77         Kind kind_;
78         ///
79         string label_;
80         ///
81         int action_;
82         ///
83         string submenu_;
84         ///
85         bool optional_;
86 };
87
88
89 ///
90 class Menu {
91 public:
92         ///
93         typedef std::vector<MenuItem> ItemList;
94         ///
95         typedef ItemList::const_iterator const_iterator;
96         ///
97         explicit Menu(string const & name, bool mb = false) 
98                 : menubar_(mb), name_(name) {}
99         ///
100         Menu & add(MenuItem const &);
101         ///
102         Menu & read(LyXLex &);
103         /// 
104         bool menubar() const { return menubar_; }
105         /// 
106         string const & name() const { return name_; }
107         ///
108         bool empty() const { return items_.empty(); }
109         ///
110         ItemList::size_type size() const { return items_.size(); }
111         ///
112         const_iterator begin() const {
113                 return items_.begin();
114         }
115         ///
116         const_iterator end() const {
117                 return items_.end();
118         }
119 private:
120         ///
121         ItemList items_;
122         ///
123         bool menubar_;
124         ///
125         string name_;
126 };
127
128
129 ///
130 class MenuBackend {
131 public:
132         ///
133         typedef std::vector<Menu> MenuList;
134         ///
135         typedef MenuList::const_iterator const_iterator;
136         ///
137         void read(LyXLex &);
138         /// Set default values for menu structure.
139         void defaults();
140         ///
141         void add(Menu const &);
142         ///
143         bool hasMenu (string const &) const;
144         ///
145         Menu & getMenu (string const &);
146         ///
147         Menu const & getMenu (string const &) const;
148         //
149         bool empty() const { return menulist_.empty(); }
150         ///
151         const_iterator begin() const {
152                 return menulist_.begin();
153         }
154         ///
155         const_iterator end() const {
156                 return menulist_.end();
157         }
158 private:
159         ///
160         MenuList menulist_;
161 };
162
163 ///
164 extern MenuBackend menubackend;
165
166 #endif /* MENUBACKEND_H */