aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-05-11 17:17:21 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-05-11 17:17:21 (GMT)
commit72a45fae3c39323206e7d19913bb3ab17a691691 (patch)
treef920a884d39c8d5d161e0fa7a3c8a6296f7a3d71 /src
parent85d8ac754974aae0a513b585e4f1810007cb157c (diff)
downloadfluxbox_paul-72a45fae3c39323206e7d19913bb3ab17a691691.zip
fluxbox_paul-72a45fae3c39323206e7d19913bb3ab17a691691.tar.bz2
reuse some menu pointers instead of using delete/new
Diffstat (limited to 'src')
-rw-r--r--src/FbCommands.cc25
-rw-r--r--src/FbCommands.hh7
-rw-r--r--src/MenuCreator.cc41
-rw-r--r--src/MenuCreator.hh4
-rw-r--r--src/Screen.cc15
-rw-r--r--src/fluxbox.cc3
6 files changed, 36 insertions, 59 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index 91490d3..4eabae2 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -76,13 +76,8 @@ void showMenu(const BScreen &screen, FbTk::Menu &menu) {
76 // special case for root menu 76 // special case for root menu
77 if (&menu == &screen.rootMenu()) { 77 if (&menu == &screen.rootMenu()) {
78 Fluxbox* fb = Fluxbox::instance(); 78 Fluxbox* fb = Fluxbox::instance();
79 if(fb->menuTimestampsChanged()) { 79 if(fb->menuTimestampsChanged())
80 // we dont show the menu here because fluxbox
81 // will bring up the rootmenu after the timed
82 // reread of the menu
83 fb->rereadMenu(); 80 fb->rereadMenu();
84 return;
85 }
86 } 81 }
87 82
88 Window root_ret; // not used 83 Window root_ret; // not used
@@ -335,8 +330,8 @@ void ShowClientMenuCmd::execute() {
335 m_list.push_back(static_cast<FluxboxWindow *>(*it)); 330 m_list.push_back(static_cast<FluxboxWindow *>(*it));
336 } 331 }
337 332
338 m_menu = new ClientMenu(*screen, m_list, 0); 333 m_menu.reset(new ClientMenu(*screen, m_list, 0));
339 ::showMenu(*screen, **m_menu); 334 ::showMenu(*screen, *m_menu.get());
340} 335}
341 336
342REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void); 337REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd, void);
@@ -347,11 +342,15 @@ void ShowCustomMenuCmd::execute() {
347 BScreen *screen = Fluxbox::instance()->mouseScreen(); 342 BScreen *screen = Fluxbox::instance()->mouseScreen();
348 if (screen == 0) 343 if (screen == 0)
349 return; 344 return;
350 m_menu = MenuCreator::createFromFile(custom_menu_file, 345
351 screen->screenNumber()); 346 if (m_menu.get()) {
352 if (!m_menu.get()) 347 m_menu->removeAll();
353 return; 348 m_menu->setLabel("");
354 ::showMenu(*screen, **m_menu); 349 } else
350 m_menu.reset(screen->createMenu(""));
351
352 MenuCreator::createFromFile(custom_menu_file, *m_menu.get());
353 ::showMenu(*screen, *m_menu.get());
355} 354}
356 355
357REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void); 356REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void);
diff --git a/src/FbCommands.hh b/src/FbCommands.hh
index f9c33af..3ad45c4 100644
--- a/src/FbCommands.hh
+++ b/src/FbCommands.hh
@@ -25,7 +25,8 @@
25#define FBCOMMANDS_HH 25#define FBCOMMANDS_HH
26 26
27#include "FbTk/Command.hh" 27#include "FbTk/Command.hh"
28#include "FbTk/RefCount.hh" 28
29#include <memory>
29 30
30#include "ClientMenu.hh" 31#include "ClientMenu.hh"
31#include "ClientPattern.hh" 32#include "ClientPattern.hh"
@@ -124,7 +125,7 @@ private:
124 const int m_option; 125 const int m_option;
125 const ClientPattern m_pat; 126 const ClientPattern m_pat;
126 std::list<FluxboxWindow *> m_list; 127 std::list<FluxboxWindow *> m_list;
127 FbTk::RefCount<ClientMenu> m_menu; 128 std::auto_ptr<ClientMenu> m_menu;
128}; 129};
129 130
130class ShowCustomMenuCmd: public FbTk::Command<void> { 131class ShowCustomMenuCmd: public FbTk::Command<void> {
@@ -133,7 +134,7 @@ public:
133 void execute(); 134 void execute();
134private: 135private:
135 std::string custom_menu_file; 136 std::string custom_menu_file;
136 FbTk::RefCount<FbTk::Menu> m_menu; 137 std::auto_ptr<FbTk::Menu> m_menu;
137}; 138};
138 139
139class ShowRootMenuCmd: public FbTk::Command<void> { 140class ShowRootMenuCmd: public FbTk::Command<void> {
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index 3f184f7..25f99ca 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -255,13 +255,13 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConver
255 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) && 255 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
256 (filelist[file_index][0] != '.') && 256 (filelist[file_index][0] != '.') &&
257 (thisfile[thisfile.length() - 1] != '~')) { 257 (thisfile[thisfile.length() - 1] != '~')) {
258 MenuCreator::createFromFile(thisfile, menu); 258 MenuCreator::createFromFile(thisfile, menu, false);
259 } 259 }
260 } 260 }
261 261
262 } else { 262 } else {
263 // inject this file into the current menu 263 // inject this file into the current menu
264 MenuCreator::createFromFile(newfile, menu); 264 MenuCreator::createFromFile(newfile, menu, false);
265 } 265 }
266 266
267 safe_counter--; 267 safe_counter--;
@@ -390,33 +390,8 @@ FbTk::Menu *MenuCreator::createMenu(const string &label, int screen_number) {
390 return menu; 390 return menu;
391} 391}
392 392
393FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_number) {
394 string real_filename = FbTk::StringUtil::expandFilename(filename);
395 Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
396
397 FbMenuParser parser(real_filename);
398 if (!parser.isLoaded())
399 return 0;
400
401 startFile();
402 string label;
403 if (!getStart(parser, label, m_stringconvertor)) {
404 endFile();
405 return 0;
406 }
407
408 FbTk::Menu *menu = createMenu(label, screen_number);
409 if (menu != 0)
410 parseMenu(parser, *menu, m_stringconvertor);
411
412 endFile();
413
414 return menu;
415}
416
417
418bool MenuCreator::createFromFile(const string &filename, 393bool MenuCreator::createFromFile(const string &filename,
419 FbTk::Menu &inject_into) { 394 FbTk::Menu &inject_into, bool begin) {
420 string real_filename = FbTk::StringUtil::expandFilename(filename); 395 string real_filename = FbTk::StringUtil::expandFilename(filename);
421 396
422 FbMenuParser parser(real_filename); 397 FbMenuParser parser(real_filename);
@@ -424,6 +399,14 @@ bool MenuCreator::createFromFile(const string &filename,
424 return false; 399 return false;
425 400
426 startFile(); 401 startFile();
402 if (begin) {
403 string label;
404 if (!getStart(parser, label, m_stringconvertor)) {
405 endFile();
406 return false;
407 }
408 inject_into.setLabel(label);
409 }
427 410
428 // save menu filename, so we can check if it changes 411 // save menu filename, so we can check if it changes
429 Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); 412 Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
@@ -467,7 +450,7 @@ FbTk::Menu *MenuCreator::createMenuType(const string &type, int screen_num) {
467 } else if (type == "workspacemenu") { 450 } else if (type == "workspacemenu") {
468 return new WorkspaceMenu(*screen); 451 return new WorkspaceMenu(*screen);
469 } else if (type == "windowmenu") { 452 } else if (type == "windowmenu") {
470 FbTk::Menu *menu = screen->createMenu(""); 453 FbTk::Menu *menu = createMenu("", screen_num);
471 454
472 menu->disableTitle(); // not titlebar 455 menu->disableTitle(); // not titlebar
473 if (screen->windowMenuFilename().empty() || 456 if (screen->windowMenuFilename().empty() ||
diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh
index 4494dc7..660d097 100644
--- a/src/MenuCreator.hh
+++ b/src/MenuCreator.hh
@@ -36,9 +36,9 @@ class FluxboxWindow;
36class MenuCreator { 36class MenuCreator {
37public: 37public:
38 static FbTk::Menu *createMenu(const std::string &label, int screen_num); 38 static FbTk::Menu *createMenu(const std::string &label, int screen_num);
39 static FbTk::Menu *createFromFile(const std::string &filename, int screen_num);
40 static FbTk::Menu *createMenuType(const std::string &label, int screen_num); 39 static FbTk::Menu *createMenuType(const std::string &label, int screen_num);
41 static bool createFromFile(const std::string &filename, FbTk::Menu &inject_into); 40 static bool createFromFile(const std::string &filename,
41 FbTk::Menu &inject_into, bool begin = true);
42 static bool createWindowMenuFromFile(const std::string &filename, FbTk::Menu &inject_into); 42 static bool createWindowMenuFromFile(const std::string &filename, FbTk::Menu &inject_into);
43 static bool createWindowMenuItem(const std::string &type, const std::string &label, 43 static bool createWindowMenuItem(const std::string &type, const std::string &label,
44 FbTk::Menu &inject_into); 44 FbTk::Menu &inject_into);
diff --git a/src/Screen.cc b/src/Screen.cc
index 1708a69..8b00186 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -1498,21 +1498,18 @@ void BScreen::initMenus() {
1498void BScreen::initMenu() { 1498void BScreen::initMenu() {
1499 1499
1500 if (m_rootmenu.get()) { 1500 if (m_rootmenu.get()) {
1501 while (m_rootmenu->numberOfItems()) 1501 m_rootmenu->removeAll();
1502 m_rootmenu->remove(0); 1502 m_rootmenu->setLabel("");
1503 } else 1503 } else
1504 m_rootmenu.reset(createMenu("")); 1504 m_rootmenu.reset(createMenu(""));
1505 1505
1506 Fluxbox * const fb = Fluxbox::instance(); 1506 Fluxbox * const fb = Fluxbox::instance();
1507 if (!fb->getMenuFilename().empty()) { 1507 if (!fb->getMenuFilename().empty())
1508 m_rootmenu.reset(MenuCreator::createFromFile(fb->getMenuFilename(), 1508 MenuCreator::createFromFile(fb->getMenuFilename(), *m_rootmenu);
1509 screenNumber()));
1510
1511 }
1512 1509
1513 if (m_rootmenu.get() == 0 || m_rootmenu->numberOfItems() == 0) { 1510 if (m_rootmenu->numberOfItems() == 0) {
1514 _FB_USES_NLS; 1511 _FB_USES_NLS;
1515 m_rootmenu.reset(createMenu(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu"))); 1512 m_rootmenu->setLabel(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu"));
1516 FbTk::RefCount<FbTk::Command<void> > restart_fb(FbTk::CommandParser<void>::instance().parse("restart")); 1513 FbTk::RefCount<FbTk::Command<void> > restart_fb(FbTk::CommandParser<void>::instance().parse("restart"));
1517 FbTk::RefCount<FbTk::Command<void> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit")); 1514 FbTk::RefCount<FbTk::Command<void> > exit_fb(FbTk::CommandParser<void>::instance().parse("exit"));
1518 FbTk::RefCount<FbTk::Command<void> > execute_xterm(FbTk::CommandParser<void>::instance().parse("exec xterm")); 1515 FbTk::RefCount<FbTk::Command<void> > execute_xterm(FbTk::CommandParser<void>::instance().parse("exec xterm"));
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index d765d3c..7d774cc 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -1490,9 +1490,6 @@ void Fluxbox::rereadMenu() {
1490 for_each(m_screen_list.begin(), 1490 for_each(m_screen_list.begin(),
1491 m_screen_list.end(), 1491 m_screen_list.end(),
1492 mem_fun(&BScreen::rereadMenu)); 1492 mem_fun(&BScreen::rereadMenu));
1493
1494 FbCommands::ShowRootMenuCmd showcmd;
1495 showcmd.execute();
1496} 1493}
1497 1494
1498void Fluxbox::saveMenuFilename(const char *filename) { 1495void Fluxbox::saveMenuFilename(const char *filename) {