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
|
||||
if (&menu == &screen.rootMenu()) {
|
||||
Fluxbox* fb = Fluxbox::instance();
|
||||
if(fb->menuTimestampsChanged()) {
|
||||
// we dont show the menu here because fluxbox
|
||||
// will bring up the rootmenu after the timed
|
||||
// reread of the menu
|
||||
if(fb->menuTimestampsChanged())
|
||||
fb->rereadMenu();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Window root_ret; // not used
|
||||
|
@ -335,8 +330,8 @@ void ShowClientMenuCmd::execute() {
|
|||
m_list.push_back(static_cast<FluxboxWindow *>(*it));
|
||||
}
|
||||
|
||||
m_menu = new ClientMenu(*screen, m_list, 0);
|
||||
::showMenu(*screen, **m_menu);
|
||||
m_menu.reset(new ClientMenu(*screen, m_list, 0));
|
||||
::showMenu(*screen, *m_menu.get());
|
||||
}
|
||||
|
||||
REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void);
|
||||
|
@ -347,11 +342,15 @@ void ShowCustomMenuCmd::execute() {
|
|||
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
||||
if (screen == 0)
|
||||
return;
|
||||
m_menu = MenuCreator::createFromFile(custom_menu_file,
|
||||
screen->screenNumber());
|
||||
if (!m_menu.get())
|
||||
return;
|
||||
::showMenu(*screen, **m_menu);
|
||||
|
||||
if (m_menu.get()) {
|
||||
m_menu->removeAll();
|
||||
m_menu->setLabel("");
|
||||
} 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);
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
#define FBCOMMANDS_HH
|
||||
|
||||
#include "FbTk/Command.hh"
|
||||
#include "FbTk/RefCount.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ClientMenu.hh"
|
||||
#include "ClientPattern.hh"
|
||||
|
@ -124,7 +125,7 @@ private:
|
|||
const int m_option;
|
||||
const ClientPattern m_pat;
|
||||
std::list<FluxboxWindow *> m_list;
|
||||
FbTk::RefCount<ClientMenu> m_menu;
|
||||
std::auto_ptr<ClientMenu> m_menu;
|
||||
};
|
||||
|
||||
class ShowCustomMenuCmd: public FbTk::Command<void> {
|
||||
|
@ -133,7 +134,7 @@ public:
|
|||
void execute();
|
||||
private:
|
||||
std::string custom_menu_file;
|
||||
FbTk::RefCount<FbTk::Menu> m_menu;
|
||||
std::auto_ptr<FbTk::Menu> m_menu;
|
||||
};
|
||||
|
||||
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()) &&
|
||||
(filelist[file_index][0] != '.') &&
|
||||
(thisfile[thisfile.length() - 1] != '~')) {
|
||||
MenuCreator::createFromFile(thisfile, menu);
|
||||
MenuCreator::createFromFile(thisfile, menu, false);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// inject this file into the current menu
|
||||
MenuCreator::createFromFile(newfile, menu);
|
||||
MenuCreator::createFromFile(newfile, menu, false);
|
||||
}
|
||||
|
||||
safe_counter--;
|
||||
|
@ -390,33 +390,8 @@ FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) {
|
|||
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,
|
||||
FbTk::Menu &inject_into) {
|
||||
FbTk::Menu &inject_into, bool begin) {
|
||||
string real_filename = FbTk::StringUtil::expandFilename(filename);
|
||||
|
||||
FbMenuParser parser(real_filename);
|
||||
|
@ -424,6 +399,14 @@ bool MenuCreator::createFromFile(const string &filename,
|
|||
return false;
|
||||
|
||||
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
|
||||
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") {
|
||||
return new WorkspaceMenu(*screen);
|
||||
} else if (type == "windowmenu") {
|
||||
FbTk::Menu *menu = screen->createMenu("");
|
||||
FbTk::Menu *menu = createMenu("", screen_num);
|
||||
|
||||
menu->disableTitle(); // not titlebar
|
||||
if (screen->windowMenuFilename().empty() ||
|
||||
|
|
|
@ -36,9 +36,9 @@ class FluxboxWindow;
|
|||
class MenuCreator {
|
||||
public:
|
||||
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 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 createWindowMenuItem(const std::string &type, const std::string &label,
|
||||
FbTk::Menu &inject_into);
|
||||
|
|
|
@ -1498,21 +1498,18 @@ void BScreen::initMenus() {
|
|||
void BScreen::initMenu() {
|
||||
|
||||
if (m_rootmenu.get()) {
|
||||
while (m_rootmenu->numberOfItems())
|
||||
m_rootmenu->remove(0);
|
||||
m_rootmenu->removeAll();
|
||||
m_rootmenu->setLabel("");
|
||||
} else
|
||||
m_rootmenu.reset(createMenu(""));
|
||||
|
||||
Fluxbox * const fb = Fluxbox::instance();
|
||||
if (!fb->getMenuFilename().empty()) {
|
||||
m_rootmenu.reset(MenuCreator::createFromFile(fb->getMenuFilename(),
|
||||
screenNumber()));
|
||||
if (!fb->getMenuFilename().empty())
|
||||
MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu);
|
||||
|
||||
}
|
||||
|
||||
if (m_rootmenu.get() == 0 || m_rootmenu->numberOfItems() == 0) {
|
||||
if (m_rootmenu->numberOfItems() == 0) {
|
||||
_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> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit"));
|
||||
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(),
|
||||
m_screen_list.end(),
|
||||
mem_fun(&BScreen::rereadMenu));
|
||||
|
||||
FbCommands::ShowRootMenuCmd showcmd;
|
||||
showcmd.execute();
|
||||
}
|
||||
|
||||
void Fluxbox::saveMenuFilename(const char *filename) {
|
||||
|
|
Loading…
Reference in a new issue