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