aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/MenuCreator.cc95
1 files changed, 53 insertions, 42 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index a2bdb5c..557cb63 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: MenuCreator.cc,v 1.8 2004/06/08 13:15:30 rathnor Exp $ 23// $Id: MenuCreator.cc,v 1.9 2004/06/10 11:43:24 fluxgen Exp $
24 24
25#include "MenuCreator.hh" 25#include "MenuCreator.hh"
26 26
@@ -92,37 +92,49 @@ static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
92 92
93} 93}
94 94
95static void translateMenuItem(Parser &parse, 95class ParseItem {
96 const std::string &str_key, 96public:
97 const std::string &str_label, 97 explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {}
98 const std::string &str_cmd, 98
99 FbTk::Menu &menu); 99 inline void load(Parser &p) {
100 p>>m_key>>m_label>>m_cmd>>m_icon;
101 }
102 inline const std::string &icon() const { return m_icon.second; }
103 inline const std::string &command() const { return m_cmd.second; }
104 inline const std::string &label() const { return m_label.second; }
105 inline const std::string &key() const { return m_key.second; }
106 inline FbTk::Menu *menu() { return m_menu; }
107private:
108 Parser::Item m_key, m_label, m_cmd, m_icon;
109 FbTk::Menu *m_menu;
110};
111
112
113static void translateMenuItem(Parser &parse, ParseItem &item);
100 114
101 115
102static void parseMenu(Parser &pars, FbTk::Menu &menu) { 116static void parseMenu(Parser &pars, FbTk::Menu &menu) {
103 Parser::Item item, item2, item3; 117 ParseItem pitem(&menu);
104 while (!pars.eof()) { 118 while (!pars.eof()) {
105 pars>>item>>item2>>item3; 119 pitem.load(pars);
106 if (item.second == "end") 120 if (pitem.key() == "end")
107 return; 121 return;
108 translateMenuItem(pars, 122 translateMenuItem(pars, pitem);
109 item.second,
110 item2.second,
111 item3.second,
112 menu);
113
114 } 123 }
115} 124}
116 125
117static void translateMenuItem(Parser &parse, 126static void translateMenuItem(Parser &parse, ParseItem &pitem) {
118 const std::string &str_key, 127 if (pitem.menu() == 0)
119 const std::string &str_label, 128 throw string("translateMenuItem: We must have a menu in ParseItem!");
120 const std::string &str_cmd, 129
121 FbTk::Menu &menu) { 130 FbTk::Menu &menu = *pitem.menu();
122 131 const std::string &str_key = pitem.key();
132 const std::string &str_cmd = pitem.command();
133 const std::string &str_label = pitem.label();
134
123 const int screen_number = menu.screenNumber(); 135 const int screen_number = menu.screenNumber();
124 _FB_USES_NLS; 136 _FB_USES_NLS;
125 137
126 if (str_key == "end") { 138 if (str_key == "end") {
127 return; 139 return;
128 } else if (str_key == "nop") { 140 } else if (str_key == "nop") {
@@ -215,13 +227,7 @@ static void translateMenuItem(Parser &parse,
215 } 227 }
216 } else if (str_key == "separator") { 228 } else if (str_key == "separator") {
217 menu.insert(new FbTk::MenuSeparator()); 229 menu.insert(new FbTk::MenuSeparator());
218 }/* else if (str_key == "icon") { 230 }
219 FbTk::RefCount<FbTk::Command> cmd(CommandParser::instance().parseLine(str_cmd));
220 FbTk::MenuItem *item = new FbTk::MenuIcon(str_label, str_cmd, screen_number);
221 item->setCommand(cmd);
222 menu.insert(item);
223
224 }*/
225 else { // ok, if we didn't find any special menu item we try with command parser 231 else { // ok, if we didn't find any special menu item we try with command parser
226 // we need to attach command with arguments so command parser can parse it 232 // we need to attach command with arguments so command parser can parse it
227 string line = str_key + " " + str_cmd; 233 string line = str_key + " " + str_cmd;
@@ -229,28 +235,32 @@ static void translateMenuItem(Parser &parse,
229 if (*command != 0) 235 if (*command != 0)
230 menu.insert(str_label.c_str(), command); 236 menu.insert(str_label.c_str(), command);
231 } 237 }
232 238 if (menu.numberOfItems() != 0) {
239 FbTk::MenuItem *item = menu.find(menu.numberOfItems() - 1);
240 if (item != 0 && !pitem.icon().empty())
241 item->setIcon(pitem.icon().c_str(), menu.screenNumber());
242 }
233} 243}
234 244
235 245
236static void parseWindowMenu(Parser &parse, FbTk::Menu &menu, FluxboxWindow &win) { 246static void parseWindowMenu(Parser &parse, FbTk::Menu &menu, FluxboxWindow &win) {
237 247
238 Parser::Item item, item2, item3; 248 ParseItem pitem(&menu);
239 while (!parse.eof()) { 249 while (!parse.eof()) {
240 parse>>item>>item2>>item3; 250 pitem.load(parse);
241 if (MenuCreator::createWindowMenuItem(item.second, item2.second, menu, win)) 251 if (MenuCreator::createWindowMenuItem(pitem.key(), pitem.label(), menu, win))
242 continue; 252 continue;
243 253
244 if (item.second == "end") { 254 if (pitem.key() == "end") {
245 return; 255 return;
246 } else if (item.second == "submenu") { 256 } else if (pitem.key() == "submenu") {
247 FbTk::Menu *submenu = MenuCreator::createMenu(item2.second, menu.screenNumber()); 257 FbTk::Menu *submenu = MenuCreator::createMenu(pitem.label(), menu.screenNumber());
248 parseWindowMenu(parse, *submenu, win); 258 parseWindowMenu(parse, *submenu, win);
249 submenu->update(); 259 submenu->update();
250 menu.insert(item2.second.c_str(), submenu); 260 menu.insert(pitem.label().c_str(), submenu);
251 261
252 } else { // try non window menu specific stuff 262 } else { // try non window menu specific stuff
253 translateMenuItem(parse, item.second, item2.second, item3.second, menu); 263 translateMenuItem(parse, pitem);
254 } 264 }
255 } 265 }
256} 266}
@@ -271,17 +281,18 @@ FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number)
271} 281}
272 282
273bool getStart(FbMenuParser &parser, std::string &label) { 283bool getStart(FbMenuParser &parser, std::string &label) {
274 Parser::Item item, item2, item3; 284 ParseItem pitem(0);
275 while (!parser.eof()) { 285 while (!parser.eof()) {
276 // get first begin line 286 // get first begin line
277 parser>>item>>item2>>item3; 287 pitem.load(parser);
278 if (item.second == "begin") { 288 if (pitem.key() == "begin") {
279 break; 289 break;
280 } 290 }
281 } 291 }
282 if (parser.eof()) 292 if (parser.eof())
283 return false; 293 return false;
284 label = item2.second; 294
295 label = pitem.label();
285 return true; 296 return true;
286} 297}
287 298