reuse some menu pointers instead of using delete/new
This commit is contained in:
parent
85d8ac7549
commit
72a45fae3c
6 changed files with 36 additions and 59 deletions
|
@ -76,13 +76,8 @@ void showMenu(const BScreen &screen, FbTk::Menu &menu) {
|
||||||
// special case for root menu
|
// special case for root menu
|
||||||
if (&menu == &screen.rootMenu()) {
|
if (&menu == &screen.rootMenu()) {
|
||||||
Fluxbox* fb = Fluxbox::instance();
|
Fluxbox* fb = Fluxbox::instance();
|
||||||
if(fb->menuTimestampsChanged()) {
|
if(fb->menuTimestampsChanged())
|
||||||
// we dont show the menu here because fluxbox
|
|
||||||
// will bring up the rootmenu after the timed
|
|
||||||
// reread of the menu
|
|
||||||
fb->rereadMenu();
|
fb->rereadMenu();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window root_ret; // not used
|
Window root_ret; // not used
|
||||||
|
@ -335,8 +330,8 @@ void ShowClientMenuCmd::execute() {
|
||||||
m_list.push_back(static_cast<FluxboxWindow *>(*it));
|
m_list.push_back(static_cast<FluxboxWindow *>(*it));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_menu = new ClientMenu(*screen, m_list, 0);
|
m_menu.reset(new ClientMenu(*screen, m_list, 0));
|
||||||
::showMenu(*screen, **m_menu);
|
::showMenu(*screen, *m_menu.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void);
|
REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void);
|
||||||
|
@ -347,11 +342,15 @@ void ShowCustomMenuCmd::execute() {
|
||||||
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
||||||
if (screen == 0)
|
if (screen == 0)
|
||||||
return;
|
return;
|
||||||
m_menu = MenuCreator::createFromFile(custom_menu_file,
|
|
||||||
screen->screenNumber());
|
if (m_menu.get()) {
|
||||||
if (!m_menu.get())
|
m_menu->removeAll();
|
||||||
return;
|
m_menu->setLabel("");
|
||||||
::showMenu(*screen, **m_menu);
|
} else
|
||||||
|
m_menu.reset(screen->createMenu(""));
|
||||||
|
|
||||||
|
MenuCreator::createFromFile(custom_menu_file, *m_menu.get());
|
||||||
|
::showMenu(*screen, *m_menu.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void);
|
REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void);
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
#define FBCOMMANDS_HH
|
#define FBCOMMANDS_HH
|
||||||
|
|
||||||
#include "FbTk/Command.hh"
|
#include "FbTk/Command.hh"
|
||||||
#include "FbTk/RefCount.hh"
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "ClientMenu.hh"
|
#include "ClientMenu.hh"
|
||||||
#include "ClientPattern.hh"
|
#include "ClientPattern.hh"
|
||||||
|
@ -124,7 +125,7 @@ private:
|
||||||
const int m_option;
|
const int m_option;
|
||||||
const ClientPattern m_pat;
|
const ClientPattern m_pat;
|
||||||
std::list<FluxboxWindow *> m_list;
|
std::list<FluxboxWindow *> m_list;
|
||||||
FbTk::RefCount<ClientMenu> m_menu;
|
std::auto_ptr<ClientMenu> m_menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShowCustomMenuCmd: public FbTk::Command<void> {
|
class ShowCustomMenuCmd: public FbTk::Command<void> {
|
||||||
|
@ -133,7 +134,7 @@ public:
|
||||||
void execute();
|
void execute();
|
||||||
private:
|
private:
|
||||||
std::string custom_menu_file;
|
std::string custom_menu_file;
|
||||||
FbTk::RefCount<FbTk::Menu> m_menu;
|
std::auto_ptr<FbTk::Menu> m_menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShowRootMenuCmd: public FbTk::Command<void> {
|
class ShowRootMenuCmd: public FbTk::Command<void> {
|
||||||
|
|
|
@ -255,13 +255,13 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConver
|
||||||
if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
|
if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
|
||||||
(filelist[file_index][0] != '.') &&
|
(filelist[file_index][0] != '.') &&
|
||||||
(thisfile[thisfile.length() - 1] != '~')) {
|
(thisfile[thisfile.length() - 1] != '~')) {
|
||||||
MenuCreator::createFromFile(thisfile, menu);
|
MenuCreator::createFromFile(thisfile, menu, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// inject this file into the current menu
|
// inject this file into the current menu
|
||||||
MenuCreator::createFromFile(newfile, menu);
|
MenuCreator::createFromFile(newfile, menu, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_counter--;
|
safe_counter--;
|
||||||
|
@ -390,33 +390,8 @@ FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number) {
|
|
||||||
string real_filename = FbTk::StringUtil::expandFilename(filename);
|
|
||||||
Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
|
|
||||||
|
|
||||||
FbMenuParser parser(real_filename);
|
|
||||||
if (!parser.isLoaded())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
startFile();
|
|
||||||
string label;
|
|
||||||
if (!getStart(parser, label, m_stringconvertor)) {
|
|
||||||
endFile();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FbTk::Menu *menu = createMenu(label, screen_number);
|
|
||||||
if (menu != 0)
|
|
||||||
parseMenu(parser, *menu, m_stringconvertor);
|
|
||||||
|
|
||||||
endFile();
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool MenuCreator::createFromFile(const string &filename,
|
bool MenuCreator::createFromFile(const string &filename,
|
||||||
FbTk::Menu &inject_into) {
|
FbTk::Menu &inject_into, bool begin) {
|
||||||
string real_filename = FbTk::StringUtil::expandFilename(filename);
|
string real_filename = FbTk::StringUtil::expandFilename(filename);
|
||||||
|
|
||||||
FbMenuParser parser(real_filename);
|
FbMenuParser parser(real_filename);
|
||||||
|
@ -424,6 +399,14 @@ bool MenuCreator::createFromFile(const string &filename,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
startFile();
|
startFile();
|
||||||
|
if (begin) {
|
||||||
|
string label;
|
||||||
|
if (!getStart(parser, label, m_stringconvertor)) {
|
||||||
|
endFile();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inject_into.setLabel(label);
|
||||||
|
}
|
||||||
|
|
||||||
// save menu filename, so we can check if it changes
|
// save menu filename, so we can check if it changes
|
||||||
Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
|
Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
|
||||||
|
@ -467,7 +450,7 @@ FbTk::Menu *MenuCreator::createMenuType(const string &type, int screen_num) {
|
||||||
} else if (type == "workspacemenu") {
|
} else if (type == "workspacemenu") {
|
||||||
return new WorkspaceMenu(*screen);
|
return new WorkspaceMenu(*screen);
|
||||||
} else if (type == "windowmenu") {
|
} else if (type == "windowmenu") {
|
||||||
FbTk::Menu *menu = screen->createMenu("");
|
FbTk::Menu *menu = createMenu("", screen_num);
|
||||||
|
|
||||||
menu->disableTitle(); // not titlebar
|
menu->disableTitle(); // not titlebar
|
||||||
if (screen->windowMenuFilename().empty() ||
|
if (screen->windowMenuFilename().empty() ||
|
||||||
|
|
|
@ -36,9 +36,9 @@ class FluxboxWindow;
|
||||||
class MenuCreator {
|
class MenuCreator {
|
||||||
public:
|
public:
|
||||||
static FbTk::Menu *createMenu(const std::string &label, int screen_num);
|
static FbTk::Menu *createMenu(const std::string &label, int screen_num);
|
||||||
static FbTk::Menu *createFromFile(const std::string &filename, int screen_num);
|
|
||||||
static FbTk::Menu *createMenuType(const std::string &label, int screen_num);
|
static FbTk::Menu *createMenuType(const std::string &label, int screen_num);
|
||||||
static bool createFromFile(const std::string &filename, FbTk::Menu &inject_into);
|
static bool createFromFile(const std::string &filename,
|
||||||
|
FbTk::Menu &inject_into, bool begin = true);
|
||||||
static bool createWindowMenuFromFile(const std::string &filename, FbTk::Menu &inject_into);
|
static bool createWindowMenuFromFile(const std::string &filename, FbTk::Menu &inject_into);
|
||||||
static bool createWindowMenuItem(const std::string &type, const std::string &label,
|
static bool createWindowMenuItem(const std::string &type, const std::string &label,
|
||||||
FbTk::Menu &inject_into);
|
FbTk::Menu &inject_into);
|
||||||
|
|
|
@ -1498,21 +1498,18 @@ void BScreen::initMenus() {
|
||||||
void BScreen::initMenu() {
|
void BScreen::initMenu() {
|
||||||
|
|
||||||
if (m_rootmenu.get()) {
|
if (m_rootmenu.get()) {
|
||||||
while (m_rootmenu->numberOfItems())
|
m_rootmenu->removeAll();
|
||||||
m_rootmenu->remove(0);
|
m_rootmenu->setLabel("");
|
||||||
} else
|
} else
|
||||||
m_rootmenu.reset(createMenu(""));
|
m_rootmenu.reset(createMenu(""));
|
||||||
|
|
||||||
Fluxbox * const fb = Fluxbox::instance();
|
Fluxbox * const fb = Fluxbox::instance();
|
||||||
if (!fb->getMenuFilename().empty()) {
|
if (!fb->getMenuFilename().empty())
|
||||||
m_rootmenu.reset(MenuCreator::createFromFile(fb->getMenuFilename(),
|
MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu);
|
||||||
screenNumber()));
|
|
||||||
|
|
||||||
}
|
if (m_rootmenu->numberOfItems() == 0) {
|
||||||
|
|
||||||
if (m_rootmenu.get() == 0 || m_rootmenu->numberOfItems() == 0) {
|
|
||||||
_FB_USES_NLS;
|
_FB_USES_NLS;
|
||||||
m_rootmenu.reset(createMenu(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu")));
|
m_rootmenu->setLabel(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu"));
|
||||||
FbTk::RefCount<FbTk::Command<void> > restart_fb(FbTk::CommandParser<void>::instance().parse("restart"));
|
FbTk::RefCount<FbTk::Command<void> > restart_fb(FbTk::CommandParser<void>::instance().parse("restart"));
|
||||||
FbTk::RefCount<FbTk::Command<void> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit"));
|
FbTk::RefCount<FbTk::Command<void> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit"));
|
||||||
FbTk::RefCount<FbTk::Command<void> > execute_xterm(FbTk::CommandParser<void>::instance().parse("exec xterm"));
|
FbTk::RefCount<FbTk::Command<void> > execute_xterm(FbTk::CommandParser<void>::instance().parse("exec xterm"));
|
||||||
|
|
|
@ -1490,9 +1490,6 @@ void Fluxbox::rereadMenu() {
|
||||||
for_each(m_screen_list.begin(),
|
for_each(m_screen_list.begin(),
|
||||||
m_screen_list.end(),
|
m_screen_list.end(),
|
||||||
mem_fun(&BScreen::rereadMenu));
|
mem_fun(&BScreen::rereadMenu));
|
||||||
|
|
||||||
FbCommands::ShowRootMenuCmd showcmd;
|
|
||||||
showcmd.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fluxbox::saveMenuFilename(const char *filename) {
|
void Fluxbox::saveMenuFilename(const char *filename) {
|
||||||
|
|
Loading…
Reference in a new issue