Refactor: move some menu-creation functions to MenuCreator

Another patch to trim down the code that needs to be part of BScreen
This commit is contained in:
Mathias Gumz 2015-01-16 08:39:05 +01:00
parent b495878065
commit 6d5781ce71
7 changed files with 48 additions and 65 deletions

View file

@ -20,12 +20,14 @@
// DEALINGS IN THE SOFTWARE.
#include "ConfigMenu.hh"
#include "MenuCreator.hh"
#include "Screen.hh"
#include "fluxbox.hh"
#include "FocusModelMenuItem.hh"
#include "ScreenPlacement.hh"
#include "FbMenu.hh"
#include "ToggleMenu.hh"
#include "FbTk/Menu.hh"
#include "FbTk/BoolMenuItem.hh"
#include "FbTk/IntMenuItem.hh"
@ -67,19 +69,30 @@ private:
typedef FbTk::RefCount<FbTk::Command<void> > _Cmd;
enum {
L_ALPHA = 0,
L_PSEUDO_TRANS,
L_FOCUS_ALPHA,
L_UNFOCUS_ALPHA,
L_MENU_ALPHA,
};
// NOTE: might also be placed into MenuCreator; for now it ends up here
// because it's just used here
FbMenu *createToggleMenu(const std::string &label, BScreen& screen) {
FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU);
FbMenu *menu = new ToggleMenu(screen.menuTheme(), screen.imageControl(), *layer);
if (!label.empty())
menu->setLabel(label);
return menu;
}
void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf) {
#ifdef HAVE_XRENDER
_FB_USES_NLS;
enum {
L_ALPHA = 0,
L_PSEUDO_TRANS,
L_FOCUS_ALPHA,
L_UNFOCUS_ALPHA,
L_MENU_ALPHA,
};
static const FbTk::FbString _labels[] = {
_FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"),
_FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"),
@ -90,7 +103,7 @@ void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_
FbTk::FbString label = _labels[L_ALPHA];
FbTk::Menu* menu = sh.screen.createMenu(label);
FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen);
if (FbTk::Transparent::haveComposite(true)) {
static FbTk::SimpleAccessor<bool> s_pseudo = Fluxbox::instance()->getPseudoTrans();
@ -131,7 +144,7 @@ void setupFocusMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save_rc
// we don't set this to internal menu so will
// be deleted toghether with the parent
FbTk::FbString label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows");
FbMenu* fm = sh.screen.createMenu(label);
FbMenu* fm = MenuCreator::createMenu(label, sh.screen);
#define _FOCUSITEM(a, b, c, d, e) \
fm->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), sh.screen.focusControl(), \
@ -197,7 +210,7 @@ void setupMaximizeMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save
FbTk::FbString label = _FB_XTEXT(Configmenu, MaxMenu,
"Maximize Options", "heading for maximization options");
FbTk::Menu* mm = sh.screen.createMenu(label);
FbTk::Menu* mm = MenuCreator::createMenu(label, sh.screen);
_BOOLITEM(*mm, Configmenu, FullMax,
"Full Maximization", "Maximise over slit, toolbar, etc",
@ -224,8 +237,8 @@ void setupTabMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_re
FbTk::FbString label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options");
// TODO: main-category is 'Menu'?? should be 'ConfigMenu'???
FbTk::FbString p_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu");
FbTk::Menu* menu = sh.screen.createMenu(label);
FbTk::Menu* p_menu = sh.screen.createToggleMenu(p_label);
FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen);
FbTk::Menu* p_menu = createToggleMenu(p_label, sh.screen);
menu->insertSubmenu(p_label, p_menu);

View file

@ -323,7 +323,7 @@ void ShowCustomMenuCmd::execute() {
return;
if (!m_menu.get() || screen->screenNumber() != m_menu->screenNumber()) {
m_menu.reset(screen->createMenu(""));
m_menu.reset(MenuCreator::createMenu("", *screen));
m_menu->setReloadHelper(new FbTk::AutoReloadHelper());
m_menu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<ShowCustomMenuCmd>(*this, &ShowCustomMenuCmd::reload)));
m_menu->reloadHelper()->setMainFile(custom_menu_file);

View file

@ -482,20 +482,24 @@ bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelc
} // end of anonymous namespace
FbMenu *MenuCreator::createMenu(const string &label, int screen_number) {
BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
if (screen == 0)
return 0;
FbMenu *menu = new FbMenu(screen->menuTheme(),
screen->imageControl(),
*screen->layerManager().getLayer(ResourceLayer::MENU));
FbMenu* MenuCreator::createMenu(const std::string& label, BScreen& screen) {
FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU);
FbMenu *menu = new FbMenu(screen.menuTheme(), screen.imageControl(), *layer);
if (!label.empty())
menu->setLabel(label);
return menu;
}
FbMenu *MenuCreator::createMenu(const string &label, int screen_number) {
BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
if (screen == 0)
return 0;
return MenuCreator::createMenu(label, *screen);
}
bool MenuCreator::createFromFile(const string &filename,
FbTk::Menu &inject_into,
AutoReloadHelper *reloader, bool begin) {

View file

@ -34,11 +34,13 @@ class Menu;
class FbMenu;
class FluxboxWindow;
class BScreen;
namespace MenuCreator {
FbMenu *createMenu(const std::string &label, int screen_num);
FbMenu *createMenuType(const std::string &label, int screen_num);
FbMenu* createMenu(const std::string& label, BScreen& screen);
FbMenu* createMenu(const std::string& label, int screen_num);
FbMenu* createMenuType(const std::string &label, int screen_num);
bool createFromFile(const std::string &filename,
FbTk::Menu &inject_into,
FbTk::AutoReloadHelper *reloader = NULL,

View file

@ -27,6 +27,7 @@
#include "Window.hh"
#include "WinClient.hh"
#include "FbMenu.hh"
#include "MenuCreator.hh"
#include "FbCommands.hh"
#include "fluxbox.hh"
#include "Layer.hh"
@ -305,7 +306,7 @@ private:
FbTk::Menu *createRememberMenu(BScreen &screen) {
// each fluxboxwindow has its own windowmenu
// so we also create a remember menu just for it...
FbTk::Menu *menu = screen.createMenu("Remember");
FbTk::Menu *menu = MenuCreator::createMenu("Remember", screen);
// if enabled, then we want this to be a unavailable menu
/*

View file

@ -359,17 +359,17 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
m_current_workspace = m_workspaces_list.front();
m_windowmenu.reset(createMenu(""));
m_windowmenu.reset(MenuCreator::createMenu("", *this));
m_windowmenu->setInternalMenu();
m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper());
m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadWindowMenu)));
m_rootmenu.reset(createMenu(""));
m_rootmenu.reset(MenuCreator::createMenu("", *this));
m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper());
m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<BScreen>(*this, &BScreen::rereadMenu)));
m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration,
"Configuration", "Title of configuration menu")));
m_configmenu.reset(MenuCreator::createMenu(_FB_XTEXT(Menu, Configuration,
"Configuration", "Title of configuration menu"), *this));
setupConfigmenu(*m_configmenu.get());
m_configmenu->setInternalMenu();
@ -745,24 +745,6 @@ void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) {
}
FbMenu *BScreen::createMenu(const string &label) {
FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU);
FbMenu *menu = new FbMenu(menuTheme(), imageControl(), *layer);
if (!label.empty())
menu->setLabel(label);
return menu;
}
FbMenu *BScreen::createToggleMenu(const string &label) {
FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU);
FbMenu *menu = new ToggleMenu(menuTheme(), imageControl(), *layer);
if (!label.empty())
menu->setLabel(label);
return menu;
}
void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) {
menu->setInternalMenu();
menu->disableTitle();

View file

@ -43,13 +43,7 @@
#include "FocusControl.hh"
#include <X11/Xresource.h>
#ifdef HAVE_CSTDIO
#include <cstdio>
#else
#include <stdio.h>
#endif
#include <cstdio>
#include <list>
#include <vector>
#include <fstream>
@ -233,19 +227,6 @@ public:
bool isCycling() const { return m_cycling; }
/**
* Creates an empty menu with specified label
* @param label for the menu
* @return created menu
*/
FbMenu *createMenu(const std::string &label);
/**
* Creates an empty toggle menu with a specific label
* @param label
* @return created menu
*/
FbMenu *createToggleMenu(const std::string &label);
/**
* For extras to add menus.
* These menus will be marked internal,