aboutsummaryrefslogtreecommitdiff
path: root/src/MenuCreator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r--src/MenuCreator.cc122
1 files changed, 83 insertions, 39 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index 2cf281f..0bbd14f 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -29,6 +29,7 @@
29#include "fluxbox.hh" 29#include "fluxbox.hh"
30#include "CommandParser.hh" 30#include "CommandParser.hh"
31#include "Window.hh" 31#include "Window.hh"
32#include "WindowCmd.hh"
32 33
33#include "FbMenu.hh" 34#include "FbMenu.hh"
34#include "IconMenu.hh" 35#include "IconMenu.hh"
@@ -53,13 +54,8 @@
53#include <iostream> 54#include <iostream>
54using namespace std; 55using namespace std;
55 56
56template <>
57void LayerMenuItem<FluxboxWindow>::click(int button, int time) {
58 m_object->moveToLayer(m_layernum);
59}
60
61static void createStyleMenu(FbTk::Menu &parent, const std::string &label, 57static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
62 const std::string &directory) { 58 const std::string &directory) {
63 // perform shell style ~ home directory expansion 59 // perform shell style ~ home directory expansion
64 string stylesdir(FbTk::StringUtil::expandFilename(directory)); 60 string stylesdir(FbTk::StringUtil::expandFilename(directory));
65 61
@@ -326,19 +322,19 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
326} 322}
327 323
328 324
329static void parseWindowMenu(Parser &parse, FbTk::Menu &menu, FluxboxWindow &win) { 325static void parseWindowMenu(Parser &parse, FbTk::Menu &menu) {
330 326
331 ParseItem pitem(&menu); 327 ParseItem pitem(&menu);
332 while (!parse.eof()) { 328 while (!parse.eof()) {
333 pitem.load(parse); 329 pitem.load(parse);
334 if (MenuCreator::createWindowMenuItem(pitem.key(), pitem.label(), menu, win)) 330 if (MenuCreator::createWindowMenuItem(pitem.key(), pitem.label(), menu))
335 continue; 331 continue;
336 332
337 if (pitem.key() == "end") { 333 if (pitem.key() == "end") {
338 return; 334 return;
339 } else if (pitem.key() == "submenu") { 335 } else if (pitem.key() == "submenu") {
340 FbTk::Menu *submenu = MenuCreator::createMenu(pitem.label(), menu.screenNumber()); 336 FbTk::Menu *submenu = MenuCreator::createMenu(pitem.label(), menu.screenNumber());
341 parseWindowMenu(parse, *submenu, win); 337 parseWindowMenu(parse, *submenu);
342 submenu->updateMenu(); 338 submenu->updateMenu();
343 menu.insert(pitem.label().c_str(), submenu); 339 menu.insert(pitem.label().c_str(), submenu);
344 340
@@ -416,9 +412,9 @@ bool MenuCreator::createFromFile(const std::string &filename,
416} 412}
417 413
418 414
419bool MenuCreator::createFromFile(const std::string &filename, 415bool MenuCreator::createWindowMenuFromFile(const std::string &filename,
420 FbTk::Menu &inject_into, 416 FbTk::Menu &inject_into,
421 FluxboxWindow &win, bool require_begin) { 417 bool require_begin) {
422 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 418 std::string real_filename = FbTk::StringUtil::expandFilename(filename);
423 FbMenuParser parser(real_filename); 419 FbMenuParser parser(real_filename);
424 if (!parser.isLoaded()) 420 if (!parser.isLoaded())
@@ -429,7 +425,7 @@ bool MenuCreator::createFromFile(const std::string &filename,
429 if (require_begin && !getStart(parser, label)) 425 if (require_begin && !getStart(parser, label))
430 return false; 426 return false;
431 427
432 parseWindowMenu(parser, inject_into, win); 428 parseWindowMenu(parser, inject_into);
433 return true; 429 return true;
434} 430}
435 431
@@ -442,26 +438,56 @@ FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num)
442 return new IconMenu(*screen); 438 return new IconMenu(*screen);
443 } else if (type == "workspacemenu") { 439 } else if (type == "workspacemenu") {
444 return new WorkspaceMenu(*screen); 440 return new WorkspaceMenu(*screen);
441 } else if (type == "windowmenu") {
442 FbTk::Menu *menu = screen->createMenu("");
443
444 menu->removeAll(); // clear old items
445 menu->disableTitle(); // not titlebar
446 if (screen->windowMenuFilename().empty() ||
447 ! createWindowMenuFromFile(screen->windowMenuFilename(), *menu, true)) {
448 char default_menu[][11] = {
449 "shade",
450 "stick",
451 "maximize",
452 "iconify",
453 "raise",
454 "lower",
455 "sendto",
456 "layer",
457 "extramenus",
458 "separator",
459 "close",
460 0
461 };
462 for (int i=0; i < sizeof(default_menu); ++i)
463 createWindowMenuItem(default_menu[i], "", *menu);
464 }
465 menu->reconfigure(); // update graphics
466 return menu;
445 } 467 }
468
446 return 0; 469 return 0;
447} 470}
448 471
449bool MenuCreator::createWindowMenuItem(const std::string &type, 472bool MenuCreator::createWindowMenuItem(const std::string &type,
450 const std::string &label, 473 const std::string &label,
451 FbTk::Menu &menu, 474 FbTk::Menu &menu) {
452 FluxboxWindow &win) {
453 typedef FbTk::RefCount<FbTk::Command> RefCmd; 475 typedef FbTk::RefCount<FbTk::Command> RefCmd;
454 typedef FbTk::SimpleCommand<FluxboxWindow> WindowCmd;
455 _FB_USES_NLS; 476 _FB_USES_NLS;
456 477
457 if (type == "shade") { 478 if (type == "shade") {
458 RefCmd shade_cmd(new WindowCmd(win, &FluxboxWindow::shade)); 479 RefCmd shade_cmd(new WindowCmd<void>(&FluxboxWindow::shade));
459 menu.insert(label.empty()?_FBTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label.c_str(), shade_cmd); 480 menu.insert(label.empty()?_FBTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label.c_str(), shade_cmd);
460 } else if (type == "maximize") { 481 } else if (type == "maximize") {
461 RefCmd maximize_cmd(new WindowCmd(win, &FluxboxWindow::maximizeFull)); 482 RefCmd maximize_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeFull));
462 RefCmd maximize_vert_cmd(new WindowCmd(win, &FluxboxWindow::maximizeVertical)); 483 RefCmd maximize_vert_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeVertical));
463 RefCmd maximize_horiz_cmd(new WindowCmd(win, &FluxboxWindow::maximizeHorizontal)); 484 RefCmd maximize_horiz_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeHorizontal));
464 FbTk::MultiButtonMenuItem *maximize_item = new FbTk::MultiButtonMenuItem(3, label.empty()?_FBTEXT(Windowmenu, Maximize, "Maximize", "Maximize the window"):label.c_str()); 485 FbTk::MultiButtonMenuItem *maximize_item =
486 new FbTk::MultiButtonMenuItem(3,
487 label.empty()?
488 _FBTEXT(Windowmenu, Maximize,
489 "Maximize", "Maximize the window"):
490 label.c_str());
465 // create maximize item with: 491 // create maximize item with:
466 // button1: Maximize normal 492 // button1: Maximize normal
467 // button2: Maximize Vertical 493 // button2: Maximize Vertical
@@ -471,43 +497,61 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
471 maximize_item->setCommand(3, maximize_horiz_cmd); 497 maximize_item->setCommand(3, maximize_horiz_cmd);
472 menu.insert(maximize_item); 498 menu.insert(maximize_item);
473 } else if (type == "iconify") { 499 } else if (type == "iconify") {
474 RefCmd iconify_cmd(new WindowCmd(win, &FluxboxWindow::iconify)); 500 RefCmd iconify_cmd(new WindowCmd<void>(&FluxboxWindow::iconify));
475 menu.insert(label.empty()?_FBTEXT(Windowmenu, Iconify, "Iconify", "Iconify the window"):label.c_str(), iconify_cmd); 501 menu.insert(label.empty()?_FBTEXT(Windowmenu, Iconify, "Iconify", "Iconify the window"):label.c_str(), iconify_cmd);
476 } else if (type == "close") { 502 } else if (type == "close") {
477 RefCmd close_cmd(new WindowCmd(win, &FluxboxWindow::close)); 503 RefCmd close_cmd(new WindowCmd<void>(&FluxboxWindow::close));
478 menu.insert(label.empty()?_FBTEXT(Windowmenu, Close, "Close", "Close the window"):label.c_str(), close_cmd); 504 menu.insert(label.empty()?_FBTEXT(Windowmenu, Close, "Close", "Close the window"):label.c_str(), close_cmd);
479 } else if (type == "kill" || type == "killwindow") { 505 } else if (type == "kill" || type == "killwindow") {
480 RefCmd kill_cmd(new WindowCmd(win, &FluxboxWindow::kill)); 506 RefCmd kill_cmd(new WindowCmd<void>(&FluxboxWindow::kill));
481 menu.insert(label.empty()?_FBTEXT(Windowmenu, Kill, "Kill", "Kill the window"):label.c_str(), kill_cmd); 507 menu.insert(label.empty()?_FBTEXT(Windowmenu, Kill, "Kill", "Kill the window"):label.c_str(), kill_cmd);
482 } else if (type == "lower") { 508 } else if (type == "lower") {
483 RefCmd lower_cmd(new WindowCmd(win, &FluxboxWindow::lower)); 509 RefCmd lower_cmd(new WindowCmd<void>(&FluxboxWindow::lower));
484 menu.insert(label.empty()?_FBTEXT(Windowmenu, Lower, "Lower", "Lower the window"):label.c_str(), lower_cmd); 510 menu.insert(label.empty()?_FBTEXT(Windowmenu, Lower, "Lower", "Lower the window"):label.c_str(), lower_cmd);
485 } else if (type == "raise") { 511 } else if (type == "raise") {
486 RefCmd raise_cmd(new WindowCmd(win, &FluxboxWindow::raise)); 512 RefCmd raise_cmd(new WindowCmd<void>(&FluxboxWindow::raise));
487 menu.insert(label.empty()?_FBTEXT(Windowmenu, Raise, "Raise", "Raise the window"):label.c_str(), raise_cmd); 513 menu.insert(label.empty()?_FBTEXT(Windowmenu, Raise, "Raise", "Raise the window"):label.c_str(), raise_cmd);
488 } else if (type == "stick") { 514 } else if (type == "stick") {
489 RefCmd stick_cmd(new WindowCmd(win, &FluxboxWindow::stick)); 515 RefCmd stick_cmd(new WindowCmd<void>(&FluxboxWindow::stick));
490 menu.insert(label.empty()?_FBTEXT(Windowmenu, Stick, "Stick", "Stick the window"):label.c_str(), stick_cmd); 516 menu.insert(label.empty()?_FBTEXT(Windowmenu, Stick, "Stick", "Stick the window"):label.c_str(), stick_cmd);
491 } else if (type == "extramenus") { 517 }
492 FluxboxWindow::ExtraMenus::iterator it = win.extraMenus().begin(); 518 else if (type == "extramenus") {
493 FluxboxWindow::ExtraMenus::iterator it_end = win.extraMenus().end(); 519 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
520 BScreen::ExtraMenus::iterator it = screen->extraWindowMenus().begin();
521 BScreen::ExtraMenus::iterator it_end = screen->extraWindowMenus().end();
494 for (; it != it_end; ++it) { 522 for (; it != it_end; ++it) {
495 it->second->disableTitle(); 523 it->second->disableTitle();
496 menu.insert(it->first, it->second); 524 menu.insert(it->first, it->second);
497 } 525 }
498 526
499 } else if (type == "sendto") { 527 } else if (type == "sendto") {
500 menu.insert(label.empty()?_FBTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"):label.c_str(), new SendToMenu(win)); 528 menu.insert(label.empty() ? _FBTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"):
501 } else if (type == "layer") { 529 label.c_str(), new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber())));
530 }else if (type == "layer") {
502 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); 531 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
503 if (screen == 0) 532 if (screen == 0)
504 return false; 533 return false;
505 FbTk::Menu *submenu = new LayerMenu<FluxboxWindow>(screen->menuTheme(), 534
506 screen->imageControl(), 535 class MenuContext: public LayerObject {
507 *screen->layerManager(). 536 public:
508 getLayer(Fluxbox::instance()->getMenuLayer()), 537 void moveToLayer(int layer_number) {
509 &win, 538 if (WindowCmd<void>::window() == 0)
510 false); 539 return;
540 WindowCmd<void>::window()->moveToLayer(layer_number);
541 }
542 int layerNumber() const {
543 if (WindowCmd<void>::window() == 0)
544 return -1;
545 return WindowCmd<void>::window()->layerItem().getLayerNum();
546 }
547 } static context;
548
549 FbTk::Menu *submenu = new LayerMenu(screen->menuTheme(),
550 screen->imageControl(),
551 *screen->layerManager().
552 getLayer(Fluxbox::instance()->getMenuLayer()),
553 &context,
554 false);
511 submenu->disableTitle(); 555 submenu->disableTitle();
512 menu.insert(label.empty()?_FBTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"):label.c_str(), submenu); 556 menu.insert(label.empty()?_FBTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"):label.c_str(), submenu);
513 557