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