aboutsummaryrefslogtreecommitdiff
path: root/src/MenuCreator.cc
diff options
context:
space:
mode:
authormathias <mathias>2004-12-18 01:29:22 (GMT)
committermathias <mathias>2004-12-18 01:29:22 (GMT)
commitb3fa5c242881b55a76c0e25b3cebaf15d0744f69 (patch)
treebcdb8e0df23428f3f3107e27e6af008d6a0409cc /src/MenuCreator.cc
parent6458b1b485c7481da6d2d1bf235b44fe3b700bd3 (diff)
downloadfluxbox_pavel-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.zip
fluxbox_pavel-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.tar.bz2
* moved FbTk/Directory.cc/hh over to FbTk/FileUtil.cc/hh which contain now
file and directory - helproutines. * created the FileUtil-namespace which contains file-related functions, moved those functions out of Directory - code * changes to the rest of the files to follow those changes
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r--src/MenuCreator.cc68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index ca36eef..2fc8194 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -46,7 +46,7 @@
46#include "FbTk/MacroCommand.hh" 46#include "FbTk/MacroCommand.hh"
47#include "FbTk/SimpleCommand.hh" 47#include "FbTk/SimpleCommand.hh"
48#include "FbTk/StringUtil.hh" 48#include "FbTk/StringUtil.hh"
49#include "FbTk/Directory.hh" 49#include "FbTk/FileUtil.hh"
50#include "FbTk/MenuSeparator.hh" 50#include "FbTk/MenuSeparator.hh"
51#include "FbTk/MenuIcon.hh" 51#include "FbTk/MenuIcon.hh"
52 52
@@ -58,12 +58,12 @@ void LayerMenuItem<FluxboxWindow>::click(int button, int time) {
58 m_object->moveToLayer(m_layernum); 58 m_object->moveToLayer(m_layernum);
59} 59}
60 60
61static void createStyleMenu(FbTk::Menu &parent, const std::string &label, 61static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
62 const std::string &directory) { 62 const std::string &directory) {
63 // perform shell style ~ home directory expansion 63 // perform shell style ~ home directory expansion
64 string stylesdir(FbTk::StringUtil::expandFilename(directory)); 64 string stylesdir(FbTk::StringUtil::expandFilename(directory));
65 65
66 if (!FbTk::Directory::isDirectory(stylesdir)) 66 if (!FbTk::FileUtil::isDirectory(stylesdir.c_str()))
67 return; 67 return;
68 68
69 FbTk::Directory dir(stylesdir.c_str()); 69 FbTk::Directory dir(stylesdir.c_str());
@@ -81,25 +81,25 @@ static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
81 std::string style(stylesdir + '/' + filelist[file_index]); 81 std::string style(stylesdir + '/' + filelist[file_index]);
82 // add to menu only if the file is a regular file, and not a 82 // add to menu only if the file is a regular file, and not a
83 // .file or a backup~ file 83 // .file or a backup~ file
84 if ((FbTk::Directory::isRegularFile(style) && 84 if ((FbTk::FileUtil::isRegularFile(style.c_str()) &&
85 (filelist[file_index][0] != '.') && 85 (filelist[file_index][0] != '.') &&
86 (style[style.length() - 1] != '~')) || 86 (style[style.length() - 1] != '~')) ||
87 FbTk::Directory::isRegularFile(style + "/theme.cfg") || 87 FbTk::FileUtil::isRegularFile((style + "/theme.cfg").c_str()) ||
88 FbTk::Directory::isRegularFile(style + "/style.cfg")) 88 FbTk::FileUtil::isRegularFile((style + "/style.cfg").c_str()))
89 parent.insert(new StyleMenuItem(filelist[file_index], style)); 89 parent.insert(new StyleMenuItem(filelist[file_index], style));
90 } 90 }
91 // update menu graphics 91 // update menu graphics
92 parent.updateMenu(); 92 parent.updateMenu();
93 Fluxbox::instance()->saveMenuFilename(stylesdir.c_str()); 93 Fluxbox::instance()->saveMenuFilename(stylesdir.c_str());
94 94
95} 95}
96 96
97static void createRootCmdMenu(FbTk::Menu &parent, const string &label, 97static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
98 const string &directory, const string &cmd) { 98 const string &directory, const string &cmd) {
99 // perform shell style ~ home directory expansion 99 // perform shell style ~ home directory expansion
100 string rootcmddir(FbTk::StringUtil::expandFilename(directory)); 100 string rootcmddir(FbTk::StringUtil::expandFilename(directory));
101 101
102 if (!FbTk::Directory::isDirectory(rootcmddir)) 102 if (!FbTk::FileUtil::isDirectory(rootcmddir.c_str()))
103 return; 103 return;
104 104
105 FbTk::Directory dir(rootcmddir.c_str()); 105 FbTk::Directory dir(rootcmddir.c_str());
@@ -114,13 +114,13 @@ static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
114 114
115 // for each file in directory add filename and path to menu 115 // for each file in directory add filename and path to menu
116 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 116 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
117 117
118 string rootcmd(rootcmddir+ '/' + filelist[file_index]); 118 string rootcmd(rootcmddir+ '/' + filelist[file_index]);
119 // add to menu only if the file is a regular file, and not a 119 // add to menu only if the file is a regular file, and not a
120 // .file or a backup~ file 120 // .file or a backup~ file
121 if ((FbTk::Directory::isRegularFile(rootcmd) && 121 if ((FbTk::FileUtil::isRegularFile(rootcmd.c_str()) &&
122 (filelist[file_index][0] != '.') && 122 (filelist[file_index][0] != '.') &&
123 (rootcmd[rootcmd.length() - 1] != '~'))) 123 (rootcmd[rootcmd.length() - 1] != '~')))
124 parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd)); 124 parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd));
125 } 125 }
126 // update menu graphics 126 // update menu graphics
@@ -172,10 +172,10 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
172 172
173 const int screen_number = menu.screenNumber(); 173 const int screen_number = menu.screenNumber();
174 _FB_USES_NLS; 174 _FB_USES_NLS;
175 175
176 if (str_key == "end") { 176 if (str_key == "end") {
177 return; 177 return;
178 } else if (str_key == "nop") { 178 } else if (str_key == "nop") {
179 menu.insert(str_label.c_str()); 179 menu.insert(str_label.c_str());
180 } else if (str_key == "icons") { 180 } else if (str_key == "icons") {
181 FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber()); 181 FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber());
@@ -195,7 +195,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
195 // execute and hide menu 195 // execute and hide menu
196 using namespace FbTk; 196 using namespace FbTk;
197 RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd)); 197 RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd));
198 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu, 198 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
199 &Menu::hide)); 199 &Menu::hide));
200 MacroCommand *exec_and_hide = new FbTk::MacroCommand(); 200 MacroCommand *exec_and_hide = new FbTk::MacroCommand();
201 exec_and_hide->add(hide_menu); 201 exec_and_hide->add(hide_menu);
@@ -205,7 +205,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
205 } else if (str_key == "macrocmd") { 205 } else if (str_key == "macrocmd") {
206 using namespace FbTk; 206 using namespace FbTk;
207 RefCount<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd)); 207 RefCount<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd));
208 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu, 208 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
209 &Menu::hide)); 209 &Menu::hide));
210 MacroCommand *exec_and_hide = new FbTk::MacroCommand(); 210 MacroCommand *exec_and_hide = new FbTk::MacroCommand();
211 exec_and_hide->add(hide_menu); 211 exec_and_hide->add(hide_menu);
@@ -218,7 +218,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
218 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 218 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
219 if (screen != 0) 219 if (screen != 0)
220 menu.insert(str_label.c_str(), &screen->configMenu()); 220 menu.insert(str_label.c_str(), &screen->configMenu());
221 } // end of config 221 } // end of config
222 else if (str_key == "include") { // include 222 else if (str_key == "include") { // include
223 223
224 // this will make sure we dont get stuck in a loop 224 // this will make sure we dont get stuck in a loop
@@ -229,7 +229,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
229 safe_counter++; 229 safe_counter++;
230 230
231 string newfile = FbTk::StringUtil::expandFilename(str_label); 231 string newfile = FbTk::StringUtil::expandFilename(str_label);
232 if (FbTk::Directory::isDirectory(newfile)) { 232 if (FbTk::FileUtil::isDirectory(newfile.c_str())) {
233 // inject every file in this directory into the current menu 233 // inject every file in this directory into the current menu
234 FbTk::Directory dir(newfile.c_str()); 234 FbTk::Directory dir(newfile.c_str());
235 235
@@ -241,7 +241,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
241 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 241 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
242 std::string thisfile(newfile + '/' + filelist[file_index]); 242 std::string thisfile(newfile + '/' + filelist[file_index]);
243 243
244 if (FbTk::Directory::isRegularFile(thisfile) && 244 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
245 (filelist[file_index][0] != '.') && 245 (filelist[file_index][0] != '.') &&
246 (thisfile[thisfile.length() - 1] != '~')) { 246 (thisfile[thisfile.length() - 1] != '~')) {
247 MenuCreator::createFromFile(thisfile, menu, false); 247 MenuCreator::createFromFile(thisfile, menu, false);
@@ -259,7 +259,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
259 259
260 } // end of include 260 } // end of include
261 else if (str_key == "submenu") { 261 else if (str_key == "submenu") {
262 262
263 FbTk::Menu *submenu = MenuCreator::createMenu("", screen_number); 263 FbTk::Menu *submenu = MenuCreator::createMenu("", screen_number);
264 if (submenu == 0) 264 if (submenu == 0)
265 return; 265 return;
@@ -274,21 +274,21 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
274 menu.insert(str_label.c_str(), submenu); 274 menu.insert(str_label.c_str(), submenu);
275 // save to screen list so we can delete it later 275 // save to screen list so we can delete it later
276 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 276 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
277 if (screen != 0) 277 if (screen != 0)
278 screen->saveMenu(*submenu); 278 screen->saveMenu(*submenu);
279 279
280 } // end of submenu 280 } // end of submenu
281 else if (str_key == "stylesdir" || str_key == "stylesmenu") { 281 else if (str_key == "stylesdir" || str_key == "stylesmenu") {
282 createStyleMenu(menu, str_label, 282 createStyleMenu(menu, str_label,
283 str_key == "stylesmenu" ? str_cmd : str_label); 283 str_key == "stylesmenu" ? str_cmd : str_label);
284 } // end of stylesdir 284 } // end of stylesdir
285 else if (str_key == "themesdir" || str_key == "themesmenu") { 285 else if (str_key == "themesdir" || str_key == "themesmenu") {
286 createStyleMenu(menu, str_label, 286 createStyleMenu(menu, str_label,
287 str_key == "themesmenu" ? str_cmd : str_label); 287 str_key == "themesmenu" ? str_cmd : str_label);
288 } // end of themesdir 288 } // end of themesdir
289 else if (str_key == "wallpapers" || str_key == "wallpapermenu" || 289 else if (str_key == "wallpapers" || str_key == "wallpapermenu" ||
290 str_key == "rootcommands") { 290 str_key == "rootcommands") {
291 createRootCmdMenu(menu, str_label, str_label, 291 createRootCmdMenu(menu, str_label, str_label,
292 str_cmd == "" ? "fbsetbg" : str_cmd); 292 str_cmd == "" ? "fbsetbg" : str_cmd);
293 } // end of wallpapers 293 } // end of wallpapers
294 else if (str_key == "workspaces") { 294 else if (str_key == "workspaces") {
@@ -353,8 +353,8 @@ FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number)
353 if (screen == 0) 353 if (screen == 0)
354 return 0; 354 return 0;
355 355
356 FbTk::Menu *menu = new FbMenu(screen->menuTheme(), 356 FbTk::Menu *menu = new FbMenu(screen->menuTheme(),
357 screen->imageControl(), 357 screen->imageControl(),
358 *screen->layerManager(). 358 *screen->layerManager().
359 getLayer(Fluxbox::instance()->getMenuLayer())); 359 getLayer(Fluxbox::instance()->getMenuLayer()));
360 if (!label.empty()) 360 if (!label.empty())
@@ -390,7 +390,7 @@ FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_
390 std::string label; 390 std::string label;
391 if (require_begin && !getStart(parser, label)) 391 if (require_begin && !getStart(parser, label))
392 return 0; 392 return 0;
393 393
394 FbTk::Menu *menu = createMenu(label, screen_number); 394 FbTk::Menu *menu = createMenu(label, screen_number);
395 if (menu != 0) 395 if (menu != 0)
396 parseMenu(parser, *menu); 396 parseMenu(parser, *menu);
@@ -416,8 +416,8 @@ bool MenuCreator::createFromFile(const std::string &filename,
416} 416}
417 417
418 418
419bool MenuCreator::createFromFile(const std::string &filename, 419bool MenuCreator::createFromFile(const std::string &filename,
420 FbTk::Menu &inject_into, 420 FbTk::Menu &inject_into,
421 FluxboxWindow &win, bool require_begin) { 421 FluxboxWindow &win, bool require_begin) {
422 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 422 std::string real_filename = FbTk::StringUtil::expandFilename(filename);
423 FbMenuParser parser(real_filename); 423 FbMenuParser parser(real_filename);
@@ -446,7 +446,7 @@ FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num)
446 return 0; 446 return 0;
447} 447}
448 448
449bool MenuCreator::createWindowMenuItem(const std::string &type, 449bool MenuCreator::createWindowMenuItem(const std::string &type,
450 const std::string &label, 450 const std::string &label,
451 FbTk::Menu &menu, 451 FbTk::Menu &menu,
452 FluxboxWindow &win) { 452 FluxboxWindow &win) {
@@ -502,10 +502,10 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
502 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); 502 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
503 if (screen == 0) 503 if (screen == 0)
504 return false; 504 return false;
505 FbTk::Menu *submenu = new LayerMenu<FluxboxWindow>(screen->menuTheme(), 505 FbTk::Menu *submenu = new LayerMenu<FluxboxWindow>(screen->menuTheme(),
506 screen->imageControl(), 506 screen->imageControl(),
507 *screen->layerManager(). 507 *screen->layerManager().
508 getLayer(Fluxbox::instance()->getMenuLayer()), 508 getLayer(Fluxbox::instance()->getMenuLayer()),
509 &win, 509 &win,
510 false); 510 false);
511 submenu->disableTitle(); 511 submenu->disableTitle();