aboutsummaryrefslogtreecommitdiff
path: root/src/Toolbar.cc
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-15 13:24:46 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-15 13:25:05 (GMT)
commit8387742c8860694777f7c2c62da0a90c9e836988 (patch)
treee5bd5a50c3e033ea73a9339474750287d06aeb3f /src/Toolbar.cc
parentb4cd45549013e8b45f95bf3e123cd14684948e91 (diff)
downloadfluxbox-8387742c8860694777f7c2c62da0a90c9e836988.zip
fluxbox-8387742c8860694777f7c2c62da0a90c9e836988.tar.bz2
Refactor menu code: be more explicit and compact
This commit is a preparation step for some menu cleanup ahead. To make it easier to understand which types of MenuItems are added where and when, I converted the overloaded FbTk::Menu::insert() functions into explicit ones (Menu::insertSubmenu(), Menu::insertItem(), etc. ). This makes it possible to just grep for 'insertSubmenu()'. Side effect this commit: it trims down the very verbose creation of menu items in regards to how the labels are created. Minor: FbTk::Menu::shown and FbTk::Menu::s_focused are moved out of the class.
Diffstat (limited to 'src/Toolbar.cc')
-rw-r--r--src/Toolbar.cc41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index c65e9ca..f7b0163 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -271,9 +271,13 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width):
271} 271}
272 272
273Toolbar::~Toolbar() { 273Toolbar::~Toolbar() {
274 if (Fluxbox::instance()->keys()) 274
275 Fluxbox::instance()->keys()->unregisterWindow(window().window()); 275 Keys* keys = Fluxbox::instance()->keys();
276 if (keys)
277 keys->unregisterWindow(window().window());
278
276 FbTk::EventManager::instance()->remove(window()); 279 FbTk::EventManager::instance()->remove(window());
280
277 // remove menu items before we delete tools so we dont end up 281 // remove menu items before we delete tools so we dont end up
278 // with dangling pointers to old submenu items (internal menus) 282 // with dangling pointers to old submenu items (internal menus)
279 // from the tools 283 // from the tools
@@ -786,11 +790,11 @@ void Toolbar::setupMenus(bool skip_new_placement) {
786 visible_macro->add(reconfig_toolbar); 790 visible_macro->add(reconfig_toolbar);
787 visible_macro->add(save_resources); 791 visible_macro->add(save_resources);
788 RefCommand toggle_visible_cmd(visible_macro); 792 RefCommand toggle_visible_cmd(visible_macro);
789 menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, 793 menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible,
790 "Visible", "Whether this item is visible"), 794 "Visible", "Whether this item is visible"),
791 m_rc_visible, toggle_visible_cmd)); 795 m_rc_visible, toggle_visible_cmd));
792 796
793 menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, 797 menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide,
794 "Auto hide", "Toggle auto hide of toolbar"), 798 "Auto hide", "Toggle auto hide of toolbar"),
795 m_rc_auto_hide, 799 m_rc_auto_hide,
796 reconfig_toolbar_and_save_resource)); 800 reconfig_toolbar_and_save_resource));
@@ -804,25 +808,24 @@ void Toolbar::setupMenus(bool skip_new_placement) {
804 808
805 809
806 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); 810 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource);
807 menu().insert(toolbar_menuitem); 811 menu().insertItem(toolbar_menuitem);
808 812
809 menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, 813 menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,
810 "Maximize Over", 814 "Maximize Over",
811 "Maximize over this thing when maximizing"), 815 "Maximize over this thing when maximizing"),
812 m_rc_maximize_over, 816 m_rc_maximize_over,
813 reconfig_toolbar_and_save_resource)); 817 reconfig_toolbar_and_save_resource));
814 menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); 818 menu().insertSubmenu(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu());
815#ifdef XINERAMA 819#ifdef XINERAMA
816 if (screen().hasXinerama()) { 820 if (screen().hasXinerama()) {
817 menu().insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), 821
818 m_xineramaheadmenu = 822 m_xineramaheadmenu = new XineramaHeadMenu<Toolbar>(screen().menuTheme(),
819 new XineramaHeadMenu<Toolbar>(screen().menuTheme(), 823 screen(),
820 screen(), 824 screen().imageControl(),
821 screen().imageControl(), 825 *screen().layerManager().getLayer(::ResourceLayer::MENU),
822 *screen().layerManager().getLayer(::ResourceLayer::MENU), 826 *this,
823 *this, 827 _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", "Title of toolbar on head menu"));
824 _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", 828 menu().insertSubmenu(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), m_xineramaheadmenu);
825 "Title of toolbar on head menu")));
826 } 829 }
827#endif // XINERAMA 830#endif // XINERAMA
828 831
@@ -860,12 +863,12 @@ void Toolbar::setupMenus(bool skip_new_placement) {
860 placementMenu().insert(p.label); 863 placementMenu().insert(p.label);
861 placementMenu().setItemEnabled(i, false); 864 placementMenu().setItemEnabled(i, false);
862 } else 865 } else
863 placementMenu().insert(new PlaceToolbarMenuItem(p.label, *this, 866 placementMenu().insertItem(new PlaceToolbarMenuItem(p.label, *this,
864 p.placement)); 867 p.placement));
865 } 868 }
866 } 869 }
867 870
868 menu().insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); 871 menu().insertSubmenu(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu());
869 placementMenu().updateMenu(); 872 placementMenu().updateMenu();
870 873
871 874
@@ -882,7 +885,7 @@ void Toolbar::setupMenus(bool skip_new_placement) {
882 RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd); 885 RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd);
883 alpha_menuitem->setCommand(set_alpha_cmd); 886 alpha_menuitem->setCommand(set_alpha_cmd);
884 887
885 menu().insert(alpha_menuitem); 888 menu().insertItem(alpha_menuitem);
886 menu().updateMenu(); 889 menu().updateMenu();
887} 890}
888 891