aboutsummaryrefslogtreecommitdiff
path: root/src/MenuCreator.cc
diff options
context:
space:
mode:
authormathias <mathias>2006-10-30 19:31:15 (GMT)
committermathias <mathias>2006-10-30 19:31:15 (GMT)
commite5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5 (patch)
treec84838a84802805e9b1463045e86200b7cef917f /src/MenuCreator.cc
parent426c12c25c2ef095a882619ad7424684b88465b8 (diff)
downloadfluxbox-e5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5.zip
fluxbox-e5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5.tar.bz2
Cosmetic patch from Slava Semushin
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r--src/MenuCreator.cc111
1 files changed, 58 insertions, 53 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index e33db19..030991c 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -53,15 +53,21 @@
53#include "FbTk/MenuIcon.hh" 53#include "FbTk/MenuIcon.hh"
54 54
55#include <iostream> 55#include <iostream>
56using namespace std;
57 56
58std::list<std::string> MenuCreator::encoding_stack; 57using std::cerr;
59std::list<size_t> MenuCreator::stacksize_stack; 58using std::endl;
59using std::string;
60using std::vector;
61using std::list;
62using std::less;
63
64list<string> MenuCreator::encoding_stack;
65list<size_t> MenuCreator::stacksize_stack;
60 66
61FbTk::StringConvertor MenuCreator::m_stringconvertor(FbTk::StringConvertor::ToFbString); 67FbTk::StringConvertor MenuCreator::m_stringconvertor(FbTk::StringConvertor::ToFbString);
62 68
63static void createStyleMenu(FbTk::Menu &parent, const std::string &label, 69static void createStyleMenu(FbTk::Menu &parent, const string &label,
64 const std::string &directory) { 70 const string &directory) {
65 // perform shell style ~ home directory expansion 71 // perform shell style ~ home directory expansion
66 string stylesdir(FbTk::StringUtil::expandFilename(directory)); 72 string stylesdir(FbTk::StringUtil::expandFilename(directory));
67 73
@@ -72,15 +78,15 @@ static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
72 78
73 // create a vector of all the filenames in the directory 79 // create a vector of all the filenames in the directory
74 // add sort it 80 // add sort it
75 std::vector<std::string> filelist(dir.entries()); 81 vector<string> filelist(dir.entries());
76 for (size_t file_index = 0; file_index < dir.entries(); ++file_index) 82 for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
77 filelist[file_index] = dir.readFilename(); 83 filelist[file_index] = dir.readFilename();
78 84
79 std::sort(filelist.begin(), filelist.end(), less<string>()); 85 sort(filelist.begin(), filelist.end(), less<string>());
80 86
81 // for each file in directory add filename and path to menu 87 // for each file in directory add filename and path to menu
82 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 88 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
83 std::string style(stylesdir + '/' + filelist[file_index]); 89 string style(stylesdir + '/' + filelist[file_index]);
84 // add to menu only if the file is a regular file, and not a 90 // add to menu only if the file is a regular file, and not a
85 // .file or a backup~ file 91 // .file or a backup~ file
86 if ((FbTk::FileUtil::isRegularFile(style.c_str()) && 92 if ((FbTk::FileUtil::isRegularFile(style.c_str()) &&
@@ -140,10 +146,10 @@ public:
140 p>>m_key>>m_label>>m_cmd>>m_icon; 146 p>>m_key>>m_label>>m_cmd>>m_icon;
141 m_label.second = m_labelconvertor.recode(m_label.second); 147 m_label.second = m_labelconvertor.recode(m_label.second);
142 } 148 }
143 inline const std::string &icon() const { return m_icon.second; } 149 inline const string &icon() const { return m_icon.second; }
144 inline const std::string &command() const { return m_cmd.second; } 150 inline const string &command() const { return m_cmd.second; }
145 inline const std::string &label() const { return m_label.second; } 151 inline const string &label() const { return m_label.second; }
146 inline const std::string &key() const { return m_key.second; } 152 inline const string &key() const { return m_key.second; }
147 inline FbTk::Menu *menu() { return m_menu; } 153 inline FbTk::Menu *menu() { return m_menu; }
148private: 154private:
149 Parser::Item m_key, m_label, m_cmd, m_icon; 155 Parser::Item m_key, m_label, m_cmd, m_icon;
@@ -182,9 +188,9 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve
182 throw string("translateMenuItem: We must have a menu in ParseItem!"); 188 throw string("translateMenuItem: We must have a menu in ParseItem!");
183 189
184 FbTk::Menu &menu = *pitem.menu(); 190 FbTk::Menu &menu = *pitem.menu();
185 const std::string &str_key = pitem.key(); 191 const string &str_key = pitem.key();
186 const std::string &str_cmd = pitem.command(); 192 const string &str_cmd = pitem.command();
187 const std::string &str_label = pitem.label(); 193 const string &str_label = pitem.label();
188 194
189 const int screen_number = menu.screenNumber(); 195 const int screen_number = menu.screenNumber();
190 _FB_USES_NLS; 196 _FB_USES_NLS;
@@ -250,13 +256,13 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve
250 // inject every file in this directory into the current menu 256 // inject every file in this directory into the current menu
251 FbTk::Directory dir(newfile.c_str()); 257 FbTk::Directory dir(newfile.c_str());
252 258
253 std::vector<std::string> filelist(dir.entries()); 259 vector<string> filelist(dir.entries());
254 for (size_t file_index = 0; file_index < dir.entries(); ++file_index) 260 for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
255 filelist[file_index] = dir.readFilename(); 261 filelist[file_index] = dir.readFilename();
256 std::sort(filelist.begin(), filelist.end(), less<string>()); 262 sort(filelist.begin(), filelist.end(), less<string>());
257 263
258 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 264 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
259 std::string thisfile(newfile + '/' + filelist[file_index]); 265 string thisfile(newfile + '/' + filelist[file_index]);
260 266
261 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) && 267 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
262 (filelist[file_index][0] != '.') && 268 (filelist[file_index][0] != '.') &&
@@ -367,7 +373,7 @@ static void parseWindowMenu(Parser &parse, FbTk::Menu &menu, FbTk::StringConvert
367 } 373 }
368} 374}
369 375
370FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number) { 376FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) {
371 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 377 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
372 if (screen == 0) 378 if (screen == 0)
373 return 0; 379 return 0;
@@ -381,7 +387,7 @@ FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number)
381 return menu; 387 return menu;
382} 388}
383 389
384bool getStart(FbMenuParser &parser, std::string &label, FbTk::StringConvertor &labelconvertor) { 390bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelconvertor) {
385 ParseItem pitem(0); 391 ParseItem pitem(0);
386 while (!parser.eof()) { 392 while (!parser.eof()) {
387 // get first begin line 393 // get first begin line
@@ -397,15 +403,15 @@ bool getStart(FbMenuParser &parser, std::string &label, FbTk::StringConvertor &l
397 return true; 403 return true;
398} 404}
399 405
400FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_number, bool require_begin) { 406FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number, bool require_begin) {
401 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 407 string real_filename = FbTk::StringUtil::expandFilename(filename);
402 Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); 408 Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
403 409
404 FbMenuParser parser(real_filename); 410 FbMenuParser parser(real_filename);
405 if (!parser.isLoaded()) 411 if (!parser.isLoaded())
406 return 0; 412 return 0;
407 413
408 std::string label; 414 string label;
409 if (require_begin && !getStart(parser, label, m_stringconvertor)) 415 if (require_begin && !getStart(parser, label, m_stringconvertor))
410 return 0; 416 return 0;
411 417
@@ -420,15 +426,15 @@ FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_
420} 426}
421 427
422 428
423bool MenuCreator::createFromFile(const std::string &filename, 429bool MenuCreator::createFromFile(const string &filename,
424 FbTk::Menu &inject_into, bool require_begin) { 430 FbTk::Menu &inject_into, bool require_begin) {
425 431
426 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 432 string real_filename = FbTk::StringUtil::expandFilename(filename);
427 FbMenuParser parser(real_filename); 433 FbMenuParser parser(real_filename);
428 if (!parser.isLoaded()) 434 if (!parser.isLoaded())
429 return false; 435 return false;
430 436
431 std::string label; 437 string label;
432 if (require_begin && !getStart(parser, label, m_stringconvertor)) 438 if (require_begin && !getStart(parser, label, m_stringconvertor))
433 return false; 439 return false;
434 440
@@ -440,15 +446,15 @@ bool MenuCreator::createFromFile(const std::string &filename,
440} 446}
441 447
442 448
443bool MenuCreator::createWindowMenuFromFile(const std::string &filename, 449bool MenuCreator::createWindowMenuFromFile(const string &filename,
444 FbTk::Menu &inject_into, 450 FbTk::Menu &inject_into,
445 bool require_begin) { 451 bool require_begin) {
446 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 452 string real_filename = FbTk::StringUtil::expandFilename(filename);
447 FbMenuParser parser(real_filename); 453 FbMenuParser parser(real_filename);
448 if (!parser.isLoaded()) 454 if (!parser.isLoaded())
449 return false; 455 return false;
450 456
451 std::string label; 457 string label;
452 458
453 if (require_begin && !getStart(parser, label, m_stringconvertor)) 459 if (require_begin && !getStart(parser, label, m_stringconvertor))
454 return false; 460 return false;
@@ -461,7 +467,7 @@ bool MenuCreator::createWindowMenuFromFile(const std::string &filename,
461} 467}
462 468
463 469
464FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num) { 470FbTk::Menu *MenuCreator::createMenuType(const string &type, int screen_num) {
465 BScreen *screen = Fluxbox::instance()->findScreen(screen_num); 471 BScreen *screen = Fluxbox::instance()->findScreen(screen_num);
466 if (screen == 0) 472 if (screen == 0)
467 return 0; 473 return 0;
@@ -476,7 +482,7 @@ FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num)
476 if (screen->windowMenuFilename().empty() || 482 if (screen->windowMenuFilename().empty() ||
477 ! createWindowMenuFromFile(screen->windowMenuFilename(), *menu, true)) { 483 ! createWindowMenuFromFile(screen->windowMenuFilename(), *menu, true)) {
478 char *default_menu[] = { 484 char *default_menu[] = {
479 "shade", 485 "shade",
480 "stick", 486 "stick",
481 "maximize", 487 "maximize",
482 "iconify", 488 "iconify",
@@ -499,8 +505,8 @@ FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num)
499 return 0; 505 return 0;
500} 506}
501 507
502bool MenuCreator::createWindowMenuItem(const std::string &type, 508bool MenuCreator::createWindowMenuItem(const string &type,
503 const std::string &label, 509 const string &label,
504 FbTk::Menu &menu) { 510 FbTk::Menu &menu) {
505 typedef FbTk::RefCount<FbTk::Command> RefCmd; 511 typedef FbTk::RefCount<FbTk::Command> RefCmd;
506 _FB_USES_NLS; 512 _FB_USES_NLS;
@@ -512,10 +518,10 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
512 RefCmd maximize_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeFull)); 518 RefCmd maximize_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeFull));
513 RefCmd maximize_vert_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeVertical)); 519 RefCmd maximize_vert_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeVertical));
514 RefCmd maximize_horiz_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeHorizontal)); 520 RefCmd maximize_horiz_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeHorizontal));
515 FbTk::MultiButtonMenuItem *maximize_item = 521 FbTk::MultiButtonMenuItem *maximize_item =
516 new FbTk::MultiButtonMenuItem(3, 522 new FbTk::MultiButtonMenuItem(3,
517 label.empty()? 523 label.empty()?
518 _FB_XTEXT(Windowmenu, Maximize, 524 _FB_XTEXT(Windowmenu, Maximize,
519 "Maximize", "Maximize the window"): 525 "Maximize", "Maximize the window"):
520 label); 526 label);
521 // create maximize item with: 527 // create maximize item with:
@@ -529,37 +535,37 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
529 } else if (type == "iconify") { 535 } else if (type == "iconify") {
530 RefCmd iconify_cmd(new WindowCmd<void>(&FluxboxWindow::iconify)); 536 RefCmd iconify_cmd(new WindowCmd<void>(&FluxboxWindow::iconify));
531 menu.insert(label.empty() ? 537 menu.insert(label.empty() ?
532 _FB_XTEXT(Windowmenu, Iconify, 538 _FB_XTEXT(Windowmenu, Iconify,
533 "Iconify", "Iconify the window") : 539 "Iconify", "Iconify the window") :
534 label, iconify_cmd); 540 label, iconify_cmd);
535 } else if (type == "close") { 541 } else if (type == "close") {
536 RefCmd close_cmd(new WindowCmd<void>(&FluxboxWindow::close)); 542 RefCmd close_cmd(new WindowCmd<void>(&FluxboxWindow::close));
537 menu.insert(label.empty() ? 543 menu.insert(label.empty() ?
538 _FB_XTEXT(Windowmenu, Close, 544 _FB_XTEXT(Windowmenu, Close,
539 "Close", "Close the window") : 545 "Close", "Close the window") :
540 label, close_cmd); 546 label, close_cmd);
541 } else if (type == "kill" || type == "killwindow") { 547 } else if (type == "kill" || type == "killwindow") {
542 RefCmd kill_cmd(new WindowCmd<void>(&FluxboxWindow::kill)); 548 RefCmd kill_cmd(new WindowCmd<void>(&FluxboxWindow::kill));
543 menu.insert(label.empty() ? 549 menu.insert(label.empty() ?
544 _FB_XTEXT(Windowmenu, Kill, 550 _FB_XTEXT(Windowmenu, Kill,
545 "Kill", "Kill the window"): 551 "Kill", "Kill the window"):
546 label, kill_cmd); 552 label, kill_cmd);
547 } else if (type == "lower") { 553 } else if (type == "lower") {
548 RefCmd lower_cmd(new WindowCmd<void>(&FluxboxWindow::lower)); 554 RefCmd lower_cmd(new WindowCmd<void>(&FluxboxWindow::lower));
549 menu.insert( label.empty() ? 555 menu.insert( label.empty() ?
550 _FB_XTEXT(Windowmenu, Lower, 556 _FB_XTEXT(Windowmenu, Lower,
551 "Lower", "Lower the window"): 557 "Lower", "Lower the window"):
552 label, lower_cmd); 558 label, lower_cmd);
553 } else if (type == "raise") { 559 } else if (type == "raise") {
554 RefCmd raise_cmd(new WindowCmd<void>(&FluxboxWindow::raise)); 560 RefCmd raise_cmd(new WindowCmd<void>(&FluxboxWindow::raise));
555 menu.insert(label.empty() ? 561 menu.insert(label.empty() ?
556 _FB_XTEXT(Windowmenu, Raise, 562 _FB_XTEXT(Windowmenu, Raise,
557 "Raise", "Raise the window"): 563 "Raise", "Raise the window"):
558 label, raise_cmd); 564 label, raise_cmd);
559 } else if (type == "stick") { 565 } else if (type == "stick") {
560 RefCmd stick_cmd(new WindowCmd<void>(&FluxboxWindow::stick)); 566 RefCmd stick_cmd(new WindowCmd<void>(&FluxboxWindow::stick));
561 menu.insert(label.empty() ? 567 menu.insert(label.empty() ?
562 _FB_XTEXT(Windowmenu, Stick, 568 _FB_XTEXT(Windowmenu, Stick,
563 "Stick", "Stick the window"): 569 "Stick", "Stick the window"):
564 label, stick_cmd); 570 label, stick_cmd);
565 } else if (type == "extramenus") { 571 } else if (type == "extramenus") {
@@ -570,7 +576,7 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
570 it->second->disableTitle(); 576 it->second->disableTitle();
571 menu.insert(it->first, it->second); 577 menu.insert(it->first, it->second);
572 } 578 }
573 579
574 } else if (type == "sendto") { 580 } else if (type == "sendto") {
575 menu.insert(label.empty() ? _FB_XTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"): 581 menu.insert(label.empty() ? _FB_XTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"):
576 label, new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber()))); 582 label, new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber())));
@@ -621,7 +627,7 @@ void MenuCreator::endFile() {
621 for (; curr_size > (target_size+1); --curr_size) 627 for (; curr_size > (target_size+1); --curr_size)
622 encoding_stack.pop_back(); 628 encoding_stack.pop_back();
623 629
624 if (curr_size == (target_size+1)) 630 if (curr_size == (target_size+1))
625 endEncoding(); 631 endEncoding();
626 632
627 stacksize_stack.pop_back(); 633 stacksize_stack.pop_back();
@@ -630,7 +636,7 @@ void MenuCreator::endFile() {
630/** 636/**
631 * Push the encoding onto the stack, and make it active. 637 * Push the encoding onto the stack, and make it active.
632 */ 638 */
633void MenuCreator::startEncoding(const std::string &encoding) { 639void MenuCreator::startEncoding(const string &encoding) {
634 // we push it regardless of whether it's valid, since we 640 // we push it regardless of whether it's valid, since we
635 // need to stay balanced with the endEncodings. 641 // need to stay balanced with the endEncodings.
636 encoding_stack.push_back(encoding); 642 encoding_stack.push_back(encoding);
@@ -646,7 +652,6 @@ void MenuCreator::startEncoding(const std::string &encoding) {
646void MenuCreator::endEncoding() { 652void MenuCreator::endEncoding() {
647 size_t min_size = stacksize_stack.back(); 653 size_t min_size = stacksize_stack.back();
648 if (encoding_stack.size() <= min_size) { 654 if (encoding_stack.size() <= min_size) {
649 // TODO: nls
650 _FB_USES_NLS; 655 _FB_USES_NLS;
651 cerr<<_FB_CONSOLETEXT(Menu, ErrorEndEncoding, "Warning: unbalanced [encoding] tags", "User menu file had unbalanced [encoding] tags")<<endl; 656 cerr<<_FB_CONSOLETEXT(Menu, ErrorEndEncoding, "Warning: unbalanced [encoding] tags", "User menu file had unbalanced [encoding] tags")<<endl;
652 return; 657 return;
@@ -655,8 +660,8 @@ void MenuCreator::endEncoding() {
655 encoding_stack.pop_back(); 660 encoding_stack.pop_back();
656 m_stringconvertor.reset(); 661 m_stringconvertor.reset();
657 662
658 std::list<std::string>::reverse_iterator it = encoding_stack.rbegin(); 663 list<string>::reverse_iterator it = encoding_stack.rbegin();
659 std::list<std::string>::reverse_iterator it_end = encoding_stack.rend(); 664 list<string>::reverse_iterator it_end = encoding_stack.rend();
660 while (it != it_end && !m_stringconvertor.setSource(*it)) 665 while (it != it_end && !m_stringconvertor.setSource(*it))
661 ++it; 666 ++it;
662 667